Browse Source

added/changed mcbe scripts

feature/startup-from-labels
Mar Alegre 5 years ago
parent
commit
b48a994d68
  1. 7
      src/mcbe/assets/bin/mcbe-backup
  2. 8
      src/mcbe/assets/bin/mcbe-exec
  3. 42
      src/mcbe/assets/bin/mcbe-restore
  4. 38
      src/mcbe/assets/bin/mcbe-shutdown

7
src/mcbe/assets/bin/mcbe-backup

@ -70,13 +70,6 @@ done
# tell minecraft it can resume
mcbe-exec save resume
# delete old inactive worlds
ls -w 1 | grep -v -E "^$world\$" | while read -r line; do
if [[ ! -e "$worlds_dir/$line" ]]; then
rm -r "$line"
fi
done
# copy inactive worlds
ls -w 1 "$worlds_dir" | grep -v -E "^$world\$" | while read -r line; do
rsync -a "$worlds_dir/$line" ./

8
src/mcbe/assets/bin/mcbe-exec

@ -1,4 +1,12 @@
#!/bin/bash
# Check if server is started
status=$(systemctl show mcbe -p ActiveState --value)
if [[ $status != active ]]; then
echo "Error: Server is not active!"
exit 1
fi
today=$(date "+%Y-%m-%d %H:%M:%S")
echo "$*" > /run/mcbe
sleep 0.2

42
src/mcbe/assets/bin/mcbe-restore

@ -0,0 +1,42 @@
#!/bin/bash
if [[ -z $1 ]]; then
echo "Usage: $0 backup_dir"
exit 2
fi
backup_dir="$1"
# Check if directory exists
if [[ ! -d "$backup_dir" ]]; then
echo "Error: directory \"$backup_dir\" not found."
exit 1
fi
cd "$backup_dir"
# Check if server is active
status=$(systemctl show mcbe -p ActiveState --value)
# shutdown server if it is active
if [[ $status == active ]]; then
echo "Server is active: executing shutdown"
systemctl stop mcbe
sleep 1
fi
# remove current worlds
worlds_dir=/home/mcadmin/worlds
rm -r $worlds_dir/*
# copy backup to worlds_dir
rsync -aSH "$backup_dir/" "$worlds_dir/"
# copy resources to each world in worlds_dir
resources_dir=/vol/data/resources
for d in "$worlds_dir/*"; do
rsync -aSH "$resources_dir/" "$d/"
done
# start server back up if it was active
if [[ $status == active ]]; then
echo "Starting server back up..."
systemctl start mcbe
sleep 5
fi

38
src/mcbe/assets/bin/mcbe-shutdown

@ -1,6 +1,22 @@
#!/bin/bash
if [[ -z $1 ]]; then
say() {
echo "$1"
mcbe-exec say "$1"
}
# first argument gives if server should halt or restart
if [[ -z $1 || $1 == "-h" ]]; then
restart=1
elif [[ $1 == "-r" ]]; then
restart=0
else; then
echo "Invalid value for shutdown type: acceptable values are \"-h\" for halt, or \"-r\" for restart."
exit 2
fi
# 2nd argument gives custom warning time
if [[ -z $2 ]]; then
# default warning time is 10 seconds
time=10
elif [[ $1 -ge 0 && $1 -le 60 ]]; then
@ -10,23 +26,19 @@ else
exit 2
fi
# if 2nd arg is given, say it before shutting down
if [[ -n $2 ]]; then
mcbe-exec say "$2"
fi
echo "Shutting down server in $time seconds..."
count=$time
say "Server shutting down in $time seconds!"
count=$(($time-1))
sleep 1
while [[ $count -gt 0 ]]; do
# print warning every 10 seconds
if [[ $(( $count % 10 )) -eq 0 ]]; then
mcbe-exec say "Server shutting down in ${count} seconds!"
say "Server shutting down in ${count} seconds!"
fi
# print warning every second for last 5 seconds
if [[ $count -le 5 ]]; then
mcbe-exec say "Shutting down in ${count}s..."
say "Shutting down in ${count}..."
fi
count=$((count-1))
@ -34,3 +46,9 @@ while [[ $count -gt 0 ]]; do
done
systemctl stop mcbe
if [[ $restart ]]; then
sleep 1
systemctl start mcbe
sleep 5
fi

Loading…
Cancel
Save