OpenFactorioServerManager / factorio-server-manager

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

Auto Start #301

Open jaschuu opened 2 years ago

jaschuu commented 2 years ago

Hey,

Is it possible to have the server auto start using the latest save file if there is one?

my unraid server stops all the containers to auto update them and what not, and when the fsm container starts back up the server does not start.

thanks

mroote commented 2 years ago

Hi @jaschuu,

You should be able to specify the -autostart flag to automatically start the server and load the latest save.

jaschuu commented 2 years ago

Hi @jaschuu,

You should be able to specify the -autostart flag to automatically start the server and load the latest save.

where do I -autostart? in the conf.json ?

mroote commented 2 years ago

You can set it via environment variable or in conf.json. I think for conf.json you would add a "autostart": true config value in the file.

jaschuu commented 2 years ago

where do my auto saves / saves go, I can not find them?

mroote commented 2 years ago

It depends on where you are mapping the /opt/factorio/saves volume in the container on your host system.

jaschuu commented 2 years ago

It depends on where you are mapping the /opt/factorio/saves volume in the container on your host system.

factorio path = /mnt/user/appdata/fsm_factorio/ fsm data = /mnt/user/appdata/fsm_factorio/fsm_data

this is all I know, they are the folders I have checked, I am running this on unraid via the dockers

5647.126 Info ServerMultiplayerManager.cpp:1212: Auto saving map as /opt/factorio/saves/Deathworld.zip 5647.142 Info AppManager.cpp:420: Saving game as /opt/factorio/saves/Deathworld.zip

i just left the default directories, but i have no idea where that is.

knoxfighter commented 2 years ago

If you have used our docker compose file, the saves are located in ./factorio-data/saves. For exact information you would need to provide your docker-compose file / the command you have used to start the docker-container. Make sure to remove passwords :)

mroote commented 2 years ago

I haven't used unraid but it looks like there are config options you can set to map the volume to your host machine: https://wiki.unraid.net/index.php/UnRAID_6_2/Docker_Management#Volume_Mappings. You'll need to map the /opt/factorio/saves directory inside the container to somewhere on your host unraid system.

jaschuu commented 2 years ago

looks to already be mapped, -v '/mnt/user/appdata/fsm_factorio/':'/opt/factorio':'rw'

I can see the saves and mods folders but they are empty so i am not sure where those files went,

knoxfighter commented 2 years ago

If you have a console available, you can connect to the docker container, look into /opt/factorio and see if the saves are really there. If they are there, it is a problem with unraid and how they map volumes.

jaschuu commented 2 years ago

Yeah there seems to be a mapping problem, found the saves in the console,

image

just need to work out how to fix it now

mroote commented 2 years ago

Try adding another mount pointing directly to the saves/ directory.

Ex.

'/mnt/user/appdata/fsm_factorio/saves':'/opt/factorio/saves':'rw'
VACIndustries commented 2 years ago

Also seem to be having an issue where after adding "autostart": true to the config.json does not actually autostart the server/game

VACIndustries commented 2 years ago

I'm not super familiar with gocode but does the json key need to be populated here? https://github.com/OpenFactorioServerManager/factorio-server-manager/blob/master/src/bootstrap/config.go#L61

jannaahs commented 2 years ago

@VACIndustries you are right. It's currently not possible to set the autostart in the config.json.

The autostart can be used as flag or environment variable when starting the OpenFactorioServerManager (see src/bootstrap/config.go#L30). The flags are injected into the configs.

What do you think of autostart being available in the config.json as well?

VACIndustries commented 2 years ago

@jannaahs that would be great if we could add it in. I'm running FSM in docker on my Unraid server and this is the final step to have it all automated right now. I'd imagine it would be beneficial to anyone using it in a container setup.

VACIndustries commented 2 years ago

Is this as easy as a one line change as I referenced above? If so, I can give it a go myself and if successful can open a PR

jannaahs commented 2 years ago

@VACIndustries yes, it should be just a one line change.

Kennochas commented 2 years ago

Was there ever any PR created for making it so the docker container can do an autostart?

This is becoming a problem for me when Unraid does a backup, stopping containers to backup all the data, then starting them all back up.

Mattie112 commented 2 years ago

(For Unraid CA backup you can also uncheck your factorio server so it won't be shut down when backing-up, yes there is a chance a file is written the same moment the backup is made but for me the backup is scheduled when there are no players online)

RASTRILL0 commented 2 years ago

I would also appreciate autostart in Unraid. I always forget to restart the server after updating the operating system.

Akuno1 commented 2 years ago

I'm not sure if you guys talk about the same as what I want but I will add my 5 cents to it. I would really appreciate it if we could start the server after the docker was restarted. If my Unraid server gets restarted all my docker start automatically. But Factorio Server Manager won't load the map/server only the docker starts. Is it somehow possible now that it will automatically start the server?

cheuer commented 1 year ago

Hi, any updates on getting this merged in? Looking at setting up a factorio server and this would be very useful.

Diman0 commented 4 weeks ago

The --autostart true parameter still works. I use docker and made the following changes to get it working. In the root folder (same folder as docker-compose.yml), create the file entrypoint.sh. Use chmod +x entrypoint.sh to make it executable. Edit entrypoint.sh and paste the below contents. I only added the --autostart true parameter.

#!/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 --autostart true

Note: In the docker container you can access the file via /opt/entrypoint.sh if you want to do the modification yourself.

In docker-compose.yml add a volume mapping. We are overwriting the entrypoint.sh in the container with our own.

    volumes:
      - "./fsm-data:/opt/fsm-data"
      - "./factorio-data/saves:/opt/factorio/saves"
      - "./factorio-data/mods:/opt/factorio/mods"
      - "./factorio-data/config:/opt/factorio/config"
      - "./factorio-data/mod_packs:/opt/fsm/mod_packs"
      - "./entrypoint.sh:/opt/entrypoint.sh"

docker-compose up -d and factorio will be automatically started now.

Mattie112 commented 3 weeks ago

If no one is working on this I will try to have a look this weekend to the auto start with docker

Diman0 commented 3 weeks ago

If no one is working on this I will try to have a look this weekend to the auto start with docker

https://github.com/OpenFactorioServerManager/factorio-server-manager/pull/332 There is already a PR for that, but for unknown reason it has been in limbo for two years now.

Mattie112 commented 3 weeks ago

Ah, good, thanks for pointing me to the PR, didn't know there was already something. It is a bit hard as there are also lots of open issues about this. I will link everything I know off in that PR and see if I can test it out this weekend then. I am in contact with knoxfighter about this anyway.