OpenFactorioServerManager / factorio-server-manager

A tool to help manage Factorio multiplayer servers including mods and save games.
MIT License
616 stars 140 forks source link

Server Autostart on Unraid #409

Open Tronnic opened 1 month ago

Tronnic commented 1 month ago

Hello everyone, I am unable to setup Server Autostart within my unraid docker.

image

I set the FSM_AUTOSTART variable to true but the server remains offline.

My unraid server does a backup of all containers at night, which results in the factorio server being offline. Is there any possible fix for this?

Is there any other way to fix the autostart? Where would the conf.json be?

Any help would be greatly appreciated!

Best regards, Frank.

matmat07 commented 1 month ago

I can confirm the same behaviour. To add to that and confirm the value was passed correctly, here's the output of a command for the container:

printenv

HOSTNAME=6ca9cbef4a20 HOME=/root HOST_OS=Unraid FSM_AUTOSTART=true TERM=xterm PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin FACTORIO_VERSION=latest HOST_HOSTNAME=Tower HOST_CONTAINERNAME=FactorioServerManager PWD=/opt RCON_PASS= TZ=America/New_York

Mattie112 commented 1 month ago

see: https://github.com/OpenFactorioServerManager/factorio-server-manager/issues/301 for more

Tronnic commented 1 month ago

Is it in any way possible to start the factorio server within the container trough command line? Maybe a workaround would be to create a userscript that runs after the backup is complete to start the server "manually".

Using the Evn.Variables seems to be bugged in fsm/unraid.

Mattie112 commented 1 month ago

@Tronnic see https://github.com/OpenFactorioServerManager/factorio-server-manager/issues/301#issuecomment-2416052379 for a possible work-around

Tronnic commented 1 month ago

@Mattie112 I have looked into the possible fix with the entrypoint.sh, unfortunately this doesn't work for me as well.

Leridon commented 1 month ago

What confuses me about the docker installation is that entrypoint.sh does not appear to pass any of its CLI arguments to the actual fsm process. So when starting the container using docker run ofsm --autostart true (or any other parameter), all parameters are dropped. Am I missing something or is this an oversight and the last command of entrypoint.sh should include an "$@" at the end?

Mattie112 commented 1 month ago

That could very well be the case but I won't have time to dive into it before the weekend. If you can test it out and report back (or create a PR) that would be great! If not I will try it in the weekend.

Leridon commented 1 month ago

@Mattie112 I tested exactly that (after taking some time to get the docker build going locally) and it appears to work fine. With the argument passing added it now reacts to --autostart true as expected when running it, as well as all other cli parameters.

Here's the command I tested this with: docker run -p 80:80 -v ./factorio-data/saves:/opt/factorio/saves -v ./factorio-data/mods:/opt/factorio/mods -v ./factorio-data/config:/opt/factorio/config -p 34197:34197/udp localofsm:latest --autostart true

Want me to create a PR for this miniscule change? I know this does not fix the original problem with Environment variables, but still seems relevant because as it stands right now, CLI parameters to fsm are ignored in docker.

OnlyPlean commented 1 month ago

@Tronnic I've gotten the autostart feature to work on Factorio Server Manger.

I am deploying the container via Unraid and followed these steps:

  1. Turn on the container
  2. Open the console for the container
  3. Install nano (or whatever text editor you like) as one is not installed by default in the container apt-get update && apt-get install nano
  4. Open the entrypoint.sh with your text editor nano entrypoint.sh
  5. Edit the final line to the following: cd /opt/fsm && ./factorio-server-manager --conf /opt/fsm-data/conf.json --dir /opt/factorio --port 80 --autostart true "$@"

After adding the --autostart true with the "$@" to the end of the line I saved and quit the editor. Restarting the container showed the server start automatically!

Thank you to @Leridon for figuring this out!

Hope this helps!