Skip to content

Instantly share code, notes, and snippets.

@Verssae
Last active January 31, 2024 07:20
Show Gist options
  • Save Verssae/076a52c542d2a3ab4904119732fef62d to your computer and use it in GitHub Desktop.
Save Verssae/076a52c542d2a3ab4904119732fef62d to your computer and use it in GitHub Desktop.
Palworld Server Auto Restart + @

Simple Scripts for Palworld Server

Useful simple scripts for Palworld Linux server.

Based on my experience about hosting palworld-server-docker on Google Cloud Platform.

Important

You should make the scripts executable (chmod +x <script_name>.sh)

Auto backup & restart server

Palworld servers currently have a memory leak issue. The following shows the memory usage when a server with 32GB of RAM, played by 2 to 5 people in the evening, was set to restart every day at 4:00 and 16:00 and operated for two days.

# Add following line to `crontab -e`
0 4,16 * * * /bin/bash /path/to/restarting.sh
image

Therefore, I am testing by changing the server to restart every 3 hours.

- 0 4,16 * * * /bin/bash /path/to/restarting.sh
+ 0 */3 * * * /bin/bash /path/to/restarting.sh

Auto Player Greeting

Schedule greetings.sh using crontab -e. For example:

* * * * * /bin/bash /path/to/greetings.sh

outputs [SYSTEM]:[12:01]<Hansae_Ju>...joined! using RCON.

Caution

When running (or restarting) the server for the first time, the player's Steam name is sometimes recorded (this seems to be a problem related to 'ShowPlayers').

How to update docker image?

docker-compose pull
docker-compose up --force-recreate --build -d
docker image prune -f // optional
#!/bin/bash
CONTAINER_NAME="palworld-server"
PLAYERS_FILE="players.txt"
if ! docker ps | grep -q $CONTAINER_NAME; then
exit 1
fi
get_current_players() {
echo "ShowPlayers" | docker exec -i palworld-server rcon-cli | \
grep -E '^[^,]+,[0-9]+,[0-9]+$' | sed 's/\x1B\[[0-9;]*m//g' | cut -d ',' -f1 | sed 's/ /_/g'
}
get_saved_players() {
if [ -f players.txt ]; then
cat players.txt
fi
}
compare_players() {
local -n _current=$1
local -n _saved=$2
local current_time=$(date '+%H:%M')
for player in "${_current[@]}"; do
if [[ ! " ${_saved[*]} " =~ " $player " ]]; then
echo "Broadcast [$current_time]:<$player>""...joined!" | docker exec -i palworld-server rcon-cli
fi
done
for player in "${_saved[@]}"; do
if [[ ! " ${_current[*]} " =~ " $player " ]]; then
echo "Broadcast [$current_time]:<$player>""...left." | docker exec -i palworld-server rcon-cli
fi
done
}
current_players=($(get_current_players))
saved_players=($(get_saved_players))
compare_players current_players saved_players
printf "%s\n" "${current_players[@]}" > $PLAYERS_FILE
#!/bin/bash
CONTAINER_NAME="palworld-server"
PLAYERS_FILE="players.txt"
SHUTDOWN_SECONDS=30
SHUTDOWN_MESSAGE="Server_will_restart_in_""$SHUTDOWN_SECONDS""_seconds."
echo "Shutdown $SHUTDOWN_SECONDS $SHUTDOWN_MESSAGE" | docker exec -i $CONTAINER_NAME rcon-cli
rm $PLAYERS_FILE
docker exec $CONTAINER_NAME backup
docker restart -t $SHUTDOWN_SECONDS $CONTAINER_NAME
@AfterWorld
Copy link

Just wondering, how can i use the Greeting script without using docker? I'm LinuxGSM and would love this if can get it

@Verssae
Copy link
Author

Verssae commented Jan 31, 2024

Just wondering, how can i use the Greeting script without using docker? I'm LinuxGSM and would love this if can get it

If you enabled RCON, you can do it using RCON client.
I recommend to install rcon-cli as standalone. Refer to DOCKERFILE:

  1. Install rcon-cli
wget -q https://github.com/gorcon/rcon-cli/releases/download/v0.10.3/rcon-0.10.3-amd64_linux.tar.gz -O - | tar -xz
sudo mv rcon-0.10.3-amd64_linux/rcon /usr/bin/rcon-cli
  1. Configure rcon-cli
    Refer to gorcon.
    You can configure using rcon.yaml or via some arguments such as -a <address:port> -p <password>.

  2. Test rcon-cli

# below ip is my docker container's internal ip. change to yours.
echo "Info" | rcon-cli -a 172.18.0.2:25575 -p mypassword
  1. Modify greetings.sh
    Just modify docker exec -i palworld-server rcon-cli to rcon-cli -a ip:port -p mypassword.

  2. Test

bash greetings.sh

See output message in the game.

Hope this helps :)

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