Skip to content

Instantly share code, notes, and snippets.

@tikenn
Created October 15, 2020 03:42
Show Gist options
  • Save tikenn/87e7cbe3c17adecdeeec4188e018d83e to your computer and use it in GitHub Desktop.
Save tikenn/87e7cbe3c17adecdeeec4188e018d83e to your computer and use it in GitHub Desktop.
Portal Knights systemd file for running as a service through screen and wine
##############################
# How to Setup New Server
##############################
#
# Create a directory in /srv/portal_knights_dedicated_server/XX where XX is a name like 'personal'
# Copy the E:\Steam\steamapps\common\Portal Knights\dedicated_server.zip to the new folder and extract
#
# Enable/Start systemd service
# systemctl enable portal-knights@personal
# systemctl start portal-knights@personal
#
# To run multiple servers simply create a new dir structure and enable/start it
# systemctl enable portal-knights@friends
# systemctl start portal-knights@friends
###############################
# How to Manage Screen
###############################
#
# Switch to appropriate user (portal-knights)
# Run 'screen -ls' to see all screens currently running
# Run 'screen -r portal-knights-<folder_name> to attach to screen running server name <folder_name>
[Unit]
Description=Portal Knights Dedicated Server - %i
After=network.target
[Service]
Type=simple
Restart=on-failure
RestartSec=60s
# WorkingDirectory=/srv/portal_knights_dedicated_server/%i
# ------------------------------
# User Settings
# ------------------------------
# Users Database is not available from within the unit, only root and specified User= is available, everybody else is nobody
# PrivateUsers=true
User=portal-knights
Group=portal-knights
# ------------------------------
# System security
# ------------------------------
# Read only mapping of /usr, /boot, and /etc
ProtectSystem=full
# /home/ root, and /run/user will appeart to be empty from within the unit.
# ProtectHome=true
# System tunabled in /proc/* are read-only in the unit
ProtectKernelTunables=true
# Block module system calls
# ProtectKernelModules=true
# ------------------------------
# Service Start/Stop/Restart
# ------------------------------
ExecStart=/bin/sh -c '/usr/bin/screen -DmS portal-knights-%i /usr/bin/wine /srv/portal_knights_dedicated_server/%i/pk_dedicated_server.exe -config /srv/portal_knights_dedicated_server/%i/server_config.json && echo %i'
# ExecStop=/usr/bin/screen -p 0 -S portal-knights-%i -X quit
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment