tf2autobot
tf2autobot copied to clipboard
Do not use PM2 with docker
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.
@rennokki @arik123
@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.
That's why I suggest a back-compatible solution (e.g. a config option) to keep previous installations alive.
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 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.
I get it now. 😁 Restarting the container should do the job?
Yep, but I can't do that via steam command. Also bot handles shutdown via docker too harsh, like a crash :)
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.
My main point is still is that I can't restart or shutdown the bot via steam commands without PM2.
Using --restart=always would restart the container in case it's crashing. Docs here
I know. This has nothing to do with steam commands anyway.
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
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.
hurmmm I am not sure how to implement this tbh.
@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.

@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.