Minecraft Java Edition and Bedrock Dedicated Server (BDS for short) systemd units, bash scripts, and chat bots for backups, automatic updates, installation, and shutdown warnings
MCBEbackup.sh also works with Docker
@@@ Compatible with Ubuntu @@@
Ubuntu on Windows 10 does not support systemd. Try my Ubuntu Server 18.04 Setup. You can run MCgetJAR.sh, MCBEgetZIP.sh, and MCBEupdate.sh without enabling the systemd units, but not others. No automatic update scripts nor chat bots for Java Edition.
How to run commands in the server console:
sudo ~mc/MCrunCmd.sh SERVICE COMMAND...
# Bedrock Edition server example
sudo ~mc/MCrunCmd.sh mcbe@MCBE help 2
How to see server output:
journalctl -eu SERVICE | ~mc/MCcolor.sed
How to add everyone to whitelist:
whitelist=$(for x in steve alex herobrine; do echo whitelist add "$x"; done)
sudo ~mc/MCrunCmd.sh SERVICE "$whitelist"
How to control systemd services:
# Backup Minecraft Bedrock Edition server
sudo systemctl start mcbe-backup@MCBE
# Stop Minecraft Bedrock Edition server
sudo systemctl stop mcbe@MCBE
Backups are in ~mc by default.
systemctl status mc-backup@MC mcbe-backup@MCBE
says the last backup's location.
Outdated bedrock-server ZIPs in ~mc will be removed by MCBEgetZIP.sh.
MCBEupdate.sh only keeps packs, worlds, JSON files, and PROPERTIES files.
Other files will be removed.
PS4 and Xbox One can only connect on LAN, Nintendo Switch cannot connect at all. Try jhead/phantom to work around this on PS4 and Xbox One. Try ProfessorValko's Bedrock Dedicated Server Tutorial.
Open Terminal:
sudo apt install curl git procps socat wget zip
git clone https://github.com/TapeWerm/MCscripts.git
cd MCscripts
sudo adduser --home /opt/MC --system mc
# I recommend replacing the 1st argument to ln with an external drive to dump backups on
# Example: sudo ln -s EXT_DRIVE ~mc/backup_dir
sudo ln -s ~mc ~mc/backup_dir
Copy and paste this block:
sudo cp *.{sed,sh} ~mc/
sudo chown -h mc:nogroup ~mc/*
sudo cp systemd/* /etc/systemd/system/
Stop the Minecraft server.
sudo mkdir ~mc/java
# Move server directory (Replace SERVER_DIR with Minecraft server directory)
sudo mv SERVER_DIR ~mc/java/MC
# Open server.jar with no GUI and 1024-2048 MB of RAM
echo java -Xms1024M -Xmx2048M -jar server.jar nogui | sudo tee ~mc/java/MC/start.bat
Copy and paste this block:
sudo chmod +x ~mc/java/MC/start.bat
sudo chown -R mc:nogroup ~mc/java
sudo systemctl enable [email protected] [email protected] [email protected] --now
If you want to automatically remove backups more than 2-weeks-old to save storage:
sudo systemctl enable [email protected] --now
Stop the Minecraft server.
sudo mkdir ~mc/bedrock
# Do one of the following:
# Move server directory (Replace SERVER_DIR with Minecraft server directory)
sudo mv SERVER_DIR ~mc/bedrock/MCBE
# OR
# Make new server directory
sudo su mc -s /bin/bash -c '~/MCBEgetZIP.sh'
sudo ~mc/MCBEautoUpdate.sh ~mc/bedrock/MCBE
If you moved a server directory from Windows:
sudo su mc -s /bin/bash -c '~/MCBEgetZIP.sh'
sudo ~mc/MCBEupdate.sh ~mc/bedrock/MCBE ~mc/bedrock-server-*.zip
# Convert DOS line endings to UNIX line endings
for file in ~mc/bedrock/MCBE/*.{json,properties}; do sudo sed -i s/$'\r'$// "$file"; done
Copy and paste this block:
sudo chown -R mc:nogroup ~mc/bedrock
sudo systemctl enable [email protected] [email protected] [email protected] mcbe-getzip.timer [email protected] --now
If you want to automatically remove backups more than 2-weeks-old to save storage:
sudo systemctl enable [email protected] --now
If you want to post server logs to webhooks (Discord and Rocket Chat):
sudo su mc -s /bin/bash
mkdir -p ~/.MCBE_Bot
touch ~/.MCBE_Bot/MCBE_BotWebhook.txt
chmod 600 ~/.MCBE_Bot/MCBE_BotWebhook.txt
Enter nano ~/.MCBE_Bot/MCBE_BotWebhook.txt
, fill this in, and write out (^G = Ctrl-G):
$url
$url
...
Copy and paste this block:
exit
sudo systemctl enable [email protected] --now
If you want to edit systemd units in a way that won't get overwritten when you update MCscripts, use systemctl edit SERVICE
to override specific options.
Options that are a list, such as ExecStop, must first be reset by setting it to an empty string.
How to change mcbe@MCBE shutdown warning to 20 seconds:
- Enter
sudo systemctl edit mcbe@MCBE
, fill this in, and write out (^G = Ctrl-G):
[Service]
ExecStop=
ExecStop=/opt/MC/MCstop.sh -s 20 %N
- If you want to revert the edit enter
sudo systemctl revert mcbe@MCBE
Other services you might want to edit:
- [email protected] - When backups occur (check time zone with
date
) - [email protected] - How many backups to keep
- mcbe-getzip.service - MCBEgetZIP.sh --no-clobber
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 is-active --quiet mcbe@MCBE && systemctl restart mcbe@MCBE
sudo apt install curl git procps socat wget zip
cd MCscripts
git pull origin master
# I recommend replacing the 1st argument to ln with an external drive to dump backups on
# Example: sudo ln -s EXT_DRIVE ~mc/backup_dir
if [ ! -d ~mc/backup_dir ]; then sudo ln -s ~mc ~mc/backup_dir; fi
sudo ./DisableServices.sh
sudo ./MoveServers.sh
Copy and paste this block:
sudo cp *.{sed,sh} ~mc/
sudo chown -h mc:nogroup ~mc/*
sudo cp systemd/* /etc/systemd/system/
sudo ./EnableServices.sh