factorio-server-manager icon indicating copy to clipboard operation
factorio-server-manager copied to clipboard

Autostart on docker on debian not working

Open kevindstanley1988 opened this issue 1 year ago • 3 comments

Hi I am having trouble getting autostart to work. I have tried all of the flags,env settings, and conf.json's as described below, but in none of the cases do I get the factorio server to start on run of the docker container.

With environment variable FSM_AUTOSTART=true - this server starts the web server, and if i click 'start' in the web ui it does start the game, but no autostart if i restart the container.

docker run --name ofsm -e FACTORIO_VERSION=2.0.23 -e FSM_AUTOSTART=true -v ./fsm-data:/opt/fsm-data -v ./factorio-data/saves:/opt/factorio/saves -v ./factorio-data/mods:/opt/factorio/mods -v ./factorio-data/config:/opt/factorio/config -v ./factorio-data/mod_packs:/opt/fsm/mod_packs -d -p 80:80 -p 34197:34197/udp --restart=always ofsm/ofsm:latest

With flag --autostart - same deal, no autostart, otherwise is functioning.

docker run --name ofsm -e FACTORIO_VERSION=2.0.23 -v ./fsm-data:/opt/fsm-data -v ./factorio-data/saves:/opt/factorio/saves -v ./factorio-data/mods:/opt/factorio/mods -v ./factorio-data/config:/opt/factorio/config -v ./factorio-data/mod_packs:/opt/fsm/mod_packs -d -p 80:80 -p 34197:34197/udp --restart=always ofsm/ofsm:latest --autostart

i also tried --autostart true to test if it required a value, but still not working docker run --name ofsm -e FACTORIO_VERSION=2.0.23 -v ./fsm-data:/opt/fsm-data -v ./factorio-data/saves:/opt/factorio/saves -v ./factorio-data/mods:/opt/factorio/mods -v ./factorio-data/config:/opt/factorio/config -v ./factorio-data/mod_packs:/opt/fsm/mod_packs -d -p 80:80 -p 34197:34197/udp --restart=always ofsm/ofsm:latest --autostart true

no environment variable, no flag, modified conf.json file

docker run --name ofsm -e FACTORIO_VERSION=2.0.23 -v ./fsm-data:/opt/fsm-data -v ./factorio-data/saves:/opt/factorio/saves -v ./factorio-data/mods:/opt/factorio/mods -v ./factorio-data/config:/opt/factorio/config -v ./factorio-data/mod_packs:/opt/fsm/mod_packs -d -p 80:80 -p 34197:34197/udp --restart=always ofsm/ofsm:latest

image

Any ideas for what to try next?

kevindstanley1988 avatar Dec 06 '24 15:12 kevindstanley1988

My quick repeatable steps for replication of this issue - with Proxmox as the base environment, but should work even if docker is installed in any linux environment with docker and docker compose installed.

First create a docker LXC, and use helper scripts to do so. https://community-scripts.github.io/ProxmoxVE/scripts?id=docker say yes to docker compose when asked

login as root to your proxmox container

apt update
apt install git
cd /home

git clone this repo

git clone https://github.com/OpenFactorioServerManager/factorio-server-manager.git
cd /home/factorio-server-manager/docker
docker compose -d -f docker-compose.simple.yml

once the docker container is created, navigate to the file(s) to edit them First try environment variable

cd /home/factorio-server-manager/docker
nano docker-compose.simple.yml

edit the environment variable to include AUTOSTART I also tried AUTOSTART=true ctrl-x to close and save the file restart the proxmox virtual machine the ui comes up, but the factorio server remains offline

all of the files mentioned in the original post with this testing method, and recreated the docker containers each time to make sure there was nothing different between the runs, except for each file edit.

kevindstanley1988 avatar Dec 12 '24 19:12 kevindstanley1988

Same thing happening to me, I've ran in docker on LXC and a full-fledged debian 12 VM and have the same issues in both. It doesn't seem to accept anything either from ENV or the json file method.

jasonfen avatar Jan 22 '25 21:01 jasonfen

This issue is because flags are not being passed to the factorio server and environment variables are not parsed correctly after starting the container. There are numerous issues and pull requests here to fix this but the maintainer seems to be unable to do so.

I managed to get flags working:

  1. Add new volume to docker run... command: -v '/some/path/to/entrypoint.sh':'/opt/entrypoint.sh':'rw'
  2. On the host create /some/path/to/entrypoint.sh
  3. Insert this code:
#!/bin/sh

init_config() {
    jq_cmd='.'

    if [ -n "$RCON_PASS" ]; then
      jq_cmd="${jq_cmd} | .rcon_pass = \"$RCON_PASS\""
      echo "Factorio rcon password is '$RCON_PASS'"
    fi

    jq_cmd="${jq_cmd} | .sq_lite_database_file = \"/opt/fsm-data/sqlite.db\""
    jq_cmd="${jq_cmd} | .log_file = \"/opt/fsm-data/factorio-server-manager.log\""

    jq "${jq_cmd}" /opt/fsm/conf.json >/opt/fsm-data/conf.json
}

random_pass() {
    LC_ALL=C tr -dc 'a-zA-Z0-9' </dev/urandom | fold -w 24 | head -n 1
}

install_game() {
    curl --location "https://www.factorio.com/get-download/${FACTORIO_VERSION}/headless/linux64" \
         --output /tmp/factorio_${FACTORIO_VERSION}.tar.xz
    tar -xf /tmp/factorio_${FACTORIO_VERSION}.tar.xz
    rm /tmp/factorio_${FACTORIO_VERSION}.tar.xz
}

if [ ! -f /opt/fsm-data/conf.json ]; then
    init_config
fi

install_game

cd /opt/fsm && ./factorio-server-manager --conf /opt/fsm-data/conf.json --dir /opt/factorio --port 80 "$@"

Notice the only change I made is I added "$@" at the end as detailed in https://github.com/OpenFactorioServerManager/factorio-server-manager/pull/413

  1. make executable (chmod +x /some/path/to/entrypoint.sh)
  2. run the container

This should inject a fixed entrypoint.sh. Notice that this does not fix environment variebles (-e ...). but running with --autostart true works.

Also this is likely bad practice as anyone who can edit entrypoint.sh can execute arbitrary commands in the container.

Edit: the image ofsm/ofms:develop has environment variables working, so use that with -e FSM_AUTOSTART='true' if you don't like my solution above.

jesta030 avatar Jan 28 '25 06:01 jesta030