Skip to content
forked from TapeWerm/MCscripts

Minecraft Java Edition and Bedrock Dedicated Server systemd units, bash scripts, and chat bots for backups, automatic updates, installation, and shutdown warnings

License

Notifications You must be signed in to change notification settings

flplv/MCscripts

 
 

Repository files navigation

Description

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.

Table of contents

Notes

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:

# Press H for help
journalctl -u SERVICE | ~mc/MCcolor.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/MCrunCmd.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 MCBEbackup.sh -n 1 -o cat
# Stop Minecraft Bedrock Edition server
sudo systemctl stop mcbe@MCBE

Backups are in ~mc by default. 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.

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 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/

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 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 mc@MC.socket mc@MC.service mc-backup@MC.timer --now

If you want to automatically remove backups more than 2-weeks-old to save storage:

sudo systemctl enable mc-rmbackup@MC.service --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 '~/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 mcbe@MCBE.socket mcbe@MCBE.service mcbe-backup@MCBE.timer mcbe-getzip.timer mcbe-autoupdate@MCBE.service --now

If you want to automatically remove backups more than 2-weeks-old to save storage:

sudo systemctl enable mcbe-rmbackup@MCBE.service --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_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 mcbe-log@MCBE.service --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/MCstop.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 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

About

Minecraft Java Edition and Bedrock Dedicated Server systemd units, bash scripts, and chat bots for backups, automatic updates, installation, and shutdown warnings

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 96.0%
  • sed 4.0%