fkie-cad / FACT_docker

Dockerfile for building the FACT container
GNU General Public License v3.0
21 stars 9 forks source link

Shutdown radare containers #32

Closed maringuu closed 1 year ago

maringuu commented 1 year ago

From #27

I noticed that after doing a docker-compose stop (or even down) that the radare containers stay up.

$ docker ps
CONTAINER ID   IMAGE                           COMMAND                  CREATED      STATUS      PORTS                                               NAMES
22227f15e563   fkiecad/radare-web-gui:latest   "python3 src/serve.py"   2 days ago   Up 2 days                                                       radare_app_1
34e62c69975b   radare_server                   "/docker-entrypoint.…"   2 days ago   Up 2 days   80/tcp, 0.0.0.0:8000->8000/tcp, :::8000->8000/tcp   radare_server_1

I am guessing that one of the intermediate containers start it but does not shut it down afterwards. Perhaps worth looking into.

Probably this has to be fixed in FACT_core

jstucke commented 1 year ago

The containers are stopped in src/start_fact_frontend.py:

run_cmd_with_logging(f'docker-compose -f {COMPOSE_YAML} down')

The problem is probably that this line is only executed when the frontend is shut down "gracefully". If it is simply killed by docker it will not work. I don't see how this could be solved in FACT because if the process is just killed we can't handle it. I'm not sure how exactly docker-compose down is handled inside the containers, though (i.e. what kind of signal gets sent, etc.). So maybe there could be a way to fix this.

frakman1 commented 1 year ago

If docker-compose is being used to launch FACT, then what is the correct method of shutting down the frontend gracefully?

jstucke commented 1 year ago

When running FACT outside of docker you would simply use Ctrl+C (so SIGINT) to stop FACT. That signal gets handled internally and a graceful shutdown is performed (including the shutdown of docker-compose for the radare web GUI). It seems when using docker-compose, the shutdown is performed differently (could be SIGTERM, SIGKILL or something entirely different). I will have to investigate this and maybe make some adjustments to the signal handling in FACT.

This also means that, sadly, there currently doesn't seem to be a way to shut down FACT_docker gracefully (except maybe starting the containers interactively but I don't think that's a long-term solution)

jstucke commented 1 year ago

I tested it and it seems the signal submitted to the container when pressing Ctrl+C or executing docker-compose stop is SIGTERM. This means if we handle this signal in the FACT start scripts everything should work.