Browse Source

changed mount points

feature/startup-from-labels
Mar Alegre 5 years ago
parent
commit
eae48a09b2
  1. 2
      src/minecraft_be/Containerfile
  2. 31
      src/minecraft_be/assets/bin/mcbe-backup
  3. 12
      src/minecraft_be/assets/minecraft/permissions.json

2
src/minecraft_be/Containerfile

@ -8,7 +8,7 @@ FROM localhost/debian:latest
LABEL deployopts="\
-p 19132:19132/udp \
-p 19133:19133/udp \
-v /srv/vol/minecraft_be/worlds:/vol/worlds"
-v /srv/vol/minecraft_be/data:/vol/data"
# Build variables
# uid that the files owner user should have

31
src/minecraft_be/assets/bin/mcbe-backup

@ -1,14 +1,29 @@
#!/bin/bash
do_backup() {
do_stop() {
echo "Shutting down server for scheduled daily backup."
mcbe-shutdown 10 "Shutting down server for scheduled daily backup."
rsync -vaSH /home/mcadmin/worlds/ /vol/worlds/
}
do_start() {
sleep 5
echo "Restarting server after backup."
service mcbe start
}
do_backup() {
day=$(date +%d)
cd /vol/data
mkdir -p worlds-daily-$day/
rsync -vaSH /home/mcadmin/worlds/ worlds-daily-$day/
if [[ $day == 1 ]]; then
month=$(date +%m)
year=$(date +%Y)
mkdir -p worlds-$year-$month-$day/
rsync -vaSH worlds-daily-$day/ worlds-$year-$month-$day/
fi
}
# Check if server is started
status=$(systemctl show mcbe -p ActiveState --value)
# Check if any players present
@ -16,22 +31,26 @@ players=$(mcbe-exec list | cut -d ' ' -f 3 | cut -d '/' -f 1)
# check when mcbe-backup was last triggered
last=$(date -d "$(systemctl show mcbe-backup.timer -p LastTriggerUSec --value)" +%s)
# get current time
today=$(date +%s)
now=$(date +%s)
# if service is not active, do backup immediately and exit
if [[ $status == inactive ]]; then
if [[ $status != active ]]; then
echo "Service is inactive: copying worlds immediately without restarting service."
rsync -vaSH /home/mcadmin/worlds/ /vol/worlds/
do_backup
# if no players are present, do backup immediately and exit
elif [[ $players == 0 ]]; then
echo "No players detected: running backup immediately."
do_stop
do_backup
do_start
# if 12 or more hours have passed since backup was triggered, go ahead and force a shutdown anyways
elif [[ $(( $today - $last )) -ge 43200 ]]; then
elif [[ $(( $now - $last )) -ge 43200 ]]; then
echo "Backup was triggered more than 12 hours ago: forcing backup now."
do_stop
do_backup
do_start
# otherwise, schedule another attempt in an hour
else

12
src/minecraft_be/assets/minecraft/permissions.json

@ -1,6 +1,10 @@
[
{
"permission" : "operator",
"xuid" : "2535473403284928"
}
{
"permission": "operator",
"xuid": "2535473403284928"
},
{
"permission": "operator",
"xuid": ""
}
]

Loading…
Cancel
Save