MCscripts Save

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

Project README

Description

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. No automatic updates nor chat bots for Java Edition.

Contributing

Table of contents

Notes

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.

Setup

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

Java Edition setup

Bring your own Java or sudo apt update && sudo apt install openjdk-21-jre-headless.

sudo su mc -s /bin/bash -c '/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:
    sudo /opt/MCscripts/bin/mc_setup.py MC
    
    Enter 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]

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

sudo systemctl enable --now [email protected]

Bedrock Edition setup

sudo su mc -s /bin/bash -c '/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]

Bedrock Edition webhook bots setup

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]

Override systemd unit configuration

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 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/MCscripts/bin/mc_stop.py -s 20 %N
    
  2. 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 try-restart mcbe@MCBE
    

Update MCscripts

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

Remove MCscripts

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
Open Source Agenda is not affiliated with "MCscripts" Project. README Source: TapeWerm/MCscripts
Stars
146
Open Issues
0
Last Commit
3 days ago
Repository
License
MIT

Open Source Agenda Badge

Open Source Agenda Rating