Skip to content

Running the Server Unattended (as a Service)

Tobias Svenblad edited this page Jan 27, 2024 · 1 revision

Introduction

Systemd is a powerful tool that manages system and service processes in Linux operating systems. It offers great adaptability and is widely used across various Linux distributions. Utilizing systemd to manage the Palworld dedicated server boosts its reliability and efficiency by automatically restarting the server after unexpected crashes and starting it up during system boot.

Running the Palworld server as a systemd service simplifies the process of keeping the server up-to-date and functional, resulting in a smoother gaming experience. This guide will demonstrate how to set up a systemd service for the Palworld server, ensuring the server is automatically updated and managed effectively.

Prerequisites

Before proceeding with the systemd service setup, ensure the following prerequisites are met:

  1. Linux System with systemd: Verify that your Linux distribution uses systemd. Most modern Linux distributions like Ubuntu, Arch Linux, CentOS, and Fedora come with systemd preconfigured. You can check this by running systemctl --version in your terminal. If you run a system that does not have systemd in its software repository, such as Alpine Linux, you need to adapt the service to your software of choice.

  2. SteamCMD Installation: SteamCMD is a command-line version of the Steam client. It's essential for managing and updating game servers like Palworld. If you haven't installed SteamCMD yet, follow the previous steps in the guide.

  3. Access Rights: Ensure you have the necessary permissions to create and modify system files, typically requiring superuser (root) access.

Once these prerequisites are in place, you can proceed with setting up the systemd service for your Palworld server. The following sections will guide you through creating and configuring the systemd unit file, customizing it to your server's specifications, and managing the service effectively.

Creating the Palworld server systemd daemon

Start by creating a new file with sudo nano /etc/systemd/system/palworld.service (or other preferred text editor) and enter the content from the file /etc/systemd/system/palworld.service found in this repo.

For your convenience, it has also been pasted below, but always refer to the source files for the latest changes.

[Unit]
Description=Palworld Dedicated Server
Documentation=https://github.com/tsvenbla/az-palworld-server
Wants=network-online.target
After=syslog.target network.target nss-lookup.target network-online.target

[Service]
# Paths and Environment
Environment="LD_LIBRARY_PATH=./linux64"
WorkingDirectory=/home/steam

# User and Group
User=steam
Group=steam

# Executables
ExecStartPre=/usr/games/steamcmd +force_install_dir /home/steam/palworld_server +login anonymous +app_update 2394010 validate +quit
ExecStart=/home/steam/palworld_server/PalServer.sh -useperfthreads -NoAsyncLoadingThread -UseMultithreadForDS

# Service Management
Restart=on-failure
RestartSec=5s
TimeoutStartSec=3min
TimeoutStopSec=90s

# Security Settings
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=full
LimitNOFILE=2048

# Output
StandardOutput=journal

[Install]
WantedBy=multi-user.target

If you are not running the Palworld server under the steam user, remember to change it. You might also want to adjust the parameters to match your desired configuration, especially the TimeoutStartSec and TimeoutStopSec if you are running on older hardware.

The above configuration will have the server logs written to the system Journal. If you do not wish for this to happen and would rather have log and error messages sent to files on disk, you can add the following two directives to the [Service] section of the Unit file. Bear in mind that if you do so, the log files will grow without limit if you do not also set up a log rotation scheme such as configuring logrotate to archive and rotate logs for you. That configuration is beyond the scope of this article. With that in mind, to log to disk rather than the journal, add these directives:

[Service]
...
# Output to log files
StandardOutput=append:/var/log/palworld.log
StandardError=append:/var/log/palworld.err
...

After creating the service, you will need to execute a daemon-reload to load the new service into systemd:

sudo systemctl daemon-reload

To enable and start the service, use the following two commands respectively:

sudo systemctl enable palworld
sudo systemctl start palworld

You can check the status with sudo systemctl status palworld.service. If configured correctly the output should look something like:

● palworld.service - Palworld Dedicated Server
     Loaded: loaded (/etc/systemd/system/palworld.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2024-01-27 20:42:10 UTC; 11s ago
       Docs: https://github.com/tsvenbla/az-palworld-server
    Process: 4542 ExecStartPre=/usr/games/steamcmd +force_install_dir /home/steam/palworld_server +login anonymous +app_update 2394010 validate +quit (>
   Main PID: 4566 (PalServer.sh)
      Tasks: 32 (limit: 38434)
     Memory: 1.1G
        CPU: 10.136s
     CGroup: /system.slice/palworld.service
             ├─4566 /bin/sh /home/steam/palworld_server/PalServer.sh -useperfthreads -NoAsyncLoadingThread -UseMultithreadForDS
             └─4573 /home/steam/palworld_server/Pal/Binaries/Linux/PalServer-Linux-Test Pal -useperfthreads -NoAsyncLoadingThread -UseMultithreadForDS

Next Steps

If you haven't already, ensure the Linux firewall is configured.

Troubleshooting

If you encounter any issues while setting up the systemd service, consider the following troubleshooting tips:

  1. Verify that all paths and user permissions in the systemd service file are correct.
  2. Ensure that SteamCMD is properly installed and updated.
  3. Check for syntax errors in the systemd service file.
  4. If the service fails to start, examine the logs using journalctl -u palworld.service for detailed error messages.

Additional Notes

This guide is based on Palworld and SteamCMD versions available as of 27/01/2024. Future updates might require adjustments to this setup. Feedback and contributions to this guide are welcome. If you find any discrepancies or have suggestions for improvement, please reach out or contribute to the documentation.