OpenFactorioServerManager / factorio-server-manager

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

factorio-server-manager Autostart under Linux #358

Open Synec5 opened 1 year ago

Synec5 commented 1 year ago

Hello, can someone tell me how I have to do that so that the "factorio-server-manager" starts automatically after a reboot (or the power on the PC).

Ubuntu Server

Manual start goes after I changed to the directory.

Best regards

knoxfighter commented 1 year ago

This has nothing to do with this project, but with the operating system you use. I will not completely answer you that questions, i will just give you hints where to look at.

You basically have three options:

Fully up to you which solution is the one best suited for you.

I3lackRacer commented 1 week ago

Ok this is not the best way in any way to fix this, but I did it like this:

import requests
import time

time.sleep(30)
# Perform login request and retrieve response cookie
response = requests.post(
    'http://localhost:80/api/login',
    json={'username': 'admin', 'password': '<<ENTER PASSWORD HERE>>'}
)
cookie = response.cookies.get('authentication')
print(response.text)
print("Cookie: " + str(cookie))

# Use response cookie to perform startup request
headers = {'Cookie': f'authentication={cookie}'}
data = {'bindip': '0.0.0.0', 'savefile': 'Load Latest', 'port': 34197}
response = requests.post(
    'http://localhost:80/api/server/start',
    headers=headers,
    json=data
)
print(response.text)

I have this python script that logs in and starts the server. And using crontab -e i add a command that runs the script on reboot @reboot python3 <<your path>/start_factorio.py