Page 1 of 1

[Resolved] Auto-update on headless server

Posted: Sat Aug 01, 2015 2:22 pm
by Eirikaine
Hi everybody !

I've an headless server running factorio (64 bits linux) version 0.12.1, and I want to upgrade to 0.12.2.
Currently, the only way I found to do it is :
  • -- Connect to the factorio website with my computer (windows) and login my account.
    -- Download the experimental release.
    -- Upload the release from my computer to the server. <--- Extremely slow, I've 1Mb/s upload so ~110 Ko/s and factorio is 176 000 Ko... Half an hour of upload !
    -- Then connect to my Linux server, extract the release in the folder and restart the server.
Is there a way to avoid the uploading from my connection ? I mean, is there a way to auto-update factorio directly from the server ?
I know the authentication process is the problem, cause I'm not authenticated to my factorio account on my Linux server.
So can I ask (from a Linux command) the factorio website for an update or, at least, for the latest package by passing my connection info through the command ?

Ty for your help ! :)

Re: Auto-update on headless server

Posted: Sat Aug 08, 2015 10:53 am
by Narc
I think maybe yes? I haven't had a chance to try it yet, though.

If you look in the headless server's root folder (e.g., /home/narc/srv/factorio), there is a file named "player-data.json", which is also present in your client. Among the bits in there, there are the keys "updater-username" and "updater-token" -- I'm pretty sure if you copy/paste those from the client to the server's copy of the file, it will successfully check for updates on startup.

What I do not know is how it will try to ask you whether you want to update -- if it tries to pop up a window, that's not going to work very well.

Before I figured this out, I took a few hours and wrote a script that fetches the updates for you. It's written in Python, so it should be fairly portable. I'll go ahead and publish it as soon as I'm done writing the documentation; whether it turns out to be useless or not, it was a fun exercise in API discovery and use.

Later edit: I've published the script, in case that's useful to you.

Re: Auto-update on headless server

Posted: Sat Aug 08, 2015 11:27 am
by Oxyd

Code: Select all

wget -O update.zip --no-check-certificate $(curl "https://www.factorio.com/updater/get-download-link?username=${username}&token=${token}&package=core-linux64&from=0.12.2&to=0.12.3&isTarget=true&apiVersion=2" | sed -n 's/\["\(.*\)"\]/\1/p')
Assuming ${token} is your token and ${username} is your user name. Also change the from= and to= in the URL as necessary.

This will save the delta as update.zip. To apply, simply

Code: Select all

./factorio --apply-update update.zip

Re: Auto-update on headless server

Posted: Sat Aug 08, 2015 11:30 am
by Narc
Oxyd wrote:

Code: Select all

wget -O update.zip --no-check-certificate $(curl "https://www.factorio.com/updater/get-download-link?username=${username}&token=${token}&package=core-linux64&from=0.12.2&to=0.12.3&isTarget=true&apiVersion=2" | sed -n 's/\["\(.*\)"\]/\1/p')
wget and curl? Oh, my. :)

Also, in case you missed it, I ended up writing a Python script that does (most of) the heavy lifting -- I basically published it as you were writing your post here.

Edit: Oh, and thank you very much for confirming I did it right! :D

Re: Auto-update on headless server

Posted: Sat Aug 08, 2015 11:47 am
by Oxyd
Narc wrote:wget and curl? Oh, my. :)
Updating is a serious business that requires usage of all of the tools I have here. :)

Re: Auto-update on headless server

Posted: Sat Aug 08, 2015 1:28 pm
by Eirikaine
I've nothing to say other than thank you ! :D
All that explanation help me a lot and I'll surely use you're little script Narc ;)

See you on space :)

Re: [Resolved] Auto-update on headless server

Posted: Wed Mar 02, 2016 5:57 pm
by dmnc
Sorry for the necroposting, please where I can get updater-token? I'm configuring my linux dedicated server and my client is Windows/Steam/0.12.24 ... my player-data.json have no updater section ... Thanks.

Re: [Resolved] Auto-update on headless server

Posted: Wed Mar 02, 2016 8:09 pm
by DaveMcW
The command probably needs to be changed, since the headless server is free now.

Re: [Resolved] Auto-update on headless server

Posted: Tue Mar 08, 2016 3:47 pm
by Bonesaw
I just set my server up last night. The wiki was helpful but I'm like the previous poster a little unsure of getting the scripts working correctly. Is there updated information anywhre on this? Sorry for posting to an old thread as well, but Google pointed me to this thread and it looks like I'm not the only new player looking for this info. Cheers!

Re: [Resolved] Auto-update on headless server

Posted: Wed Jun 08, 2022 3:17 pm
by Timestream
Heres another completely automated Script i wrote for a Headless Factorio Server in NodeJS:
http://pestbin.de/servers/factorio/utils/update.js
It works well when used together with systemd services, so whenever your server is restarted it will try to update first.

Dependencies are Nodejs and Screen

Example Service:

Code: Select all

# Factorio Server service
[Unit]
Description=Factorio Server
AssertPathExists=/path/to/server/directory/
StartLimitIntervalSec=0

[Service]
User=your_user
WorkingDirectory=/path/to/server/directory/
Type=forking
ExecStartPre=/path/to/server/directory/update.js
ExecStart=screen -dmS factorio_server_console sh start.sh	#this is where your Server's start script is
Restart=always
RestartSec=2s

[Install]
WantedBy=multi-user.target
This should be put in a file named something like: factorio_server.service
in the /etc/systemd/system/ directory.
Afterwards you can use the command

Code: Select all

sudo systemctl daemon-reload			#this will make the new Service visible to systemd
sudo systemctl enable your_service_file.service	#this will start the server whenever your Machine starts
sudo systemctl start your_service_file.service	#this will start the server
you can then access your servers Console any time (when its running) using

Code: Select all

screen -r factorio_server_console
You can get out of the Console by pressing Ctrl + A , D (thats first ctrl a then d)