From 267560ec1278e3f106bac51b7d2a29fa64b66651 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Wed, 31 Jan 2024 19:58:57 -0500 Subject: [PATCH 1/4] Added waiting for backups to complete before stopping --- scripts/backup.sh | 1 + scripts/init.sh | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/scripts/backup.sh b/scripts/backup.sh index 3f7c845fd..c659f0c50 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -8,6 +8,7 @@ DATE=$(date +"%Y-%m-%d_%H-%M-%S") FILE_PATH="/palworld/backups/palworld-save-${DATE}.tar.gz" cd /palworld/Pal/ || exit +echo "Creating backup" tar -zcf "$FILE_PATH" "Saved/" if [ "$(id -u)" -eq 0 ]; then diff --git a/scripts/init.sh b/scripts/init.sh index 24c3fac10..7dd492e7e 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -28,3 +28,9 @@ su steam -c ./start.sh & # Process ID of su killpid="$!" wait $killpid + +echo "Waiting for backup to finish" +backup_pids=($(pgrep backup)) +for pid in "${backup_pids[@]}"; do + tail --pid=$pid -f 2>/dev/null +done From e7ad9801f026880f424f781ac530c8063ccffbfb Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Wed, 31 Jan 2024 20:13:18 -0500 Subject: [PATCH 2/4] Added check to see if backups are running --- scripts/init.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/init.sh b/scripts/init.sh index 7dd492e7e..b54120479 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -29,8 +29,10 @@ su steam -c ./start.sh & killpid="$!" wait $killpid -echo "Waiting for backup to finish" backup_pids=($(pgrep backup)) -for pid in "${backup_pids[@]}"; do - tail --pid=$pid -f 2>/dev/null -done +if [ "${#backup_pids[@]}" -ne 0 ]; then + echo "Waiting for backup to finish" + for pid in "${backup_pids[@]}"; do + tail --pid=$pid -f 2>/dev/null + done +fi From 4e7971e54dcc5b2b8bc50a1b9c39991712dbeb78 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Wed, 31 Jan 2024 20:17:45 -0500 Subject: [PATCH 3/4] Reading array with mapfile --- scripts/init.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/init.sh b/scripts/init.sh index b54120479..a54490ccd 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -29,7 +29,7 @@ su steam -c ./start.sh & killpid="$!" wait $killpid -backup_pids=($(pgrep backup)) +mapfile -t backup_pids < <(pgrep backup) if [ "${#backup_pids[@]}" -ne 0 ]; then echo "Waiting for backup to finish" for pid in "${backup_pids[@]}"; do From 9c8b6f85de125bd1b1338acbf5c52a29d46a7db1 Mon Sep 17 00:00:00 2001 From: "Carlos M. Martinez" Date: Wed, 31 Jan 2024 20:18:16 -0500 Subject: [PATCH 4/4] Added quotes around pids --- scripts/init.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/init.sh b/scripts/init.sh index a54490ccd..8a216c23c 100644 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -19,7 +19,7 @@ term_handler() { else # Does not save kill -SIGTERM "$(pidof PalServer-Linux-Test)" fi - tail --pid=$killpid -f 2>/dev/null + tail --pid="$killpid" -f 2>/dev/null } trap 'term_handler' SIGTERM @@ -27,12 +27,12 @@ trap 'term_handler' SIGTERM su steam -c ./start.sh & # Process ID of su killpid="$!" -wait $killpid +wait "$killpid" mapfile -t backup_pids < <(pgrep backup) if [ "${#backup_pids[@]}" -ne 0 ]; then echo "Waiting for backup to finish" for pid in "${backup_pids[@]}"; do - tail --pid=$pid -f 2>/dev/null + tail --pid="$pid" -f 2>/dev/null done fi