Skip to content

Commit

Permalink
Refactoring of shell-scripts and docker-based files, #120 also added …
Browse files Browse the repository at this point in the history
…the ability to send start and stop webhook notifies
  • Loading branch information
jammsen committed Jan 31, 2024
1 parent cd16c11 commit 74668d8
Show file tree
Hide file tree
Showing 10 changed files with 445 additions and 379 deletions.
21 changes: 16 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ RUN curl -fsSLO "$RCON_URL" \
&& ln -s "/usr/local/bin/${RCON_BINARY}" /usr/local/bin/rconcli \
&& rm -Rf rcon-0.10.3-amd64_linux rcon-0.10.3-amd64_linux.tar.gz

ADD --chown=steam:steam --chmod=755 servermanager.sh /servermanager.sh
ADD --chown=steam:steam --chmod=755 backupmanager.sh /backupmanager.sh
COPY --chown=steam:steam --chmod=755 backupmanager.sh servermanager.sh includes/* /

EXPOSE 8211/udp
EXPOSE 25575/tcp

# Workaround for 'Named Volumes'
RUN mkdir /palworld \
&& chown steam:steam /palworld

Expand All @@ -53,7 +53,7 @@ ADD --chown=steam:steam --chmod=440 rcon.yaml ./rcon.yaml
ENV DEBIAN_FRONTEND=noninteractive \
PUID=1000 \
PGID=1000 \
# Container setttings
### Container-setttings
TZ="Europe/Berlin" \
ALWAYS_UPDATE_ON_START=true \
MULTITHREAD_ENABLED=true \
Expand All @@ -63,8 +63,19 @@ ENV DEBIAN_FRONTEND=noninteractive \
BACKUP_RETENTION_POLICY=false \
BACKUP_RETENTION_AMOUNT_TO_KEEP=30 \
STEAMCMD_VALIDATE_FILES=true \
SERVER_SETTINGS_MODE=auto \
# Server-setting
SERVER_SETTINGS_MODE=manual \
WEBHOOK_ENABLED=false \
WEBHOOK_URL= \
WEBHOOK_START_TITLE="Server is starting" \
WEBHOOK_START_DESCRIPTION="The gameserver is starting" \
WEBHOOK_START_COLOR="2328576" \
WEBHOOK_STOP_TITLE="Server has been stopped" \
WEBHOOK_STOP_DESCRIPTION="The gameserver has been stopped" \
WEBHOOK_STOP_COLOR="7413016" \
WEBHOOK_INFO_TITLE="Info" \
WEBHOOK_INFO_DESCRIPTION="This is an info from the server" \
WEBHOOK_INFO_COLOR="2849520" \
### Server-setting
NETSERVERMAXTICKRATE=120 \
DIFFICULTY=None \
DAYTIME_SPEEDRATE=1.000000 \
Expand Down
20 changes: 8 additions & 12 deletions backupmanager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,17 @@ TIME=$(date +%H-%M-%S)
mkdir -p /palworld/backups
if [[ -n $BACKUP_RETENTION_POLICY ]] && [[ $BACKUP_RETENTION_POLICY == "true" ]]; then
cd /palworld/backups
echo ">>> The Backup retention policy is enabled"
echo "> Keeping latest $BACKUP_RETENTION_AMOUNT_TO_KEEP backups"
echo ">>> The Backup retention policy is enabled - Keeping latest $BACKUP_RETENTION_AMOUNT_TO_KEEP backups"
ls -1t saved-*.tar.gz | tail -n +$(($BACKUP_RETENTION_AMOUNT_TO_KEEP + 1)) | xargs -d '\n' rm -f --
echo ">>> Cleanup finished"
fi
echo ">>> Creating backup"
echo "> Sending message to gameserver"
cd ~/steamcmd/
rconcli "broadcast $TIME-Backup-in-progress"
sleep 1
rconcli 'broadcast Saving...'
rconcli "broadcast $TIME-Saving-in-5-seconds"
sleep 5
rconcli 'save'
rconcli 'broadcast Done...'
sleep 15
# Create backup dir and change into it
rconcli 'broadcast Saving-done'
sleep 1
rconcli 'broadcast Creating-backup'
cd /palworld/Pal
tar cfz /palworld/backups/saved-$DATE.tar.gz Saved/
echo ">>> Done"
cd ~/steamcmd/
rconcli 'broadcast Backup-done'
11 changes: 11 additions & 0 deletions default.env
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ 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
WEBHOOK_ENABLED=false
WEBHOOK_URL="YOUR-URL-IN-HERE"
WEBHOOK_START_TITLE="Server is starting"
WEBHOOK_START_DESCRIPTION="The gameserver is starting"
WEBHOOK_START_COLOR="2328576"
WEBHOOK_STOP_TITLE="Server has been stopped"
WEBHOOK_STOP_DESCRIPTION="The gameserver has been stopped"
WEBHOOK_STOP_COLOR="7413016"
WEBHOOK_INFO_TITLE="Info"
WEBHOOK_INFO_DESCRIPTION="This is an info from the server"
WEBHOOK_INFO_COLOR="2849520"
NETSERVERMAXTICKRATE=120
DIFFICULTY=None
DAYTIME_SPEEDRATE=1.000000
Expand Down
311 changes: 311 additions & 0 deletions includes/config.sh

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions includes/cron.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Function to start supercronic and load crons from cronlist
function setup_crons() {
touch cronlist
if [[ -n $BACKUP_ENABLED ]] && [[ $BACKUP_ENABLED == "true" ]]; then
echo "$BACKUP_CRON_EXPRESSION /backupmanager.sh" >> cronlist
fi
/usr/local/bin/supercronic cronlist &
}
27 changes: 27 additions & 0 deletions includes/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Function to install the gameserver
function install_server() {
# force a fresh install of all
echo ">>> Doing a fresh install of the gameserver"
if [[ -n $WEBHOOK_ENABLED ]] && [[ $WEBHOOK_ENABLED == "true" ]]; then
send_webhook_notification "Installing server" "Server is beeing installed" "$WEBHOOK_INFO_COLOR"
fi
/home/steam/steamcmd/steamcmd.sh +force_install_dir "$GAME_PATH" +login anonymous +app_update 2394010 validate +quit
}

# Function to update the gameserver
function update_server() {
# force an update and validation
if [[ -n $STEAMCMD_VALIDATE_FILES ]] && [[ $STEAMCMD_VALIDATE_FILES == "true" ]]; then
echo ">>> Doing an update and validate of the gameserver files"
if [[ -n $WEBHOOK_ENABLED ]] && [[ $WEBHOOK_ENABLED == "true" ]]; then
send_webhook_notification "Updating server" "Server is beeing updated and validated" "$WEBHOOK_INFO_COLOR"
fi
/home/steam/steamcmd/steamcmd.sh +force_install_dir "$GAME_PATH" +login anonymous +app_update 2394010 validate +quit
else
echo ">>> Doing an update of the gameserver files"
if [[ -n $WEBHOOK_ENABLED ]] && [[ $WEBHOOK_ENABLED == "true" ]]; then
send_webhook_notification "Updating server" "Server is beeing updated" "$WEBHOOK_INFO_COLOR"
fi
/home/steam/steamcmd/steamcmd.sh +force_install_dir "$GAME_PATH" +login anonymous +app_update 2394010 +quit
fi
}
Empty file added includes/rcon.sh
Empty file.
12 changes: 12 additions & 0 deletions includes/security.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Function to check if the default passwords are replaced
function check_for_default_credentials() {
echo ">>> Checking for existence of default credentials"
if [[ -n $ADMIN_PASSWORD ]] && [[ $ADMIN_PASSWORD == "adminPasswordHere" ]]; then
echo ">>> Error: Security thread detected: Please change the default admin password. Aborting server start ..."
exit 1
fi
if [[ -n $SERVER_PASSWORD ]] && [[ $SERVER_PASSWORD == "serverPasswordHere" ]]; then
echo ">>> Error: Security thread detected: Please change the default server password. Aborting server start ..."
exit 1
fi
}
28 changes: 28 additions & 0 deletions includes/webhook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Function to generate JSON data for the Discord message
# Webpage for COLOR-Calculation - https://www.spycolor.com/
# IMPORTANT: Dont use Hex-Colors! Go to the page search for the Hex-Color.
# After that add the DECIMAL-Represenetation to the color field or it will break!
generate_post_data() {
cat <<EOF
{
"content": "",
"embeds": [{
"title": "$1",
"description": "$2",
"color": "$3"
}]
}
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"
}
Loading

0 comments on commit 74668d8

Please sign in to comment.