Skip to content

Instantly share code, notes, and snippets.

@Bluefissure
Last active September 19, 2024 05:32
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
@DrasticalFire
Copy link

DrasticalFire commented Feb 3, 2024

You may not need force_install_dir, I'm not 100% sure. If yours doesn't work, you may have to relocate your files to the same file structure I have.

And if you want to use the arguments, you just add them after the PalServer.sh in ExecStart. I found that the args lowered my server's FPS, but you will want to experiment yourself.

@travisrroy I think I broke something, I changed the file, now systemctl says no changes and removed my config. server is no longer up, I'll probably revert.... I'm really trying to wrap my head around this, I learned a bit about crontab and got that working and modified a few things to my liking, but this systemd stuff may be beyond me today. I just setup a on premise fusionPBX server at home and spent all day getting incoming and outgoing calls working so maybe I'm just burnt out.

@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