Skip to content

Commit 1516757

Browse files
committed
solves #273
1 parent ac114e6 commit 1516757

6 files changed

Lines changed: 69 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Updated docker-image pinning and github-actions versions by @jammsen (#312)
99
- Refactored from docker-compose.yml to new standard compose.yml including gitignore by @jammsen (#312)
1010
- Implemented finally a version of auto-updating the compose.yml @jahusa02 (#188)
11+
- Added the function to run a custom script, that the user can place at /palworld/custom-script - Off by default, completely opt-in and added a very explicit PSA in the README.md for it by @jammsen for @Jadiction (#273)
1112

1213
## 2025-09-06
1314

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ ENV DEBIAN_FRONTEND=noninteractive \
7777
RCON_PLAYER_DEBUG=false \
7878
RCON_PLAYER_DETECTION_STARTUP_DELAY=60 \
7979
RCON_PLAYER_DETECTION_CHECK_INTERVAL=15 \
80+
# Custom-script-settings
81+
CUSTOM_SCRIPT_ENABLED=false \
82+
CUSTOM_SCRIPT_PATH="/palworld/custom-script.sh" \
8083
# Webhook-settings
8184
WEBHOOK_ENABLED=false \
8285
WEBHOOK_DEBUG_ENABLED=false \

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ This Docker image includes a Palworld Dedicated Server based on Linux and Docker
1616

1717
___
1818

19+
> [!CAUTION]
20+
> **Public Service Announcement — Custom Script Feature**
21+
>
22+
> After many community requests, this image now supports running a custom script before the server starts.
23+
> This feature is entirely **opt-in** and is controlled by the `CUSTOM_SCRIPT_ENABLED` environment variable, which defaults to `false`.
24+
>
25+
> **This image will never ship with a custom script of any kind.**
26+
>
27+
> If you come across a Docker image that appears to be this one but includes a bundled custom script, please be careful — it is not this image and I have no affiliation with it.
28+
>
29+
> This feature was added at the request of the community. While I am glad to offer the option, I will not be providing support for it, and I refuse to accept **any liability** for any harm, data loss, corruption, or security issues that may result from its use. Please use it at your own discretion. — Public Service Announcement.
30+
1931
## Table of Contents
2032

2133
- [Docker - Palworld Dedicated Server](#docker---palworld-dedicated-server)

default.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ RCON_PLAYER_DETECTION=true
2020
RCON_PLAYER_DEBUG=false
2121
RCON_PLAYER_DETECTION_STARTUP_DELAY=60
2222
RCON_PLAYER_DETECTION_CHECK_INTERVAL=15
23+
# Custom-script-settings
24+
CUSTOM_SCRIPT_ENABLED=false
25+
CUSTOM_SCRIPT_PATH=/palworld/custom-script.sh
2326
# Webhook-settings
2427
WEBHOOK_ENABLED=false
2528
WEBHOOK_DEBUG_ENABLED=false

docs/ENV_VARS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ These settings control the behavior of the Docker container:
2929
| RCON_PLAYER_DEBUG | Set to enabled will post debug messages to the console output | false | Boolean |
3030
| RCON_PLAYER_DETECTION_STARTUP_DELAY | Initial delay for start checking for players, consider steam-updates and server start up in seconds | 60 | Integer |
3131
| RCON_PLAYER_DETECTION_CHECK_INTERVAL | Interval in seconds to wait for next check in the infinite loop | 15 | Integer |
32+
| CUSTOM_SCRIPT_ENABLED | Set to enabled will execute a custom script before the gameserver starts, see `CUSTOM_SCRIPT_PATH` | false | Boolean |
33+
| CUSTOM_SCRIPT_PATH | Absolute path to the custom script to execute; the file must exist at container runtime (e.g. mounted via a volume) | /palworld/custom-script.sh | String (absolute path) |
3234
| WEBHOOK_ENABLED | Set to enabled will send webhook notifications, NEEDS `WEBHOOK_URL` | false | Boolean |
3335
| WEBHOOK_DEBUG_ENABLED | Set to enabled will enable feedback of curl and not use --silent | false | Boolean |
3436
| WEBHOOK_URL | Defines the url the webhook to send data to | | Url |

includes/server.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,52 @@ source /includes/colors.sh
44
source /includes/rcon.sh
55
source /includes/webhook.sh
66

7+
function check_and_run_custom_script() {
8+
if [[ -z $CUSTOM_SCRIPT_ENABLED ]] || [[ "${CUSTOM_SCRIPT_ENABLED,,}" != "true" ]]; then
9+
return 0
10+
fi
11+
12+
ei ">>> Custom script is enabled"
13+
14+
# Validate CUSTOM_SCRIPT_PATH is set
15+
if [[ -z $CUSTOM_SCRIPT_PATH ]]; then
16+
ee ">>> CUSTOM_SCRIPT_PATH is not set, skipping custom script execution"
17+
return 0
18+
fi
19+
20+
# Security: require an absolute path to prevent relative-path or injection tricks
21+
if [[ "$CUSTOM_SCRIPT_PATH" != /* ]]; then
22+
ee ">>> CUSTOM_SCRIPT_PATH must be an absolute path (got: '$CUSTOM_SCRIPT_PATH'), skipping"
23+
return 0
24+
fi
25+
26+
# Security: reject any path containing '..' to prevent traversal
27+
if [[ "$CUSTOM_SCRIPT_PATH" == *".."* ]]; then
28+
ee ">>> CUSTOM_SCRIPT_PATH must not contain '..', skipping"
29+
return 0
30+
fi
31+
32+
# Check that the target is a regular file
33+
if [[ ! -f "$CUSTOM_SCRIPT_PATH" ]]; then
34+
ew "> Custom script not found at '$CUSTOM_SCRIPT_PATH', skipping"
35+
return 0
36+
fi
37+
38+
ei "> Found custom script at '$CUSTOM_SCRIPT_PATH', preparing to execute"
39+
chmod u+x "$CUSTOM_SCRIPT_PATH"
40+
41+
ei "> Executing custom script..."
42+
local custom_script_exit_code=0
43+
# The '||' prevents set -e from aborting on a non-zero exit so we can log it
44+
"$CUSTOM_SCRIPT_PATH" || custom_script_exit_code=$?
45+
46+
if [[ $custom_script_exit_code -ne 0 ]]; then
47+
ee ">>> Custom script exited with error code $custom_script_exit_code, continuing server startup"
48+
else
49+
es ">>> Custom script completed successfully"
50+
fi
51+
}
52+
753
function start_server() {
854
cd "$GAME_ROOT" || exit
955
setup_configs
@@ -20,6 +66,8 @@ function start_server() {
2066
if [[ -n $WEBHOOK_ENABLED ]] && [[ "${WEBHOOK_ENABLED,,}" == "true" ]]; then
2167
send_start_notification
2268
fi
69+
check_and_run_custom_script
70+
2371
es ">>> Starting the gameserver"
2472
./PalServer.sh "${START_OPTIONS[@]}"
2573
}

0 commit comments

Comments
 (0)