Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add pre and post update, start, backup, and shutdown discord hooks. #172

Merged
merged 32 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
4a25061
add hooks
zick-debug Jan 28, 2024
4010579
-X is assumed when using -d arg for curl
zick-debug Jan 28, 2024
2bc3df6
Merge branch 'main' into feature/discord-webhooks
zick-debug Jan 28, 2024
aa26185
Merge branch 'main' into feature/discord-webhooks
zick-debug Jan 31, 2024
65aae40
testing new discord vars
zick-debug Feb 1, 2024
58b2033
Merge branch 'main' into feature/discord-webhooks
zick-debug Feb 4, 2024
5ed5522
solve linting errors
zick-debug Feb 4, 2024
96e73b9
dockerfile linting
zick-debug Feb 4, 2024
cd04e85
remove comments
zick-debug Feb 4, 2024
97bd840
define max_timeout
zick-debug Feb 4, 2024
a39eca7
testing new discord msgs
zick-debug Feb 4, 2024
be93af2
update printf formatting to interpret escapes
zick-debug Feb 4, 2024
c1bcdc9
update help msg
zick-debug Feb 4, 2024
b932e6d
update help params
zick-debug Feb 4, 2024
54be46f
validate timeout integer and update discord cmd
zick-debug Feb 4, 2024
1a8ae98
tested basic discord functionality
zick-debug Feb 5, 2024
896c041
updated docs
zick-debug Feb 5, 2024
0a2ec77
gramma error in backup webhooks
zick-debug Feb 5, 2024
1ca842d
fix unintentional indirect expansion syntax
zick-debug Feb 5, 2024
619a143
fix linting error
thijsvanloef Feb 5, 2024
72c61fa
move discord from usr/local/bin
thijsvanloef Feb 5, 2024
4464ba0
fix some more linting
thijsvanloef Feb 5, 2024
34470e6
revert printf
thijsvanloef Feb 5, 2024
21d7fec
updated hooks to use less args, use webhook url var, default webhook …
zick-debug Feb 5, 2024
14e2571
dont set discord update status to run in background
zick-debug Feb 5, 2024
5dc0234
no bare url in md
zick-debug Feb 5, 2024
2b647ce
url is in wrong position in readme
zick-debug Feb 5, 2024
4126e26
added allowed vals for discord msgs
zick-debug Feb 5, 2024
5d2d591
check for new URL var instead of ID
zick-debug Feb 5, 2024
956f4ad
resolve connect-timeout and max-timeout not an integer logs
zick-debug Feb 5, 2024
56f20b7
remove "The" as other messages do not include it.
zick-debug Feb 6, 2024
587b346
change text
thijsvanloef Feb 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 64 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,30 @@ It is highly recommended you set the following environment values before startin
* PUID
* PGID

| Variable | Info | Default Values | Allowed Values |
|------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------|------------------------------------------------------------------------------------------------------------|
| TZ | Timezone used for time stamping backup server | UTC | See [TZ Identifiers](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#Time_Zone_abbreviations) |
| PLAYERS* | Max amount of players that are able to join the server | 16 | 1-32 |
| PORT* | UDP port that the server will expose | 8211 | 1024-65535 |
| PUID* | The uid of the user the server should run as | 1000 | !0 |
| PGID* | The gid of the group the server should run as | 1000 | !0 |
| MULTITHREADING** | Improves performance in multi-threaded CPU environments. It is effective up to a maximum of about 4 threads, and allocating more than this number of threads does not make much sense. | false | true/false |
| COMMUNITY | Whether or not the server shows up in the community server browser (USE WITH SERVER_PASSWORD) | false | true/false |
| PUBLIC_IP | You can manually specify the global IP address of the network on which the server running. If not specified, it will be detected automatically. If it does not work well, try manual configuration. | | x.x.x.x |
| PUBLIC_PORT | You can manually specify the port number of the network on which the server running. If not specified, it will be detected automatically. If it does not work well, try manual configuration. | | 1024-65535 |
| SERVER_NAME | A name for your server | | "string" |
| SERVER_PASSWORD | Secure your community server with a password | | "string" |
| ADMIN_PASSWORD | Secure administration access in the server with a password | | "string" |
| UPDATE_ON_BOOT** | Update/Install the server when the docker container starts (THIS HAS TO BE ENABLED THE FIRST TIME YOU RUN THE CONTAINER) | true | true/false |
| RCON_ENABLED*** | Enable RCON for the Palworld server | true | true/false |
| RCON_PORT | RCON port to connect to | 25575 | 1024-65535 |
| QUERY_PORT | Query port used to communicate with Steam servers | 27015 | 1024-65535 |
| Variable | Info | Default Values | Allowed Values |
|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------|---------------------------------------------------------------------------------------|
| TZ | Timezone used for time stamping backup server | UTC | See [TZ Identifiers](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#Time_Zone_abbreviations) |
| PLAYERS* | Max amount of players that are able to join the server | 16 | 1-32 |
| PORT* | UDP port that the server will expose | 8211 | 1024-65535 |
| PUID* | The uid of the user the server should run as | 1000 | !0 |
| PGID* | The gid of the group the server should run as | 1000 | !0 |
| MULTITHREADING** | Improves performance in multi-threaded CPU environments. It is effective up to a maximum of about 4 threads, and allocating more than this number of threads does not make much sense. | false | true/false |
| COMMUNITY | Whether or not the server shows up in the community server browser (USE WITH SERVER_PASSWORD) | false | true/false |
| PUBLIC_IP | You can manually specify the global IP address of the network on which the server running. If not specified, it will be detected automatically. If it does not work well, try manual configuration. | | x.x.x.x |
| PUBLIC_PORT | You can manually specify the port number of the network on which the server running. If not specified, it will be detected automatically. If it does not work well, try manual configuration. | | 1024-65535 |
| SERVER_NAME | A name for your server | | "string" |
| SERVER_PASSWORD | Secure your community server with a password | | "string" |
| ADMIN_PASSWORD | Secure administration access in the server with a password | | "string" |
| UPDATE_ON_BOOT** | Update/Install the server when the docker container starts (THIS HAS TO BE ENABLED THE FIRST TIME YOU RUN THE CONTAINER) | true | true/false |
| RCON_ENABLED*** | Enable RCON for the Palworld server | true | true/false |
| RCON_PORT | RCON port to connect to | 25575 | 1024-65535 |
| QUERY_PORT | Query port used to communicate with Steam servers | 27015 | 1024-65535 |
| PRE_INIT_HOOK | You can add a custom sh commands before initializing | | sh command |
| POST_INIT_HOOK | You can add a custom sh commands after initializing | | sh command |
| PRE_BACKUP_HOOK | You can add a custom sh commands before a backup is created | | sh command |
| POST_BACKUP_HOOK | You can add a custom sh commands after a backup is created | | sh command |
| PRE_SHUTDOWN_HOOK | You can add a custom sh commands before pid is killed | | sh command |
| POST_SHUTDOWN_HOOK | You can add a custom sh commands after pid is killed | | sh command |

*highly recommended to set

Expand Down Expand Up @@ -203,6 +209,46 @@ Please keep in mind that the ENV variables will always overwrite the changes mad

For a more detailed list of explanations of server settings go to: [shockbyte](https://shockbyte.com/billing/knowledgebase/1189/How-to-Configure-your-Palworld-server.html)

## Using sh hooks

### Create a backup

Backup the server whenever it is gracefully shut down.

docker run:

```sh
-e POST_SHUTDOWN_HOOK=backup
```

docker compose:

```yaml
- POST_SHUTDOWN_HOOK=backup
```

### Send discord webhooks

1. Generate a webhook url for your discord server in your discord's server settings.

2. You can use the discord webhook in the pre init hook like so:

send discord message with docker run:

```sh
-e DISCORD_WEBHOOK="https://discord.com/api/webhooks/xxxx/xxxxx" \
-e DISCORD_PRE_INIT_MESSAGE="Server initializing" \
-e PRE_INIT_HOOK='curl -sfSL -H "Content-Type: application/json" -d "{\"username\":\"Palworld\",\"content\":\"$DISCORD_PRE_INIT_MESSAGE\"}" "$DISCORD_WEBHOOK"'
```

send discord message with docker compose:

```yaml
- DISCORD_WEBHOOK=https://discord.com/api/webhooks/xxxx/xxxxx
- DISCORD_PRE_INIT_MESSAGE="Server initializing..."
- 'PRE_INIT_HOOK=curl -sfSL -H "Content-Type: application/json" -d "{\"username\":\"Palworld\",\"content\":\"$$(eval echo $$DISCORD_PRE_INIT_MESSAGE)\"}" $$DISCORD_WEBHOOK'
thijsvanloef marked this conversation as resolved.
Show resolved Hide resolved
```

## Reporting Issues/Feature Requests

Issues/Feature requests can be submitted by using [this link](https://github.com/thijsvanloef/palworld-server-docker/issues/new/choose).
Expand Down
46 changes: 23 additions & 23 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
services:
palworld:
image: thijsvanloef/palworld-server-docker:latest
restart: unless-stopped
container_name: palworld-server
ports:
- 8211:8211/udp
- 27015:27015/udp # Required if you want your server to show up in the community servers tab
environment:
- PUID=1000
- PGID=1000
- PORT=8211 # Optional but recommended
- PLAYERS=16 # Optional but recommended
- SERVER_PASSWORD="worldofpals" # Optional but recommended
- MULTITHREADING=true
- RCON_ENABLED=true
- RCON_PORT=25575
- TZ=UTC
- ADMIN_PASSWORD="adminPasswordHere"
- COMMUNITY=false # Enable this if you want your server to show up in the community servers tab, USE WITH SERVER_PASSWORD!
- SERVER_NAME="World of Pals"
- SERVER_DESCRIPTION=""
volumes:
- ./palworld:/palworld/
palworld:
image: thijsvanloef/palworld-server-docker:latest
restart: unless-stopped
container_name: palworld-server
ports:
- 8211:8211/udp
- 27015:27015/udp # Required if you want your server to show up in the community servers tab
environment:
- PUID=1000
- PGID=1000
- PORT=8211 # Optional but recommended
- PLAYERS=16 # Optional but recommended
- SERVER_PASSWORD="worldofpals" # Optional but recommended
- MULTITHREADING=true
- RCON_ENABLED=true
- RCON_PORT=25575
- TZ=UTC
- ADMIN_PASSWORD="adminPasswordHere"
- COMMUNITY=false # Enable this if you want your server to show up in the community servers tab, USE WITH SERVER_PASSWORD!
- SERVER_NAME="World of Pals"
- SERVER_DESCRIPTION=""
volumes:
- ./palworld:/palworld/
10 changes: 10 additions & 0 deletions scripts/backup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/bin/bash

if [ -n "$PRE_BACKUP_HOOK" ]; then
echo "PRE_BACKUP_HOOK: $PRE_BACKUP_HOOK"
eval "$PRE_BACKUP_HOOK"
fi

if [ "${RCON_ENABLED}" = true ]; then
rcon-cli save
fi
Expand All @@ -10,3 +15,8 @@ cd /palworld/Pal/ || exit

tar -zcf "$FILE_PATH" "Saved/"
echo "backup created at $FILE_PATH"

if [ -n "$POST_BACKUP_HOOK" ]; then
echo "POST_BACKUP_HOOK: $POST_BACKUP_HOOK"
eval "$POST_BACKUP_HOOK"
fi
20 changes: 20 additions & 0 deletions scripts/init.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/bin/bash

if [ -n "$PRE_INIT_HOOK" ]; then
echo "PRE_INIT_HOOK: $PRE_INIT_HOOK"
eval "$PRE_INIT_HOOK"
fi

if [[ ! "${PUID}" -eq 0 ]] && [[ ! "${PGID}" -eq 0 ]]; then
printf "\e[0;32m*****EXECUTING USERMOD*****\e[0m\n"
usermod -o -u "${PUID}" steam
Expand All @@ -18,17 +23,32 @@ if [ "${UPDATE_ON_BOOT}" = true ]; then
fi

term_handler() {
if [ -n "$PRE_SHUTDOWN_HOOK" ]; then
echo "PRE_SHUTDOWN_HOOK: $PRE_SHUTDOWN_HOOK"
eval "$PRE_SHUTDOWN_HOOK"
fi

if [ "${RCON_ENABLED}" = true ]; then
rcon-cli save
rcon-cli "shutdown 1"
else # Does not save
kill -SIGTERM "$(pidof PalServer-Linux-Test)"
fi
tail --pid=$killpid -f 2>/dev/null

if [ -n "$POST_SHUTDOWN_HOOK" ]; then
echo "POST_SHUTDOWN_HOOK: $POST_SHUTDOWN_HOOK"
eval "$POST_SHUTDOWN_HOOK"
fi
}

trap 'term_handler' SIGTERM

if [ -n "$POST_INIT_HOOK" ]; then
echo "POST_INIT_HOOK: $POST_INIT_HOOK"
eval "$POST_INIT_HOOK"
fi

./start.sh &
killpid="$!"
wait $killpid