-
Notifications
You must be signed in to change notification settings - Fork 160
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
Introduce to start or stop gameserver remotly via webho… #174
base: develop
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,17 @@ | ||
FROM golang:alpine AS build | ||
|
||
# Set the working directory | ||
WORKDIR /go/src/github.com/adnanh/webhook | ||
ENV WEBHOOK_VERSION=2.8.1 | ||
|
||
RUN apk add --update -t build-deps curl libc-dev gcc libgcc | ||
|
||
RUN curl -L --silent -o webhook.tar.gz https://github.com/adnanh/webhook/archive/${WEBHOOK_VERSION}.tar.gz && \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This neither a good nor secure way to install software and doesnt follow the Ansible way. |
||
tar -xzf webhook.tar.gz --strip 1 | ||
|
||
RUN go get -d -v | ||
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o /usr/local/bin/webhook | ||
|
||
FROM --platform=linux/amd64 cm2network/steamcmd:root | ||
|
||
LABEL maintainer="Sebastian Schmidt - https://github.com/jammsen/docker-palworld-dedicated-server" | ||
|
@@ -37,6 +51,10 @@ RUN curl -fsSLO "$RCON_URL" \ | |
|
||
COPY --chown=steam:steam --chmod=755 backupmanager.sh servermanager.sh includes/* / | ||
|
||
COPY --from=build /usr/local/bin/webhook /usr/local/bin/webhook | ||
COPY remotehooks.json /remotehooks.json | ||
|
||
EXPOSE 9000/tcp | ||
EXPOSE 8211/udp | ||
EXPOSE 25575/tcp | ||
|
||
|
@@ -65,7 +83,7 @@ ENV DEBIAN_FRONTEND=noninteractive \ | |
STEAMCMD_VALIDATE_FILES=true \ | ||
SERVER_SETTINGS_MODE=manual \ | ||
WEBHOOK_ENABLED=false \ | ||
WEBHOOK_URL= \ | ||
WEBHOOK_URL="" \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This introduces a bug with the SED scripts. |
||
WEBHOOK_START_TITLE="Server is starting" \ | ||
WEBHOOK_START_DESCRIPTION="The gameserver is starting" \ | ||
WEBHOOK_START_COLOR="2328576" \ | ||
|
@@ -133,10 +151,10 @@ ENV DEBIAN_FRONTEND=noninteractive \ | |
ADMIN_PASSWORD=adminPasswordHere \ | ||
SERVER_PASSWORD=serverPasswordHere \ | ||
PUBLIC_PORT=8211 \ | ||
PUBLIC_IP= \ | ||
PUBLIC_IP="" \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here too |
||
RCON_ENABLED=false \ | ||
RCON_PORT=25575 \ | ||
REGION= \ | ||
REGION="" \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here too |
||
USEAUTH=true \ | ||
BAN_LIST_URL=https://api.palworldgame.com/api/banlist.txt | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ These settings control the behavior of the Docker container: | |
> **Important:** If you want to change the server settings via environment variables use the default value (`auto`) for the environment variable `SERVER_SETTINGS_MODE`, otherwise change it to `manual` and edit the config file directly. | ||
|
||
| Variable | Description | Default value | Allowed values | | ||
| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
|---------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
| TZ | Timezone used for time stamping server backups | Europe/Berlin | See [TZ identifiers](#tz-identifiers) | | ||
| ALWAYS_UPDATE_ON_START | Updates the server on startup | true | false/true | | ||
| MULTITHREAD_ENABLED | Sets options for "Improved multi-threaded CPU performance" | true | false/true | | ||
|
@@ -22,6 +22,7 @@ These settings control the behavior of the Docker container: | |
| BACKUP_RETENTION_AMOUNT_TO_KEEP | Defines how many backups in numbers to keep | 30 | Integer | | ||
| SERVER_SETTINGS_MODE | Determines whether settings can be modified via environment variables or via file, except `COMMUNITY_SERVER` and `MULTITHREAD_ENABLED`! | `auto` | `auto`: Settings are modified only by environment variables, manual edits will be ignored<br>`manual`: Settings are modified only by editing the file directly, environment variables are ignored | | ||
| STEAMCMD_VALIDATE_FILES | Set to enabled SteamCMD will also validate the gameserver files, making sure nothing is corrupted and also overwrite any file changes of the source<br>See https://developer.valvesoftware.com/wiki/SteamCMD#Downloading_an_App | true | false/true | | ||
| REMOTE_CONTROL | If enabled server will not automatically start on container start and can be started/stopped via webhook call. Stop of the gameserver does not exit the container to allow external restart. | false | false/true | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If enabled gameserver ... |
||
|
||
#### TZ identifiers | ||
|
||
|
@@ -31,6 +32,15 @@ The `TZ` setting affects logging output and the backup function. [TZ identifiers | |
|
||
The `BACKUP_CRON_EXPRESSION` setting affects the backup function. In a Cron-Expression, you define an interval for when to run jobs. This image uses Supercronic for crons, see https://github.com/aptible/supercronic#crontab-format or https://crontab-generator.org | ||
|
||
#### Remote Control | ||
If you enable the container setting the Container will not autostart the gameserver, it will however provide webhooks that allow you to control the server remotely. Hooks provided are | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which setting again? Im a new user, why isnt this desribed here, its a readme right? |
||
|
||
`{containerip}:9000/hooks/start` - starts the gameserver | ||
`{containerip}:9000/hooks/stop` - stops the gameserver | ||
|
||
In order to utilize the webhooks expose port 9000 to your host/service and call them via `GET` | ||
|
||
|
||
### Gameserver-Settings | ||
|
||
This section lists all the settings currently adjustable via Docker environment variables, based on the **order** and **contents of the DefaultPalWorldSettings.ini**. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,26 @@ | ||
# Change this for logging and backup, see "Environment variables" in the README.md | ||
TZ=Europe/Berlin | ||
TZ=Europe/Berlin | ||
ALWAYS_UPDATE_ON_START=true | ||
MULTITHREAD_ENABLED=true | ||
COMMUNITY_SERVER=true | ||
BACKUP_ENABLED=true | ||
BACKUP_CRON_EXPRESSION=0 * * * * | ||
BACKUP_CRON_EXPRESSION="0 * * * *" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Introduces a "" bug |
||
BACKUP_RETENTION_POLICY=false | ||
BACKUP_RETENTION_AMOUNT_TO_KEEP=30 | ||
STEAMCMD_VALIDATE_FILES=true | ||
# Change this to manual if you want to edit your configs yourself | ||
SERVER_SETTINGS_MODE=auto | ||
SERVER_SETTINGS_MODE=auto | ||
WEBHOOK_ENABLED=false | ||
WEBHOOK_URL="YOUR-URL-IN-HERE" | ||
WEBHOOK_REMOTE_ACTION="Server remote action" | ||
WEBHOOK_START_TITLE="Server is starting" | ||
WEBHOOK_START_DESCRIPTION="The gameserver is starting" | ||
WEBHOOK_REMOTE_START_DESCRIPTION="Remote start of gameserver initiated" | ||
WEBHOOK_REMOTE_READY_DESCRIPTION="Service is ready to recieve start or stop webhook" | ||
WEBHOOK_START_COLOR="2328576" | ||
WEBHOOK_STOP_TITLE="Server has been stopped" | ||
WEBHOOK_STOP_DESCRIPTION="The gameserver has been stopped" | ||
WEBHOOK_REMOTE_STOP_DESCRIPTION="Remote stop of gameserver initiated" | ||
WEBHOOK_STOP_COLOR="7413016" | ||
WEBHOOK_INFO_TITLE="Info" | ||
WEBHOOK_INFO_DESCRIPTION="This is an info from the server" | ||
|
@@ -74,7 +78,7 @@ ENABLE_DEFENSE_OTHER_GUILD_PLAYER=false | |
COOP_PLAYER_MAX_NUM=4 | ||
MAX_PLAYERS=32 | ||
SERVER_NAME=jammsen-docker-generated-###RANDOM### | ||
SERVER_DESCRIPTION=Palworld-Dedicated-Server running in Docker by jammsen | ||
SERVER_DESCRIPTION="Palworld-Dedicated-Server running in Docker by jammsen" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Introduces a bug "" |
||
ADMIN_PASSWORD=adminPasswordHere | ||
SERVER_PASSWORD=serverPasswordHere | ||
PUBLIC_PORT=8211 | ||
|
@@ -84,3 +88,4 @@ RCON_PORT=25575 | |
REGION= | ||
USEAUTH=true | ||
BAN_LIST_URL=https://api.palworldgame.com/api/banlist.txt | ||
REMOTE_CONTROL=false |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
|
||
if [ ${REMOTE_CONTROL:false} != "true" ]; then | ||
echo "Remote control is not active..." | ||
exit 0; | ||
fi | ||
|
||
if [ ! -z "$(pidof PalServer-Linux-Test)" ]; then | ||
echo "Server already running" | ||
exit 0; | ||
fi | ||
|
||
source /server.sh | ||
source /webhook | ||
|
||
trap 'term_handler' SIGTERM | ||
|
||
send_webhook_notification "$WEBHOOK_REMOTE_ACTION" "$WEBHOOK_REMOTE_START_DESCRIPTION" "$WEBHOOK_INFO_COLOR" | ||
|
||
start_main | ||
|
||
while true; do | ||
if [ -z "$(pidof PalServer-Linux-Test)" ]; then | ||
term_handler | ||
fi | ||
|
||
sleep 5 | ||
done |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
|
||
if [ ${REMOTE_CONTROL:false} != "true" ]; then | ||
echo "Remote control is not active..." | ||
exit 0; | ||
fi | ||
|
||
if [ -z "$(pidof PalServer-Linux-Test)" ]; then | ||
echo "Server not running" | ||
exit 0; | ||
fi | ||
|
||
source /server.sh | ||
source /webhook.sh | ||
|
||
trap 'term_handler' SIGTERM | ||
|
||
send_webhook_notification "$WEBHOOK_REMOTE_ACTION" "$WEBHOOK_REMOTE_STOP_DESCRIPTION" "$WEBHOOK_INFO_COLOR" | ||
|
||
term_handler |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/bin/bash | ||
# Stop on errors, comment in, if needed | ||
#set -e | ||
source /config.sh | ||
source /cron.sh | ||
source /install.sh | ||
source /rcon.sh | ||
source /security.sh | ||
source /webhook.sh | ||
|
||
GAME_PATH="/palworld" | ||
|
||
function start_server() { | ||
# IF Bash extension used: | ||
# https://stackoverflow.com/a/13864829 | ||
# https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02 | ||
|
||
echo ">>> Starting the gameserver" | ||
cd $GAME_PATH | ||
|
||
setup_engine_ini | ||
setup_pal_world_settings_ini | ||
|
||
START_OPTIONS="" | ||
if [[ -n $COMMUNITY_SERVER ]] && [[ $COMMUNITY_SERVER == "true" ]]; then | ||
echo "> Setting Community-Mode to enabled" | ||
START_OPTIONS="$START_OPTIONS EpicApp=PalServer" | ||
fi | ||
if [[ -n $MULTITHREAD_ENABLED ]] && [[ $MULTITHREAD_ENABLED == "true" ]]; then | ||
echo "> Setting Multi-Core-Enchancements to enabled" | ||
START_OPTIONS="$START_OPTIONS -useperfthreads -NoAsyncLoadingThread -UseMultithreadForDS" | ||
fi | ||
if [[ -n $WEBHOOK_ENABLED ]] && [[ $WEBHOOK_ENABLED == "true" ]]; then | ||
send_start_notification | ||
fi | ||
./PalServer.sh "$START_OPTIONS" | ||
} | ||
|
||
function start_main() { | ||
check_for_default_credentials | ||
setup_crons | ||
if [ ! -f "$GAME_PATH/PalServer.sh" ]; then | ||
install_server | ||
fi | ||
if [ $ALWAYS_UPDATE_ON_START == "true" ]; then | ||
update_server | ||
fi | ||
start_server | ||
} | ||
|
||
term_handler() { | ||
local exit_code = ${1:-143} | ||
|
||
if [ -z "$(pidof PalServer-Linux-Test)" ]; then | ||
exit $exit_code | ||
fi | ||
|
||
if [[ ! -z ${RCON_ENABLED+x} ]]; then | ||
save_and_shutdown_server | ||
fi | ||
kill -SIGTERM $(pidof PalServer-Linux-Test) | ||
tail --pid=$(pidof PalServer-Linux-Test) -f 2>/dev/null | ||
send_stop_notification | ||
|
||
exit $exit_code; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,14 +17,16 @@ EOF | |
|
||
# Function to send a notification to a webhook | ||
send_webhook_notification() { | ||
local title="$1" | ||
local description="$2" | ||
local color="$3" | ||
|
||
# Debug Curl | ||
#curl --ssl-no-revoke -H "Content-Type: application/json" -X POST -d "$(generate_post_data "$title" "$description" "$color")" "$WEBHOOK_URL" | ||
# Prod Curl | ||
curl --silent --ssl-no-revoke -H "Content-Type: application/json" -X POST -d "$(generate_post_data "$title" "$description" "$color")" "$WEBHOOK_URL" | ||
if [ ${WEBHOOK_ENABLED:false} == "true" ]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make usage of webhooks more convienient - no mor need to check for the toogle before every call. |
||
local title="$1" | ||
local description="$2" | ||
local color="$3" | ||
|
||
# Debug Curl | ||
#curl --ssl-no-revoke -H "Content-Type: application/json" -X POST -d "$(generate_post_data "$title" "$description" "$color")" "$WEBHOOK_URL" | ||
# Prod Curl | ||
curl --silent --ssl-no-revoke -H "Content-Type: application/json" -X POST -d "$(generate_post_data "$title" "$description" "$color")" "$WEBHOOK_URL" | ||
fi | ||
} | ||
|
||
#Aliases to use in scripts | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[ | ||
{ | ||
"id": "start", | ||
"execute-command": "/remotestart.sh", | ||
"command-working-directory": "/home/steam/steamcmd" | ||
}, | ||
{ | ||
"id": "stop", | ||
"execute-command": "/remotestop.sh", | ||
"command-working-directory": "/home/steam/steamcmd" | ||
} | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,18 @@ | ||
#!/bin/bash | ||
# Stop on errors, comment in, if needed | ||
#set -e | ||
source /config.sh | ||
source /cron.sh | ||
source /install.sh | ||
source /rcon.sh | ||
source /security.sh | ||
source /webhook.sh | ||
|
||
GAME_PATH="/palworld" | ||
|
||
function start_server() { | ||
# IF Bash extension used: | ||
# https://stackoverflow.com/a/13864829 | ||
# https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02 | ||
|
||
echo ">>> Starting the gameserver" | ||
cd $GAME_PATH | ||
|
||
setup_engine_ini | ||
setup_pal_world_settings_ini | ||
|
||
START_OPTIONS="" | ||
if [[ -n $COMMUNITY_SERVER ]] && [[ $COMMUNITY_SERVER == "true" ]]; then | ||
echo "> Setting Community-Mode to enabled" | ||
START_OPTIONS="$START_OPTIONS EpicApp=PalServer" | ||
fi | ||
if [[ -n $MULTITHREAD_ENABLED ]] && [[ $MULTITHREAD_ENABLED == "true" ]]; then | ||
echo "> Setting Multi-Core-Enchancements to enabled" | ||
START_OPTIONS="$START_OPTIONS -useperfthreads -NoAsyncLoadingThread -UseMultithreadForDS" | ||
fi | ||
if [[ -n $WEBHOOK_ENABLED ]] && [[ $WEBHOOK_ENABLED == "true" ]]; then | ||
send_start_notification | ||
fi | ||
./PalServer.sh "$START_OPTIONS" | ||
} | ||
|
||
function start_main() { | ||
check_for_default_credentials | ||
setup_crons | ||
if [ ! -f "$GAME_PATH/PalServer.sh" ]; then | ||
install_server | ||
fi | ||
if [ $ALWAYS_UPDATE_ON_START == "true" ]; then | ||
update_server | ||
fi | ||
start_server | ||
} | ||
source /server.sh | ||
source /webhook.sh | ||
|
||
term_handler() { | ||
if [[ ! -z ${RCON_ENABLED+x} ]]; then | ||
save_and_shutdown_server | ||
fi | ||
kill -SIGTERM $(pidof PalServer-Linux-Test) | ||
tail --pid=$(pidof PalServer-Linux-Test) -f 2>/dev/null | ||
if [[ -n $WEBHOOK_ENABLED ]] && [[ $WEBHOOK_ENABLED == "true" ]]; then | ||
send_stop_notification | ||
fi | ||
exit 143; | ||
} | ||
trap 'term_handler' SIGTERM | ||
|
||
trap 'kill ${!}; term_handler' SIGTERM | ||
if [ ${REMOTE_CONTROL:false} == "true" ]; then | ||
webhook -hooks /remotehooks.json -verbose & | ||
killpid=$(pidof webhook) | ||
send_webhook_notification "$WEBHOOK_REMOTE_ACTION" "$WEBHOOK_REMOTE_READY_DESCRIPTION" "$WEBHOOK_INFO_COLOR" | ||
wait "$killpid" | ||
else | ||
start_main & | ||
killpid="$!" | ||
fi | ||
|
||
start_main & | ||
killpid="$!" | ||
while true | ||
do | ||
wait $killpid | ||
send_stop_notification | ||
exit 0; | ||
done | ||
wait "$killpid" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not going to happen in any of my images, even in multistage builds.