[Resolved] Auto-update on headless server

Anything that prevents you from playing the game properly. Do you have issues playing for the game, downloading it or successfully running it on your computer? Let us know here.
Post Reply
Eirikaine
Burner Inserter
Burner Inserter
Posts: 10
Joined: Sat Apr 11, 2015 7:38 pm
Contact:

[Resolved] Auto-update on headless server

Post 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 ! :)
Last edited by Eirikaine on Fri Aug 14, 2015 11:38 am, edited 1 time in total.
Interested by modding, multiplayer and often active on IRC
No native English speaker.

User avatar
Narc
Filter Inserter
Filter Inserter
Posts: 278
Joined: Mon Feb 11, 2013 7:25 am
Contact:

Re: Auto-update on headless server

Post 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.
Last edited by Narc on Sat Aug 08, 2015 11:27 am, edited 1 time in total.

Oxyd
Former Staff
Former Staff
Posts: 1428
Joined: Thu May 07, 2015 8:42 am
Contact:

Re: Auto-update on headless server

Post 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

User avatar
Narc
Filter Inserter
Filter Inserter
Posts: 278
Joined: Mon Feb 11, 2013 7:25 am
Contact:

Re: Auto-update on headless server

Post 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

Oxyd
Former Staff
Former Staff
Posts: 1428
Joined: Thu May 07, 2015 8:42 am
Contact:

Re: Auto-update on headless server

Post 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. :)

Eirikaine
Burner Inserter
Burner Inserter
Posts: 10
Joined: Sat Apr 11, 2015 7:38 pm
Contact:

Re: Auto-update on headless server

Post 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 :)
Interested by modding, multiplayer and often active on IRC
No native English speaker.

dmnc
Manual Inserter
Manual Inserter
Posts: 1
Joined: Wed Mar 02, 2016 5:52 pm
Contact:

Re: [Resolved] Auto-update on headless server

Post 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.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: [Resolved] Auto-update on headless server

Post by DaveMcW »

The command probably needs to be changed, since the headless server is free now.

Bonesaw
Manual Inserter
Manual Inserter
Posts: 3
Joined: Tue Mar 08, 2016 3:38 pm
Contact:

Re: [Resolved] Auto-update on headless server

Post 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!

Timestream
Manual Inserter
Manual Inserter
Posts: 1
Joined: Wed Jun 08, 2022 2:59 pm
Contact:

Re: [Resolved] Auto-update on headless server

Post 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)

Post Reply

Return to “Technical Help”