In this post, you will learn how to create and set up a restart script for your self-installed Palworld server. Restarts can help if the Palworld server is slow (poor performance), keeps crashing or is no longer accessible.

This guide assumes that you are familiar with Linux, Docker and Docker-Compose. If you have already set up your own server with our guide, the changes should not be a problem for you.

Restart script without in-game warnings

If you just want to restart your server without the players receiving a message, this is relatively easy.

Create script

First you have to create the restart script. To do this, go to the folder in which your docker-compose.yml is already located. There you create the restart script with nano restart-palworld.sh and insert the code from the next code block.

#!/bin/bash

# Change to the directory where this script is located
cd "$(dirname "$0")"

# Stop current Docker Compose setup
docker-compose down

# Pull the latest images (not needed)
docker-compose pull

# Start Docker Compose in detached mode
docker-compose up -d

Make script executable

Then run chmod +x restart-palworld.sh after closing Nano so that the script can be executed.

Enter script as cron job

To enter the script as a cron job, you have to run 'crontab -e'. You can then choose the editor, although Nano is recommended for most. For example, for a restart at 9 p.m. I entered the following line.

0 21 * * * /root/docker-compose/palworld/restart_palworld.sh

If you don't know the full path to the file, but you are in the folder in which the file is located, the following command can help:

readlink -f restart_palworld.sh

If you don't know which times you have to enter in the crontab for other restart times of your script, the following link can help:

https://crontab.guru/

If the time on your server does not correspond to your time zone, you can use the date command to find out the current server time and then adjust this accordingly in your crontab.

If you want to set multiple restart times, you can also enter several lines in the crontab.

Advanced script with in-game warnings

Changes - docker-compose.yml

Changes that are important in the Docker Compose File of the Palworld Server: All entries should be present accordingly and 'serverip' and 'adminpassword' should be replaced with your corresponding data.

    ports:
      - target: 8211 # Gamerserver port inside of the container
        published: 8211 # Gamerserver port on your host
        protocol: udp
        mode: host
      - target: 25575 # RCON port inside of the container
        published: 25575 # RCON port on your host
        protocol: tcp
        mode: host  
    environment:
      - RCON_ENABLED=true
      - RCON_PORT=25575
  rcon:
    image: outdead/rcon:latest
    entrypoint: ['/rcon', '-a', 'serverip:25575', '-p', 'adminpassword']
    profiles: ['rcon'] 

Restart script

#!/bin/bash

# Define a function to send broadcast messages
broadcast() {
    message=${1// /_}
    docker-compose run --rm rcon "broadcast $message"
}

# Define a function to save the game
save_game() {
    docker-compose run --rm rcon save
}

# Define a function to gracefully shut down the server
shutdown_server() {
    docker-compose run --rm rcon DoExit
}

# Change to the directory where this script is located
cd "$(dirname "$0")"

# Broadcasting restart warnings
broadcast "Server will restart in 5 minutes!"
sleep 50s

broadcast "Server will restart in 4 minutes!"
sleep 50s

broadcast "Server will restart in 3 minutes!"
sleep 50s

broadcast "Server will restart in 2 minutes!"
sleep 50s

broadcast "Server will restart in 1 minute!"
sleep 50s

# Save game and broadcast message
broadcast "Saving game and preparing for restart..."
save_game

# Gracefully shut down the server
broadcast "Shutting down the server..."
shutdown_server

# Stop current Docker Compose setup
docker-compose down

# Pull the latest images
docker-compose pull

# Start Docker Compose in detached mode
docker-compose up -d

The description above is of course also valid for setting up the extended script. Have fun with your Palworld server :)