Skip to content

Latest commit

 

History

History
190 lines (179 loc) · 6.87 KB

README.md

File metadata and controls

190 lines (179 loc) · 6.87 KB

Description

Minecraft Java and Bedrock Dedicated Server systemd units and scripts for backups, automatic updates, and posting logs to chat bots

mcbe_backup.sh also works with Docker

@@@ Compatible with Ubuntu @@@

Ubuntu on Windows 10 does not support systemd. Try Ubuntu Server. You can run mc_getjar.sh, mcbe_getzip.sh, and mcbe_update.sh without enabling the systemd units, but not others. No automatic updates nor chat bots for Java Edition.

Table of contents

Notes

How to run commands in the server console:

sudo ~mc/mc_cmd.sh SERVICE COMMAND...
# Bedrock Edition server example
sudo ~mc/mc_cmd.sh mcbe@MCBE help 2

How to see server output:

# Press H for help
journalctl -u SERVICE | ~mc/mc_color.sed | less -r +G

How to add everyone to whitelist:

whitelist=$(for x in steve alex herobrine; do echo whitelist add "$x"; done)
sudo ~mc/mc_cmd.sh SERVICE "$whitelist"

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 -u mcbe-backup@MCBE -t mcbe_backup.sh -n 1 -o cat
# Stop Minecraft Bedrock Edition server
sudo systemctl stop mcbe@MCBE

Backups are in ~mc/backup_dir. Outdated bedrock-server ZIPs in ~mc will be removed by mcbe_getzip.sh. mcbe_update.sh 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 jhead/phantom to work around this on PlayStation and Xbox. Try ProfessorValko's Bedrock Dedicated Server Tutorial.

Setup

Open Terminal:

sudo apt install curl procps socat zip
curl -L https://github.com/TapeWerm/MCscripts/archive/refs/heads/master.zip -O
unzip master.zip
cd MCscripts-master
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/

Java Edition setup

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 chmod +x server.jar | sudo tee ~mc/java/MC/start.bat
echo java -Xms1024M -Xmx2048M -jar server.jar nogui | sudo tee -a ~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

Bedrock Edition setup

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 '~/mcbe_getzip.sh'
sudo ~mc/mcbe_autoupdate.sh ~mc/bedrock/MCBE

If you moved a server directory from Windows:

sudo su mc -s /bin/bash -c '~/mcbe_getzip.sh'
sudo ~mc/mcbe_update.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

Bedrock Edition webhook bots setup

If you want to post server logs to webhooks (Discord and Rocket Chat):

sudo su mc -s /bin/bash
mkdir -p ~/.mcbe_log
touch ~/.mcbe_log/MCBE_webhook.txt
chmod 600 ~/.mcbe_log/MCBE_webhook.txt

Enter nano ~/.mcbe_log/MCBE_webhook.txt, fill this in, and write out (^G = Ctrl-G):

$url
$url
...

Copy and paste this block:

exit
sudo systemctl enable [email protected] --now

Override systemd unit configuration

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:

  1. Enter sudo systemctl edit mcbe@MCBE, fill this in, and write out (^G = Ctrl-G):
[Service]
ExecStop=
ExecStop=/opt/MC/mc_stop.sh -s 20 %N
  1. If you want to revert the edit enter sudo systemctl revert mcbe@MCBE

Other services you might want to edit:

How to restart mcbe@MCBE at 3 AM daily:

  1. 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

Update MCscripts

sudo apt install curl procps socat zip
curl -L https://github.com/TapeWerm/MCscripts/archive/refs/heads/master.zip -O
rm -rf MCscripts-master
unzip master.zip
cd MCscripts-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 ./disable_services.sh
sudo ./move_servers.sh
sudo ./move_backups.sh

Copy and paste this block:

sudo cp *.{sed,sh} ~mc/
sudo chown -h mc:nogroup ~mc/*
sudo cp systemd/* /etc/systemd/system/
sudo ./enable_services.sh