Skip to content

Instantly share code, notes, and snippets.

@Insax
Last active July 25, 2024 04:33
Show Gist options
  • Save Insax/37617020076cfad912222f57d3cc270a to your computer and use it in GitHub Desktop.
Save Insax/37617020076cfad912222f57d3cc270a to your computer and use it in GitHub Desktop.
Improved & Automated Palworld Setup for Linux Dedicated Servers

Improved & Automated Palworld Setup for Linux Dedicated Servers

Introduction

This small guide will introduce you to some helpful scripts to automatically manage a palworld server, please use all scripts at your own discretion This Guide will cover the following automated functionalities.

This guide is also aimed at debian destributions based on it. (Ubuntu etc.)

  • Automated PalWorld Gameserver start on server start
  • Automated PalWorld Gameserver restart in case of a crash
  • Automated PalWorld Gameserver restart every day at 4am
  • Automated PalWorld Gameserver file backups every hour, day and week

Getting Started

Before you start of with this, please verify that you are indeed on a linux based server and you do have the ability to READ and TYPE. Please also read this guide once before you start so you know what you are about to do.

Requirements

  • Please follow all the steps from the official guide https://tech.palworldgame.com/dedicated-server-guide#linux, this guide is based on it, any deviation must be adjusted in the scripts
  • This guide uses https://github.com/gorcon/rcon-cli to shutdown the Server, please download and install it in a suitable place (for example /usr/local/bin), the config in the scripts is located in /home/steam/rcon.yaml, an example config has been provided - also you have to enable RCON Access and an RCON Port in your palworld config

Step 1: Setup an Automated Start & Crash Recovery

In order to to achieve that we will use https://wiki.debian.org/systemd - check the palworld.service file, which needs to placed at /etc/systemd/system/palworld.service Please recheck the path to steamcmd and the PalServer.sh if it is indeed correct. Also check the user and group - for security reasons the server should never run as user root

Then run (as root or using sudo) systemctl daemon-reload systemctl enable palworld

To veryfy if it works just run systemctl start palworld (this will update and start the Gameserver)

Step 2: Setup a scheduled Restart and Automated backup

We add to scripts anywhere on the filesystem, in my case i chose the /home/steam/ directory but finally its up to you.

Script 1: Shutdown Script (which will cause a restart thanks to our systemd entry) shutDownScript.sh

Script 2: Backup Script - which will backup every hour, will keep the last 5 copies of every hour, and will also do a daily and weekly backup backUpScript.sh

In order to achieve this we will use https://wiki.debian.org/cron Type in (as user steam in this case) crontab -e and edit the file that it looks like the crontab.sh file.

This settings will cause the backUpScript.sh to run every hour and the shutDownScript.sh every day at 4am SERVERTIME

Then add the 2 scripts backUpScript.sh and shutDownScript.sh to your /home/steam folder.

both scripts need a chmod +x in order to be used. you can test all scripts by execting them manually

Conclusion

If you did everything correctly you now have the ability to backup and automatically restart your palworld Server on a Linux Server

Frequently Asked Questions (FAQs)

  • Will you provide instructions for XXXXXX

    • No
  • Something is not working as intended!

    • Reread the guide, verify paths and check if everything is correct
#!/bin/bash
TARGET_FOLDER="/home/steam/Steam/steamapps/common/PalServer/Pal/Saved/SaveGames/"
BACKUP_FOLDER="/home/steam/backups"
#Create backup dir in case it does not exist
mkdir -p "$BACKUP_FOLDER"
# Hourly backups
HOUR_FILE="$BACKUP_FOLDER/hourly_$(date +\%H).tar.gz"
tar -czf "$HOUR_FILE" "$TARGET_FOLDER"
# Keep only last 5 hourly backups
ls -tpd $BACKUP_FOLDER/* | grep hourly | tail -n +6 | xargs -I {} rm -- {}
# Daily backup at 4am
if [ "$(date +\%H)" == "04" ]; then
DAY_FILE="$BACKUP_FOLDER/daily_$(date +\%F).tar.gz"
cp "$HOUR_FILE" "$DAY_FILE"
fi
# Weekly backup at Sunday 4am
if [ "$(date +\%u)" == "7" ] && [ "$(date +\%H)" == "04" ]; then
WEEK_FILE="$BACKUP_FOLDER/weekly_$(date +\%Y-\%V).tar.gz"
cp "$DAY_FILE" "$WEEK_FILE"
fi
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
0 4 * * * /home/steam/shutDownScript.sh
0 * * * * /home/steam/backUpScript.sh
[Unit]
Description=PalWorld Server
After=network.target
[Service]
WorkingDirectory=/home/steam/Steam/steamapps/common/PalServer
ExecStartPre=/usr/games/steamcmd +login anonymous +app_update 2394010 validate +quit
ExecStart=/home/steam/Steam/steamapps/common/PalServer/PalServer.sh
Restart=always
User=steam
Group=steam
[Install]
WantedBy=multi-user.target
default:
address: "" # host:port, for example 127.0.0.1:16260
password: ""
log: "rcon-default.log"
type: "" # rcon, telnet, web.
timeout: "10s"
palworld:
address: "127.0.0.1:54655" # host:port, 127.0.0.1 should always work, please adjust to your set rcon port in palworld config
password: "superSafePassword"
log: "rcon-default.log"
type: "rcon" # rcon, telnet, web.
timeout: "10s"
#!/bin/bash
/usr/local/bin/rcon -c /home/steam/rcon.yaml -e palworld "broadcast Saving_Map_&_Server"
/usr/local/bin/rcon -c /home/steam/rcon.yaml -e palworld "save"
#Sleep here so we can save no matter the shutdown time.
sleep 10
/usr/local/bin/rcon -c /home/steam/rcon.yaml -e palworld "broadcast Initiating_Automated_Shutdown"
/usr/local/bin/rcon -c /home/steam/rcon.yaml -e palworld "shutdown 300"
@httpsergio
Copy link

Hi,
The rcon is stopping the server but not starting it automatically?

@namomitk
Copy link

namomitk commented Feb 1, 2024

That is the expected behavior. RCON is only available when the server is online. Depending on the OS you are running your server on you will need to restart the server another way. Be it init or systemctl etc.

If using *nix; did you follow step one and systemctl enable palworld ?

@httpsergio
Copy link

I was trying to understand all the steps and did not understood why the server is shutdown daily but not started again automatically. Maybe it can cause some confusion to others not having a automated start in the script.

I've not yet implemented it but will do later.

Thanks for the work! :)

@namomitk
Copy link

namomitk commented Feb 1, 2024

This is not my work. Just an appreciative leech who didn’t want to write his own scripts. :) Doing my part.

The server provided by the game developer has a memory leak. The server is shutdown daily in order to prevent this from being an issue. The service file is responsible for immediately restarting the server after it has been shut down via the rcon command. See https://gist.github.com/Insax/37617020076cfad912222f57d3cc270a#file-palworld-service Line:9

@httpsergio
Copy link

ups, you are right, the service has a restart always! Thanks for the help!

@cr-lgl
Copy link

cr-lgl commented Feb 5, 2024

I use this method, but on restarts, the RCON port often fails to start... 😢

udp   UNCONN 6912   0              0.0.0.0:8211       0.0.0.0:*    users:(("PalServer-Linux",pid=40235,fd=43))
udp   UNCONN 1280   0              0.0.0.0:27015      0.0.0.0:*    users:(("PalServer-Linux",pid=40235,fd=26))
tcp   LISTEN 0      1              0.0.0.0:1985       0.0.0.0:*    users:(("PalServer-Linux",pid=40235,fd=44))
tcp   LISTEN 0      128          127.0.0.1:32993      0.0.0.0:*    users:(("PalServer-Linux",pid=40235,fd=14))

@httpsergio
Copy link

httpsergio commented Feb 5, 2024

Did you changed the in PalWorldSettings.ini:

RCONEnabled=True,RCONPort=25575

Then in the rcon.yaml you should put the palworld server admin password and the correct 127.0.0.1:25575

@jjwong
Copy link

jjwong commented Feb 12, 2024

thanks, the backup script is super helpful. I went with ARRCON to do the shutdowns.

@ucolaf
Copy link

ucolaf commented Mar 8, 2024

Thanks for the backup script, I'm using this now.
But I use a different method to restart the server

I entered the crontab as root
0 4 * * * systemctl restart palworld

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment