Bisa / factorio-init

Factorio init script
MIT License
414 stars 82 forks source link

map doesn't finish saving when running shutdown -r now #115

Closed BeanHeaDza closed 6 years ago

BeanHeaDza commented 7 years ago

So I've only recently gotten into this linux thing so there might be something small I am doing wrong, but when I call "sudo shutdown -r now" systemd does not wait for factorio to close gracefully before restarting the system. When I do a "sudo service factorio stop" it runs for around 7 seconds and then stops gracefully (I can see it stop properly by checking the server.out file).

Should I just call "sudo service factorio stop" before each restart or is there something I could have messed up? Because what is happening now is that when I restart it creates a "/opt/factorio/saves/server-save.tmp.zip" file and then because it couldn't finish saving the server tries to load that file (The "latest" save) and complains that it is corrupt. So I have to delete that file and then restart the service.

Dynamic-Gravity commented 7 years ago

I would append your ~/.bashrc to something like this:

alias clean-restart='sudo service factorio stop && sudo shutdown -r now'

That way all you need to do from now on is type clean-restart from your terminal.

Once you update your bashrc you will need to reload your shell for it to take effect, so logout, then back in.

dgw commented 6 years ago

From some research I just did, I gather that systemd might not wait for this init script to finish because:

  1. This is a legacy init script, not a systemd unit, so systemd's SysV compatibility generator builds a minimal unit file for this using ExecStart and ExecStop directives. (Unix.SE)
  2. systemd assumes that whatever command is run by ExecStop will wait synchronously for the operation to finish. (systemd issue comment) Glancing at the code, it looks like this init-script should synchronously block for some time, but my Bash isn't great, so it might not be waiting?

At any rate, you might have better luck with a real systemd unit, examples of which I was able to find with a quick Google search.

Xiretza commented 6 years ago

@dgw what exactly is wrong with https://github.com/Bisa/factorio-init/blob/master/factorio.service.example? A slightly changed version (different executable paths and group name) is used in my AUR package, and as far as I can tell it waits just fine.

Bisa commented 6 years ago

Doing some cleaning here, please re-open if anyone still has the same issue.