thegreatstorm / game-ansible

12 stars 6 forks source link

Systemd unit file #4

Closed gelbbauch closed 3 years ago

gelbbauch commented 3 years ago

root@valheim:/etc/systemd/system# cat valheim.service [Unit] Description=Valheim game server

[Service] Type=forking ExecStart=/usr/bin/ansible-playbook /opt/server/game-ansible/valheim/ansible-playbook start.yml --extra-vars '{"app_dir":"/opt/server","name":"ServerName","world":"Dedicated","public":"1","password":"secret", "port":"2456"}' ExecStop=/usr/bin/ansible-playbook /opt/server/game-ansible/valheim/stop.yml Type=oneshot RemainAfterExit=yes

[Install] WantedBy=multi-user.target

thegreatstorm commented 3 years ago

Oh thats awesome! I personally never messed with systemd. So thats cool!

gelbbauch commented 3 years ago

Easier way to to it:

`cat << EOF > /etc/systemd/system/valheim.service [Unit] Description=Valheim game server

[Service] Type=forking ExecStart=/usr/bin/ansible-playbook /opt/server/game-ansible/valheim/start.yml --extra-vars '{"app_dir":"/opt/server","name":"Wastaken","world":"Dedicated","public":"1","password":"4Valhalla!", "port":"2456"}' ExecStop=/usr/bin/ansible-playbook /opt/server/game-ansible/valheim/stop.yml Type=oneshot RemainAfterExit=yes

[Install] WantedBy=multi-user.target EOF`

then:

systemctl daemon-reload

and

systemctl enable --now valheim.service

... to run the service on boot and start it now, all of the above ran with sudo/root permissions.

thegreatstorm commented 3 years ago

Is this something you wanted implemented or is this documentation purposes?

gelbbauch commented 3 years ago

It's up to you. I made it and use it, technically don't need this documented anymore, but I thought others might like to use systemd with the service so you can enable the server to run on boot. At least it's here if anyone else want to use it.

thegreatstorm commented 3 years ago

Added to docs. https://github.com/thegreatstorm/game-ansible/commit/5ebbc0ea3bb25ce1ff4948b1e0a71ef888f29cf8