Minecraft Java and Bedrock Dedicated Server systemd units and scripts for backups, automatic updates, and posting logs to chat bots
mcbe_backup.py also works with Docker
@@@ Compatible with Ubuntu @@@
Ubuntu on Windows Subsystem for Linux does not support systemctl poweroff. Try Ubuntu Server. You can run mc_getjar.py, mcbe_getzip.py, and mcbe_update.py without enabling the systemd units, but not others.
How to run commands in the server console:
sudo /opt/MCscripts/bin/mc_cmd.py SERVICE COMMAND...
# Minecraft Bedrock Edition server example
sudo /opt/MCscripts/bin/mc_cmd.py mcbe@MCBE help 2
How to see server output:
# Press H for help
journalctl -u SERVICE | /opt/MCscripts/bin/mc_color.sed | less -r +G
How to add everyone to allowlist:
allowlist=$(for x in steve alex herobrine; do echo "allowlist add $x"; done)
sudo /opt/MCscripts/bin/mc_cmd.py SERVICE "$allowlist"
How to control systemd services:
# See Minecraft Bedrock Edition server status
systemctl status mcbe@MCBE
# Backup Minecraft Bedrock Edition server
sudo systemctl start mcbe-backup@MCBE
# See backup's location
journalctl [email protected] -n 1 -o cat
# Check for Minecraft Bedrock Edition server updates
sudo systemctl start mcbe-getzip
# Stop Minecraft Bedrock Edition server
sudo systemctl stop mcbe@MCBE
How to restore backup for Minecraft Bedrock Edition server:
sudo systemctl stop mcbe@MCBE
sudo /opt/MCscripts/bin/mcbe_restore.py ~mc/bedrock/MCBE BACKUP
sudo systemctl start mcbe@MCBE
How to see MCscripts version:
cat /opt/MCscripts/version
How to see MCscripts commit hash:
unzip -z /tmp/master.zip | tail -n +2
Backups are in /opt/MCscripts/backup_dir. Outdated bedrock-server ZIPs in ~mc will be removed by mcbe_getzip.py. mcbe_update.py only keeps packs, worlds, JSON files, and PROPERTIES files. Other files will be removed.
PlayStation and Xbox can only connect on LAN with subscription, Nintendo Switch cannot connect at all. Try ProfessorValko's Bedrock Dedicated Server Tutorial.
Open Terminal:
curl -L https://github.com/TapeWerm/MCscripts/archive/refs/heads/master.zip -o /tmp/master.zip
unzip /tmp/master.zip -d /tmp
sudo /tmp/MCscripts-master/src/install.sh
If you want to change where backups are stored:
# Replace EXT_DRIVE with external drive
sudo ln -snf EXT_DRIVE /opt/MCscripts/backup_dir
Bring your own Java or sudo apt update && sudo apt install openjdk-21-jre-headless
.
sudo systemd-run -PGqp User=mc -- /opt/MCscripts/bin/mc_getjar.py
Do one of the following:
- Import server directory:
/opt/MCscripts/bin/mc_import.py --help # Replace SERVER_DIR with server directory sudo /opt/MCscripts/bin/mc_import.py SERVER_DIR MC
- Make new server directory:
Enter
sudo /opt/MCscripts/bin/mc_setup.py MC
sudo nano ~mc/java/MC/eula.txt
, fill it in, and write out (^G = Ctrl-G).
sudo systemctl enable --now [email protected] [email protected] [email protected]
sudo systemctl enable --now mc-getjar.timer [email protected]
If you want to automatically remove backups more than 2-weeks-old to save storage:
sudo systemctl enable --now [email protected]
If you want to post server logs to webhooks (Discord and Rocket Chat):
sudo mkdir -p ~mc/.mc_log
# Rocket Chat: MC_rocket.txt
sudo touch ~mc/.mc_log/MC_discord.txt
sudo chmod 600 ~mc/.mc_log/MC_discord.txt
sudo chown -R mc:mc ~mc/.mc_log
Enter sudo nano ~mc/.mc_log/MC_discord.txt
, fill this in, and write out (^G = Ctrl-G):
$url
$url
...
sudo systemctl enable --now [email protected]
sudo systemd-run -PGqp User=mc -- /opt/MCscripts/bin/mcbe_getzip.py
Do one of the following:
- Import server directory:
/opt/MCscripts/bin/mcbe_import.py --help # Replace SERVER_DIR with server directory sudo /opt/MCscripts/bin/mcbe_import.py SERVER_DIR MCBE
- Make new server directory:
sudo /opt/MCscripts/bin/mcbe_setup.py MCBE
sudo systemctl enable --now [email protected] [email protected] [email protected]
sudo systemctl enable --now mcbe-getzip.timer [email protected]
If you want to automatically remove backups more than 2-weeks-old to save storage:
sudo systemctl enable --now [email protected]
If you want to post server logs to webhooks (Discord and Rocket Chat):
sudo mkdir -p ~mc/.mcbe_log
# Rocket Chat: MCBE_rocket.txt
sudo touch ~mc/.mcbe_log/MCBE_discord.txt
sudo chmod 600 ~mc/.mcbe_log/MCBE_discord.txt
sudo chown -R mc:mc ~mc/.mcbe_log
Enter sudo nano ~mc/.mcbe_log/MCBE_discord.txt
, fill this in, and write out (^G = Ctrl-G):
$url
$url
...
sudo systemctl enable --now [email protected]
How to change mcbe@MCBE shutdown warning to 20 seconds:
-
sudo mkdir -p /etc/MCscripts/mcbe sudo cp /etc/MCscripts/mcbe.toml /etc/MCscripts/mcbe/MCBE.toml
- Enter
sudo nano /etc/MCscripts/mcbe/MCBE.toml
, fill this in, and write out (^G = Ctrl-G):# Seconds before stopping. # 0-60 seconds = 20
mcbe.toml configures mcbe@*. mcbe/MCBE.toml only configures mcbe@MCBE. mcbe/MCBE.toml overrides mcbe.toml.
MCscripts config files are TOML format.
If you want to edit systemd units in a way that won't get overwritten when you update MCscripts, use sudo systemctl edit SERVICE
to override specific options.
Options that are a list, such as ExecStart, must first be reset by setting it to an empty string.
How to change mcbe-rmbackup@MCBE to keep backups for 4 weeks:
- Enter
sudo systemctl edit mcbe-rmbackup@MCBE
, fill this in, and write out (^G = Ctrl-G):[Service] ExecStart= ExecStart=/usr/bin/find /opt/MCscripts/backup_dir/bedrock_backups/%i -type f -mtime +28 -delete
- If you want to revert the edit enter
sudo systemctl revert mcbe-rmbackup@MCBE
Other services you might want to edit:
- [email protected] - When backups occur (check time zone with
date
)
How to restart mcbe@MCBE at 3 AM daily:
- Enter
sudo crontab -e
, fill this in, and write out (^G = Ctrl-G):# m h dom mon dow command 0 3 * * * systemctl try-restart mcbe@MCBE
curl -L https://github.com/TapeWerm/MCscripts/archive/refs/heads/master.zip -o /tmp/master.zip
rm -rf /tmp/MCscripts-master
unzip /tmp/master.zip -d /tmp
sudo /tmp/MCscripts-master/src/install.sh
If you want to change where backups are stored:
# Replace EXT_DRIVE with external drive
sudo ln -snf EXT_DRIVE /opt/MCscripts/backup_dir
sudo /opt/MCscripts/bin/disable_services.sh
sudo userdel mc
sudo groupdel mc
sudo chown -R root:root /opt/MC
sudo mv -T --backup=numbered /opt/MC /opt/MC.old
sudo mv -T --backup=numbered /opt/MCscripts /opt/MCscripts.old
sudo mv -T --backup=numbered /etc/MCscripts /etc/MCscripts.old