Path | Description |
---|---|
/home/minecraft_server/ |
The Minecraft server itself |
/home/minecraft_server/run.sh |
The script to start the server |
/home/minecraft_server/server.properties |
The server properties file |
/home/tools |
Tools folder |
/home/tools/mcrcon |
Clone of https://github.com/Tiiffi/mcrcon.git for connecting to the server, follow their tutorial for installation (essential for any scripts below) |
/home/tools/backup.sh |
Backup helper (needs rclone configured and a Discord webhook) |
/home/tools/restart.sh |
Restart helper, needs pm2 to restart the server |
/home/tools/server_console.sh |
Connect to the server console |
/home/backups |
Folder where up to 4 local backups are stored |
Last active
September 26, 2024 08:23
-
-
Save JPBM135/3d88675cd110513a733c4c22c8e21410 to your computer and use it in GitHub Desktop.
Tools for mine server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
~/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p pass_n_stuff "say [SYSTEM]: Starting Backup..." | |
~/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p pass_n_stuff "save-off" | |
~/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p pass_n_stuff "save-all" | |
DATE=$(date +%F-%H-%M) | |
# Add all mods names to a file (no need to upload the whole mods folder) | |
ls -1 ~/minecraft_server/mods > ~/minecraft_server/mods-bkp.txt | |
# Create a backup while excluding mods, libraries, and logs directories | |
tar --exclude='mods' --exclude='libraries' --exclude='local' -cvpzf ~/backups/server-$DATE.tar.gz ~/minecraft_server/**/* | |
~/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p pass_n_stuff "save-on" | |
~/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p pass_n_stuff "say [SYSTEM]: Backup finished!" | |
# Upload the backup to the remote server on the path mine/backups/latest.tar.gz | |
rclone copyto ~/backups/server-$DATE.tar.gz r2:test/mine/backup/latest.tar.gz | |
~/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p pass_n_stuff "say [SYSTEM]: Backup uploaded to the cloud!" | |
# Delete older backups | |
cd ~/backups | |
# Check the number of files in the folder | |
file_count=$(ls -1 | wc -l) | |
# If file count is greater than 4, delete the oldest files | |
if [ $file_count -gt 4 ]; then | |
files_to_delete=$(ls -t server-*.tar.gz | tail -n $(($file_count - 4))) | |
for file in $files_to_delete; do | |
echo "Deleting file: $file" | |
~/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p pass_n_stuff "say [SYSTEM]: Deleting old backup: $file" | |
rm $file | |
done | |
fi | |
# To make command more readable you can split it to multiple lines using backslash `\` | |
# and/or set webhook url and body as variables. | |
WEBHOOK_URL="<YOUR_URL>" | |
BODY='{"username": "Mine Backup", "content": "[System] Backup completed!"}' | |
curl \ | |
-H "Content-Type: application/json" \ | |
-d "$BODY" \ | |
$WEBHOOK_URL | |
# Keep the container running so pm2 can restart the script every hour | |
while true | |
do | |
sleep 1 | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @type {{apps: import('pm2').StartOptions[]}} | |
*/ | |
const process = { | |
apps: [ | |
{ | |
name: 'Minecraft Server', | |
cwd: './minecraft_server', | |
autorestart: true, | |
autostart: true, | |
interpreter: 'bash', | |
kill_timeout: 10000, // Needed so the minecraft server can stop gracefully | |
script: 'run.sh', | |
}, | |
{ | |
name: 'Minecraft Backup', | |
cron_restart: '0 * * * *', // Every hour | |
cwd: './tools', | |
autorestart: true, | |
autostart: true, | |
interpreter: 'bash', | |
kill_timeout: 10000, | |
script: 'backup.sh', | |
restart_delay: 1000 * 60, // If the script crashes, ensure a timer before trying again | |
} | |
] | |
} | |
module.exports = process |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ensure the gave is saved | |
~/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p pass_n_stuff "save-all" | |
# Stop the server, pm2 will handle the restart | |
~/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p pass_n_stuff "stop" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
/opt/jre1.8.0_311/bin/java -Xmx12000M -Xms12000M -jar forge-1.16.5-36.2.21.jar nogui |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Minecraft server properties | |
#Sat Sep 21 08:34:18 UTC 2024 | |
# Allow flights since we are in a modded server | |
allow-flight=true | |
allow-nether=true | |
broadcast-console-to-ops=true | |
broadcast-rcon-to-ops=true | |
difficulty=hard | |
enable-command-block=false | |
enable-jmx-monitoring=false | |
enable-query=false | |
enable-rcon=true | |
enable-status=true | |
enforce-whitelist=false | |
entity-broadcast-range-percentage=100 | |
force-gamemode=false | |
function-permission-level=2 | |
gamemode=survival | |
generate-structures=true | |
generator-settings= | |
hardcore=false | |
level-name=world | |
level-seed= | |
level-type=default | |
max-build-height=256 | |
max-players=10 | |
max-tick-time=600000 | |
max-world-size=29999984 | |
motd=Never gonna give you up! :) | |
network-compression-threshold=256 | |
online-mode=false | |
op-permission-level=4 | |
player-idle-timeout=0 | |
prevent-proxy-connections=false | |
pvp=true | |
query.port=8080 | |
rate-limit=0 | |
rcon.password=pass_n_stuff | |
rcon.port=25575 | |
resource-pack= | |
resource-pack-sha1= | |
server-ip= | |
server-port=8080 | |
snooper-enabled=true | |
spawn-animals=true | |
spawn-monsters=true | |
spawn-npcs=true | |
spawn-protection=0 | |
sync-chunk-writes=true | |
text-filtering-config= | |
use-native-transport=true | |
view-distance=10 | |
white-list=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Helper to access the server console | |
~/tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p pass_n_stuff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment