Browse Source

some bugfixes to mcbe

feature/startup-from-labels
Mario Alegre 5 years ago
parent
commit
a01f8dae6e
  1. 2
      src/debian/Containerfile
  2. 52
      src/minecraft_be/assets/bin/mcbe-backup
  3. 6
      src/minecraft_be/assets/bin/mcbe-shutdown
  4. 4
      src/minecraft_be/assets/systemd/mcbe-backup.service
  5. 2
      src/minecraft_be/assets/systemd/mcbe-backup.timer
  6. 6
      src/minecraft_be/assets/systemd/mcbe.service

2
src/debian/Containerfile

@ -14,7 +14,7 @@ RUN rm /etc/localtime && \
# Install packages
RUN apt update -y && \
apt upgrade -y && \
apt install -y init sudo wget nano less man-db unzip && \
apt install -y init sudo wget nano less man-db unzip rsync && \
apt autoremove -y --purge && \
apt clean -y

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

@ -1,44 +1,40 @@
#!/bin/bash
do_backup() {
mcbe-stop $1 "Shutting down server for scheduled daily backup."
rsyn /home/mcadmin/worlds/ /vol/worlds/
systemctl start mcbe
rm /home/mcadmin/backup.attempts
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/
sleep 5
echo "Restarting server after backup."
service mcbe start
}
# Check if server is started
status=$(systemctl show "$service" -p ActiveState --value)
status=$(systemctl show mcbe -p ActiveState --value)
# Check if any players present
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)
# if service is not active, do backup immediately and exit
if [[ $status == inactive ]]; then
rsyn /home/mcadmin/worlds/ /vol/worlds/
rm /home/mcadmin/backup.attempts
exit 0
fi
echo "Service is inactive: copying worlds immediately without restarting service."
rsync -vaSH /home/mcadmin/worlds/ /vol/worlds/
# Check if any players present
present=$(mcbe-exec list | cut -d ' ' -f 3 | cut -d '/' -f 1)
# if no players are present, do backup immediately and exit
if [[ $present == 0 ]]; then
do_backup 0
exit 0
fi
cd /home/mcadmin
# create backup.attempts file if it doesn't exist
if [[ ! -e backup.attempts ]]; then
echo "0" > backup.attempts
fi
elif [[ $players == 0 ]]; then
echo "No players detected: running backup immediately."
do_backup
# read backup.wait and add one to it
attempts=$(( $(cat backup.attempts) + 1 ))
# if 12 or more hours have passed since backup was triggered, go ahead and force a shutdown anyways
elif [[ $(( $today - $last )) -ge 43200 ]]; then
echo "Backup was triggered more than 12 hours ago: forcing backup now."
do_backup
# if 12 or more attempts have already been made, go ahead and force a shutdown anyways
if [[ $attempts -ge 12 ]]; then
do_backup 10
# otherwise, schedule another attempt in an hour
else
echo $attempts > backup.attempts
echo "Players present in server: rescheduling backup to one hour from now."
systemd-run --on-active=1h $0
fi

6
src/minecraft_be/assets/bin/mcbe-stop → src/minecraft_be/assets/bin/mcbe-shutdown

@ -10,8 +10,8 @@ else
exit 2
fi
# if 2nd arg is given (and shutdown is not immediate), say it before shutting down
if [[ -z $2 ]]; then
# if 2nd arg is given, say it before shutting down
if [[ -n $2 ]]; then
mcbe-exec say "$2"
fi
@ -33,4 +33,4 @@ while [[ $count -gt 0 ]]; do
sleep 1
done
mcbe-exec stop
systemctl stop mcbe

4
src/minecraft_be/assets/systemd/mcbe-backup.service

@ -1,9 +1,11 @@
[Unit]
After=mcbe.service
Description=Back up Minecraft Bedrock Edition server
Description=Backup Minecraft Bedrock Edition Server
Requisite=mcbe.service
[Service]
ExecStart=/usr/local/bin/mcbe-backup
StandardOutput=journal
StandardError=journal
KillMode=none
Type=oneshot

2
src/minecraft_be/assets/systemd/mcbe-backup.timer

@ -1,5 +1,5 @@
[Unit]
Description=Back up Minecraft Bedrock Edition server daily at 4:05 AM
Description=Backup Minecraft Bedrock Edition Server daily at 4:05 AM
[Timer]
# Every 2 hours: OnCalendar=0/2:00:00

6
src/minecraft_be/assets/systemd/mcbe.service

@ -5,9 +5,9 @@ BindsTo=mcbe.socket
Description=Minecraft Bedrock Edition server
[Service]
ExecReload=/usr/local/bin/mcbe-exec reload
ExecStop=/usr/local/bin/mcbe-stop
ExecStart=/bin/bash -c 'LD_LIBRARY_PATH=. ./bedrock_server'
ExecReload=/bin/bash -c "echo reload > /run/mcb"
ExecStop=/bin/bash -c "echo stop > /run/mcb"
ExecStart=/bin/bash -c "LD_LIBRARY_PATH=. ./bedrock_server"
User=mcadmin
WorkingDirectory=/home/mcadmin
Restart=on-failure

Loading…
Cancel
Save