Skip to content

Instantly share code, notes, and snippets.

@Bluefissure
Last active February 25, 2024 20:23
Show Gist options
  • Save Bluefissure/b0fcb05c024ee60cad4e23eb55463062 to your computer and use it in GitHub Desktop.
Save Bluefissure/b0fcb05c024ee60cad4e23eb55463062 to your computer and use it in GitHub Desktop.
Some Useful PalWorld Scripts

Pal World Scripts (Linux & Bash)

Remember to replace the folder directory, <AdminPassword>, <RCONPort> to your own.

Also, you need to use crontab to schedule the following scripts if necessary.

Supervisor

I'm using supervisor to restart the service, the example config is as:

[program:pal]
command="/home/steam/.local/share/Steam/steamapps/common/PalServer/Pal/Binaries/Linux/PalServer-Linux-Test" Pal -useperfthreads -NoAsyncLoadingThread -UseMultithreadForDS
numprocs=1
process_name=pal-%(process_num)d
directory=/home/steam/.local/share/Steam/steamapps/common/PalServer
user=steam
environment=HOME="/home/steam",USER="steam"
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/pal.out
stderr_logfile=/var/log/supervisor/pal.err

Backup

#!/bin/sh
DDATE=`date "+%F-%T"`
mkdir $DDATE
cp -r /home/steam/steamapps/common/PalServer/Pal/Saved/SaveGames $DDATE/

Restart

Need to:

  • Download Releases from ARRCON
  • Have your AdminPassword ready.
  • Enable RCON in Server Settings doc
#!/bin/sh

RCON_PORT=<RCONPort>
ADMIN_PASSWORD=<AdminPassword>

echo 'broadcast Auto_Reboot_Initialized' | ./ARRCON -P $RCON_PORT -p $ADMIN_PASSWORD
echo 'save' | ./ARRCON -P $RCON_PORT -p $ADMIN_PASSWORD
echo "shutdown 300 Server_is_going_to_reboot_in_5_minutes" | ./ARRCON -P $RCON_PORT -p $ADMIN_PASSWORD
sleep 120
echo 'broadcast Server_is_going_to_reboot_in_3_minutes' | ./ARRCON -P $RCON_PORT -p $ADMIN_PASSWORD
sleep 60
echo 'broadcast Server_is_going_to_reboot_in_2_minutes' | ./ARRCON -P $RCON_PORT -p $ADMIN_PASSWORD
sleep 60
echo 'broadcast Server_is_going_to_reboot_in_60_seconds' | ./ARRCON -P $RCON_PORT -p $ADMIN_PASSWORD
sleep 50
echo 'broadcast Server_is_going_to_reboot_in_10_seconds' | ./ARRCON -P $RCON_PORT -p $ADMIN_PASSWORD
sleep 5
echo 'broadcast Server_is_going_to_reboot_in_5_seconds' | ./ARRCON -P $RCON_PORT -p $ADMIN_PASSWORD
sleep 1
echo 'broadcast Server_is_going_to_reboot_in_4_seconds' | ./ARRCON -P $RCON_PORT -p $ADMIN_PASSWORD
sleep 1
echo 'broadcast Server_is_going_to_reboot_in_3_seconds' | ./ARRCON -P $RCON_PORT -p $ADMIN_PASSWORD
sleep 1
echo 'broadcast Server_is_going_to_reboot_in_2_seconds' | ./ARRCON -P $RCON_PORT -p $ADMIN_PASSWORD
sleep 1
echo 'broadcast Server_is_going_to_reboot_in_1_second' | ./ARRCON -P $RCON_PORT -p $ADMIN_PASSWORD

Check Memory

Need to install bc by apt install bc.

#!/bin/bash

RCON_PORT=<RCONPort>
ADMIN_PASSWORD=<AdminPassword>
THRESHOLD=80

MEMORY_USAGE=$(free | grep Mem | awk '{print $3/$2 * 100.0}')

if (( $(echo "$MEMORY_USAGE > $THRESHOLD" | bc -l) )); then
    echo "Memory usage is above $THRESHOLD%. Running clean command."
    echo "broadcast Memory_Is_Above_$THRESHOLD%" | ./ARRCON -P $RCON_PORT -p $ADMIN_PASSWORD
    echo "save" | ./ARRCON -P $RCON_PORT -p $ADMIN_PASSWORD
    echo "shutdown 60 Reboot_In_60_Seconds" | ./ARRCON -P $RCON_PORT -p $ADMIN_PASSWORD
    cd ~/backups ; ./backup.sh
else
    echo "Memory usage is below $THRESHOLD%. No action required."
fi

Known Bug:

  1. Exiting the guild will cause all players who was not logged-in at the moment to corrupt their save files! (Joining another guild will exit the old one as well.) Next time they log in they'll stuck at the loading spinning black screen. You can either clean the save files of those who got corrupted or restore a backup. Now fixable by https://gist.github.com/Bluefissure/f277a3409cdaf09cddbad5983fd01f68
@cr-lgl
Copy link

cr-lgl commented Feb 5, 2024

Sometimes, if restart the service via a cronjob, the server will run, but the RCON process will not come up...

=> ss -tuplwn | grep PalServer-Linux

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))

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