Skip to content

Instantly share code, notes, and snippets.

@Bluefissure
Last active February 25, 2024 20:23
Show Gist options
  • Star 48 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • 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
@Bluefissure
Copy link
Author

Bluefissure commented Jan 24, 2024

You can also check my new project that generates the server configuration file in a friendly way! https://github.com/Bluefissure/pal-conf

@AsthmaQueen
Copy link

Thanks these have been really helpful, and have gotten most of way there to automating least restart process.

I'm having a bit of issues with supervisord still, I am trying to run it on main user (steam being secondary), and its not able to locate the command.

My Steam put normally behind /home/steam/.local/share/Steam/... and is normally just /home/steam/Steam/... I created a symlink/directory for the executable to where you have it, since read when figuring out steamcmd this was allegedly good idea for the sdk64 sdk32

but supervisor spits out this error still,

INFO spawnerr: can't find command '/home/steam/.local/share/Steam/steamapps/common/PalServer/Pal/Binaries/Linux/PalServer-Linux-Test'

I'm still a bit of a linux noob, so if I missed something obvious thats messing with authorization pointers would be appreciated.

so far got everything to work just can't start up the server automatically

Supervisord doesn't seem to work when ran in steam user console.

@Bluefissure
Copy link
Author

Thanks these have been really helpful, and have gotten most of way there to automating least restart process.

I'm having a bit of issues with supervisord still, I am trying to run it on main user (steam being secondary), and its not able to locate the command.

My Steam put normally behind /home/steam/.local/share/Steam/... and is normally just /home/steam/Steam/... I created a symlink/directory for the executable to where you have it, since read when figuring out steamcmd this was allegedly good idea for the sdk64 sdk32

but supervisor spits out this error still,

INFO spawnerr: can't find command '/home/steam/.local/share/Steam/steamapps/common/PalServer/Pal/Binaries/Linux/PalServer-Linux-Test'

I'm still a bit of a linux noob, so if I missed something obvious thats messing with authorization pointers would be appreciated.

so far got everything to work just can't start up the server automatically

Supervisord doesn't seem to work when ran in steam user console.

You don't need to add symlinks for that, you can simply change the directory in the command /home/steam/.local/share/Steam/steamapps/common/PalServer to your own (as well as in thedirectory parameter)

@AsthmaQueen
Copy link

You don't need to add symlinks for that, you can simply change the directory in the command /home/steam/.local/share/Steam/steamapps/common/PalServer to your own (as well as in thedirectory parameter)

That was first thing I tried with same issue that supervisor can't access the executable.

Do I need to do a chmod or anything like that?

This is run off main user, with the server under steam user like yours.

I might be missing something basic that let's stuff like supervisor see across accounts?

@Bluefissure
Copy link
Author

You don't need to add symlinks for that, you can simply change the directory in the command /home/steam/.local/share/Steam/steamapps/common/PalServer to your own (as well as in thedirectory parameter)

That was first thing I tried with same issue that supervisor can't access the executable.

Do I need to do a chmod or anything like that?

This is run off main user, with the server under steam user like yours.

I might be missing something basic that let's stuff like supervisor see across accounts?

Yes, for the very first time executing, you need to chmod PalServer-Linux-Test in the user you're going to execute the command.

If you take a look at the official PalServer.sh, it does it for you, as

$ cat ./PalServer.sh
#!/bin/sh
UE_TRUE_SCRIPT_NAME=$(echo \"$0\" | xargs readlink -f)
UE_PROJECT_ROOT=$(dirname "$UE_TRUE_SCRIPT_NAME")
chmod +x "$UE_PROJECT_ROOT/Pal/Binaries/Linux/PalServer-Linux-Test"
"$UE_PROJECT_ROOT/Pal/Binaries/Linux/PalServer-Linux-Test" Pal "$@"

The supervisor script only execute the last command, you need to chmod or run the official script once.

If it still cannot execute, I recommend you double check the priviledges of the file owners by ls -l.

@AsthmaQueen
Copy link

AsthmaQueen commented Jan 25, 2024

Yes, for the very first time executing, you need to chmod PalServer-Linux-Test in the user you're going to execute the command.
,,,

Thanks, this was issue seems like will see if it works on next restart, as well there was write access issues with how logfiles were being written in supervisor so ended up changing it to just logfile=logs/supervisord.log as it was throwing errors similar to https://stackoverflow.com/questions/35273197/unable-to-start-service-with-nohup-due-to-info-spawnerr-unknown-error-making-d

Edit: Nevermind error I was seeing, exit code 127 is just another version of command not found.

@AsthmaQueen
Copy link

AsthmaQueen commented Jan 29, 2024

I ended up using linuxGSM and a combo of these scripts, and that is working very nicely.

https://linuxgsm.com/servers/pwserver/

I followed that, and in the home folder of /home/pwserver I put a few of my custom scripts, based on these.
and assigned crontab to them as well, in linuxgsm they mention whats recommended, and when your in user pwserver just type crontab -e to add more commands.

I added restart every 6 hours and a save command every 15 minutes (since we had some issues with roll backs before moving to linuxgsm)

restart script,

#!/bin/sh

RCON_PORT=<RCON Port>
ADMIN_PASSWORD=<admin password>

echo 'broadcast Scheduled_Server_Restart' | ./ARRCON -P $RCON_PORT -p $ADMIN_PASSWORD
sleep 1
echo 'broadcast 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 'save' | ./ARRCON -P $RCON_PORT -p $ADMIN_PASSWORD
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
./pwserver stop
sleep 25
./backup.sh
./pwserver start

Backup Script

!/bin/bash

dt=`date +"%d-%m-%Y %T"`

cd ~

rclone copy --update --verbose --transfers 20 --retries 5 --stats 1s "/home/pwserver/serverfiles/Pal/Saved/SaveGames/" "BACKUP/current" --backup-dir="BACKUP/archive/$dt"

cd ~

Save script

#!/bin/sh

RCON_PORT=<rcon port>
ADMIN_PASSWORD=<admin password>

echo 'save' | ./ARRCON -P $RCON_PORT -p $ADMIN_PASSWORD

RCON is just the ARRCON executable in my case sitting in /home/pwserver

my crontab -e looks like

*/5 * * * * /home/pwserver/pwserver monitor > /dev/null 2>&1
*/30 * * * * /home/pwserver/pwserver update > /dev/null 2>&1
0 0 * * 0 /home/pwserver/pwserver update-lgsm > /dev/null 2>&1
*/15 * * * * /home/pwserver/save.sh > /dev/null 2>&1
0 */6 * * * /home/pwserver/restart.sh > /dev/null 2>&1

monitor is responsible for checking if server is running and restarting it if nessicary, update checks for steam updates and will stop and update server if its avaliable, I just wanted regular restarts that are graceful since linuxgsm wasn't offering that.

@DrasticalFire
Copy link

Ok I figured out how to make your systemd file work. with that said, I am trying to figure out how to make it also run STEAMCMD's app update prior to the server application running, any insight on this?

I'm trying to read through documentation to figure this out.

@Bluefissure

@travisrroy
Copy link

travisrroy commented Feb 3, 2024

Ok I figured out how to make your systemd file work. with that said, I am trying to figure out how to make it also run STEAMCMD's app update prior to the server application running, any insight on this?

I'm trying to read through documentation to figure this out.

@Bluefissure

Hey @DrasticalFire, here is my systemd service file. I adapted it from a Satisfactory tutorial and it has been working perfectly since day 2 after release.

Server update? I just run systemctl restart palworld and steamcmd downloads the update and it fires back up. Power goes out? Server starts when the machine starts (assuming you do systemctl enable).

Do note that this is setup to kill the server if it hits 16GB used.

[Unit]
Description=Palworld dedicated server
Wants=network-online.target
After=syslog.target network.target nss-lookup.target network-online.target

[Service]
Environment="LD_LIBRARY_PATH=./linux64"
ExecStartPre=/usr/games/steamcmd +login anonymous +force_install_dir "/home/steam/PalworldDedicatedServer" +app_update 2394010 validate +quit
ExecStart=/home/steam/PalworldDedicatedServer/PalServer.sh
User=steam
Group=steam
StandardOutput=journal
MemoryMax=16G
Restart=on-failure
KillSignal=SIGINT
WorkingDirectory=/home/steam/PalworldDedicatedServer

[Install]
WantedBy=multi-user.target

@DrasticalFire
Copy link

DrasticalFire commented Feb 3, 2024

Hey @travisrroy

Ok I figured out how to make your systemd file work. with that said, I am trying to figure out how to make it also run STEAMCMD's app update prior to the server application running, any insight on this?
I'm trying to read through documentation to figure this out.
@Bluefissure

Hey @DrasticalFire, here is my systemd service file. I adapted it from a Satisfactory tutorial and it has been working perfectly since day 2 after release.

Server update? I just run systemd restart palworld and steamcmd downloads the update and it fires back up. Power goes out? Server starts when the machine starts (assuming you do systemd enable).

Do note that this is setup to kill the server if it hits 16GB used.

[Unit]
Description=Palworld dedicated server
Wants=network-online.target
After=syslog.target network.target nss-lookup.target network-online.target

[Service]
Environment="LD_LIBRARY_PATH=./linux64"
ExecStartPre=/usr/games/steamcmd +login anonymous +force_install_dir "/home/steam/PalworldDedicatedServer" +app_update 2394010 validate +quit
ExecStart=/home/steam/PalworldDedicatedServer/PalServer.sh
User=steam
Group=steam
StandardOutput=journal
MemoryMax=16G
Restart=on-failure
KillSignal=SIGINT
WorkingDirectory=/home/steam/PalworldDedicatedServer

[Install]
WantedBy=multi-user.target

Greetings, here is my systemd file, I notice our install directories are different, would i adopt yours without the "+force_install_dir" argument? I would have to set my RAM limt to about 10-12Gigs.

[program:pal]
command="/home/steam/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/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


My updated systemd should be? How would I add the arguments "-useperfthreads -NoAsyncLoadingThread -UseMultithreadForDS"

[Unit]
Description=Palworld dedicated server
Wants=network-online.target
After=syslog.target network.target nss-lookup.target network-online.target

[Service]
Environment="LD_LIBRARY_PATH=./linux64"
ExecStartPre=/usr/games/steamcmd +login anonymous +app_update 2394010 validate +quit
ExecStart=/home/steam/Steam/steamapps/common/PalServer/PalServer.sh
User=steam
Group=steam
StandardOutput=journal
MemoryMax=12G
Restart=on-failure
KillSignal=SIGINT
WorkingDirectory=/home/steam/Steam/steamapps/common/PalServer

[Install]
WantedBy=multi-user.target

@travisrroy
Copy link

travisrroy 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 add it in with your directory path or 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.

@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