forked from lloesche/valheim-server-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor logging and fix usage of empty password for V+ (lloesche#111)
* Refactor logging and pid file handling * Allow empty password when V+ is enabled and related bug fixes (Fixes lloesche#110) * Misc. fixes
- Loading branch information
Showing
8 changed files
with
266 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,80 @@ | ||
#!/bin/bash | ||
# valheim-backups runs permanently if BACKUPS=true | ||
# and creates backups of the /config/worlds directory. | ||
|
||
# Include defaults | ||
. /usr/local/etc/valheim/defaults | ||
. /usr/local/etc/valheim/common | ||
|
||
# Remove trailing slash if any | ||
BACKUPS_DIRECTORY=${BACKUPS_DIRECTORY%/} | ||
pidfile=$valheim_backup_pidfile | ||
next_backup=$(date +%s) | ||
run=true | ||
|
||
|
||
main() { | ||
echo $$ > "$valheim_backup_pidfile" | ||
cd /config | ||
while [ $run = true ]; do | ||
backup | ||
flush_old | ||
next_backup=$(($(date +%s)+$BACKUPS_INTERVAL)) | ||
while [ $run = true -a $(date +%s) -lt $next_backup ]; do | ||
sleep 8 | ||
if (set -o noclobber; echo $$ > "$pidfile") 2> /dev/null; then | ||
trap backup_now SIGHUP | ||
trap shutdown SIGINT SIGTERM | ||
trap 'error_handler $? $LINENO $BASH_LINENO "$BASH_COMMAND" $(printf "::%s" ${FUNCNAME[@]}); trap - ERR' ERR | ||
|
||
cd /config | ||
while [ $run = true ]; do | ||
backup | ||
flush_old | ||
next_backup=$(($(date +%s)+$BACKUPS_INTERVAL)) | ||
while [ $run = true -a $(date +%s) -lt $next_backup ]; do | ||
sleep 8 | ||
done | ||
done | ||
done | ||
else | ||
info "Found existing pid file - checking process" | ||
check_lock $pidfile | ||
fi | ||
} | ||
|
||
|
||
backup() { | ||
if [ ! -d "/config/worlds" ]; then | ||
echo "No Valheim worlds to backup" | ||
debug "No Valheim worlds to backup" | ||
return | ||
fi | ||
local backup_file="$BACKUPS_DIRECTORY/worlds-$(date +%Y%m%d-%H%M%S).zip" | ||
echo "Backing up Valheim server worlds to $backup_file" | ||
info "Backing up Valheim server worlds to $backup_file" | ||
mkdir -p "$BACKUPS_DIRECTORY" | ||
chmod $BACKUPS_DIRECTORY_PERMISSIONS "$BACKUPS_DIRECTORY" | ||
zip -r "$backup_file" "worlds/" | ||
chmod $BACKUPS_FILE_PERMISSIONS "$backup_file" | ||
} | ||
|
||
|
||
flush_old() { | ||
if [ ! -d "$BACKUPS_DIRECTORY" ]; then | ||
echo "No old backups to remove" | ||
debug "No old backups to remove" | ||
return | ||
fi | ||
echo "Removing backups older than $BACKUPS_MAX_AGE days" | ||
info Removing backups older than $BACKUPS_MAX_AGE days | ||
find "$BACKUPS_DIRECTORY" -type f -mtime +$BACKUPS_MAX_AGE -name 'worlds-*.zip' -print -exec rm -f "{}" \; | ||
} | ||
|
||
|
||
# This is a signal handler registered to SIGHUP | ||
backup_now() { | ||
echo "Received signal to backup world" | ||
debug "Received signal to backup world" | ||
next_backup=0 | ||
} | ||
|
||
|
||
shutdown() { | ||
rm -f "$valheim_backup_pidfile" | ||
clear_lock $pidfile | ||
run=false | ||
} | ||
|
||
|
||
if [ "X$BACKUPS" = Xtrue ]; then | ||
trap backup_now SIGHUP | ||
trap shutdown SIGINT SIGTERM | ||
if [ "$BACKUPS" = true ]; then | ||
main | ||
else | ||
echo "Backups have been turned off by env BACKUPS=$BACKUPS" | ||
info "Backups have been turned off by env BACKUPS=$BACKUPS" | ||
supervisorctl stop valheim-backup | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.