aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2020-01-04 18:09:50 +0100
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2020-01-04 18:09:50 +0100
commit272bd7bcc4e1aab834ea2ddb76ea0bae84330a87 (patch)
tree4ac8016388f41f21fc46ff1f4e88fdc1e37ef65d
parentb0246c61aebe3c847690f96247c6ff23360172ae (diff)
downloadminecraft-server-tools-272bd7bcc4e1aab834ea2ddb76ea0bae84330a87.tar.gz
Updated Readme, more checks
-rw-r--r--Readme.md38
-rwxr-xr-xserver.sh80
2 files changed, 100 insertions, 18 deletions
diff --git a/Readme.md b/Readme.md
index 0512098..29a3792 100644
--- a/Readme.md
+++ b/Readme.md
@@ -2,24 +2,48 @@
My minecraft server management script with safe online Backup.
+## Configuration
+
+Config-variables are located at the top of `server.sh`
+
## Usage
-`./server.sh start|stop|attach|status`
+`./server.sh start|stop|attach|status|backup`
+
+### start
+
+Creates a `screen` session and starts a minecraft server within.
+Fails, if a session is already running with the same sessionname.
+
+### stop
+
+Sends `stop` command to running server instance to safely shut down.
+
+### attach
+
+attaches to `screen` session. Exit with `CTRL + A d`
+
+### status
+
+lists active screen sessions with `SCREEN_SESSIONNAME`.
-`attach` attaches to the server console using `screen`. to detach, type: `CTRL+A d`
+### backup
-Configuration is located at at the top of the script.
+Backs up the world as a `tar.gz` archive in `./backup/`.
+If a running server is detected,
+the world is flushed to disk and autosave is disabled temporarily to prevent chunk corruption.
The command specified in `$BACKUP_HOOK` is
-executed on every backup. `$ARCHNAME` contains the relative path to the backup.
+executed on every successful backup. `$ARCHNAME` contains the relative path to the archive.
+This can be used to further process the created backup.
-Example:
+The following example copies the created archive to a remote server.
- scp $ARCHNAME user@server:/home/backups/
+ BACKUP_HOOK="scp $ARCHNAME user@server:/home/user/backups/"
## Disclaimer
The scripts are provided as-is at no warranty.
-They are not idiot-proof.
+They are in no way idiot-proof.
Improvements are welcome.
diff --git a/server.sh b/server.sh
index e1722ed..2dd284b 100755
--- a/server.sh
+++ b/server.sh
@@ -2,22 +2,32 @@
#CONFIG
JRE_JAVA="java"
-JVM_ARGS="-Xms9G -Xmx9G"
-JAR="fabric-server-launch.jar"
+JVM_ARGS="-Xms10G -Xmx10G"
+JAR="server.jar"
JAR_ARGS="-nogui"
SCREEN_WINDOW="minecraftserverscreen"
WORLD_NAME="world"
LOGFILE="mcserver.log"
#HOOKS
-BACKUP_HOOK="echo HOOK"
+BACKUP_HOOK="echo $ARCHNAME"
function send_cmd () {
screen -S $SCREEN_WINDOW -p 0 -X stuff "$1^M"
}
function server_start() {
- screen -L -Logfile "$LOGFILE" -S $SCREEN_WINDOW -p 0 -d -m $JRE_JAVA $JVM_ARGS -jar $JAR $JAR_ARGS
+ screen -list $SCREEN_WINDOW
+ if [ $? -eq 0 ]
+ then
+ echo "It seems a server is already running. If this is not the case,\
+ manually attach to the running screen and close it."
+ exit 1
+ fi
+
+ rm -f $LOGFILE
+ screen -L -Logfile "$LOGFILE" -S $SCREEN_WINDOW -p 0 -d -m \
+ $JRE_JAVA $JVM_ARGS -jar $JAR $JAR_ARGS
exit
}
@@ -33,10 +43,18 @@ function server_attach() {
function server_status() {
screen -list $SCREEN_WINDOW
+
+ if [ $? -eq 0 ]
+ then
+ echo "Server seems to be running. attach to be sure"
+ else
+ fi
+ echo "Server is not running"
exit
}
-function server_backup() {
+function server_backup_safe() {
+ echo "Detected running server. Disabling autosave"
send_cmd "save-off"
send_cmd "save-all flush"
echo "Waiting for save... If froze, run /save-on to re-enable autosave!!"
@@ -48,15 +66,55 @@ function server_backup() {
done
echo "Done! starting backup..."
- local ARCHNAME="backup/$WORLD_NAME-backup_`date +%d-%m-%y-%T`.tar.gz"
- tar -czvf "$ARCHNAME" "./$WORLD_NAME"
-
- echo "Done! Saved in $ARCHNAME"
+ create_backup_archive
+ local RET=$?
+
echo "Re-enabling auto-save"
send_cmd "save-on"
- echo "Running Backup-Hook"
- $BACKUP_HOOK
+ if [ $RET -eq 0 ]
+ then
+ echo Running backup hook
+ $BACKUP_HOOK
+ fi
+}
+
+function server_backup_unsafe() {
+ echo "No running server detected. Running Backup"
+
+ create_backup_archive
+
+ if [ $? -eq 0 ]
+ then
+ echo Running backup hook
+ $BACKUP_HOOK
+ fi
+}
+
+function create_backup_archive() {
+ ARCHNAME="backup/$WORLD_NAME-backup_`date +%d-%m-%y-%T`.tar.gz"
+ tar -czvf "$ARCHNAME" "./$WORLD_NAME"
+
+ if [ ! $? -eq 0 ]
+ then
+ echo "TAR failed. No Backup created."
+ rm $ARCHNAME #remove (probably faulty) archive
+ return 1
+ else
+ echo $ARCHNAME created.
+ fi
+}
+
+function server_backup() {
+ screen -list $SCREEN_WINDOW > /dev/null
+ if [ $? -eq 0 ]
+ then #Server is running
+ server_backup_safe
+ else #Not running
+ server_backup_unsafe
+ fi
+
+ exit
}
case $1 in