tf2autobot icon indicating copy to clipboard operation
tf2autobot copied to clipboard

Do not use PM2 with docker

Open Haarolean opened this issue 4 years ago • 16 comments

I see that we have a Dockerfile in the repo now, so I raise this request.

Could we please bypass pm2 checks upon bot restarts? Like, I'd like it to just terminate itself if I'm running it in a container (we could use env option to detect this, for example).

I suppose there's really no point in running PM2 inside a single process container.

Haarolean avatar Apr 14 '21 17:04 Haarolean

@rennokki @arik123

idinium96 avatar Apr 15 '21 11:04 idinium96

@Haarolean In essence, that's true - it's a rule of thumb to run a single process per container.

PM2 comes bundled up in the final image to not break the functionality for users that have ecosystem.json.

The final images support them and can be used as usual with PM2 if you also wish to change the default entrypoint with a custom PM2 entrypoint command.

rennokki avatar Apr 15 '21 12:04 rennokki

That's why I suggest a back-compatible solution (e.g. a config option) to keep previous installations alive.

Haarolean avatar Apr 15 '21 16:04 Haarolean

PM2 is completely optional in Docker. The process is still running with the node CLI: https://github.com/TF2Autobot/tf2autobot/blob/master/Dockerfile#L17

rennokki avatar Apr 15 '21 17:04 rennokki

@rennokki Yes it does. I think you're missing my point, I can't restart the bot because it says I don't run it with PM2. Which shouldn't be a problem restart:always will do the deed for me without PM2.

Haarolean avatar Apr 15 '21 17:04 Haarolean

I get it now. 😁 Restarting the container should do the job?

rennokki avatar Apr 15 '21 17:04 rennokki

Yep, but I can't do that via steam command. Also bot handles shutdown via docker too harsh, like a crash :)

Haarolean avatar Apr 15 '21 18:04 Haarolean

That's completely normal to treat it like a crash. Closing the bot is signaling with SIGTERM or SIGINT to the process and kills it after a brief period of time (it depends on what it does before killing the process, as you can catch this signal).

The main rule here would be to kill the container and create another one and that's a restart.

rennokki avatar May 27 '21 17:05 rennokki

My main point is still is that I can't restart or shutdown the bot via steam commands without PM2.

Haarolean avatar May 27 '21 17:05 Haarolean

Using --restart=always would restart the container in case it's crashing. Docs here

rennokki avatar May 27 '21 18:05 rennokki

I know. This has nothing to do with steam commands anyway.

Haarolean avatar May 27 '21 19:05 Haarolean

Maybe this should be used? https://github.com/sindresorhus/is-docker

maybe here? https://github.com/TF2Autobot/tf2autobot/blob/b66bc63772d9c41c2e621879b9c88c16f6b6bef0/src/classes/BotManager.ts#L211-L227

idinium96 avatar Jun 04 '21 14:06 idinium96

Yeah, I think this might work. @idinium96 would you push a dev branch with this changes please? I'm not familiar with ts but I can build and test the changes.

Haarolean avatar Jun 05 '21 19:06 Haarolean

hurmmm I am not sure how to implement this tbh.

idinium96 avatar Jun 07 '21 05:06 idinium96

@Haarolean @idinium96 Hello. I have issued a PR for this thing that can be tested on. I have explained in the PR what the caveats are.

rennokki avatar Feb 11 '22 14:02 rennokki

@Haarolean The dev branch received an update regarding this. If you still use Docker for this, please check if this works with the tf2autobot/tf2autobot:ba85ccf97ff2947e6646f8b81575098fb8a8fdfd-16.13.0-alpine tag as it's the head of the branch (after the merge).

I will still keep the issue active until things turn out alright.

Basically, you want to use --restart=always with the docker run command.

$ docker run \
    -v $(pwd)/tf2autobot_data/123456:/app/files/123456 \
    -v $(pwd)/tf2autobot_data/ecosystem.json:/app/ecosystem.json \
    --restart=always \
    -e DOCKER=1 \
    tf2autobot/tf2autobot:ba85ccf97ff2947e6646f8b81575098fb8a8fdfd-16.13.0-alpine

@idinium96 The wiki should also get updated on the next version when dev gets merged.

rennokki avatar Feb 11 '22 17:02 rennokki