From cdeff8c58cd02201b2ec3d0d082f13ddc6158a2a Mon Sep 17 00:00:00 2001 From: Wild1145 Date: Sun, 27 Jun 2021 18:35:05 +0100 Subject: [PATCH] First stab at getting the scripts in a slightly better setup ready for future expansion work --- FreeOP Servers/.env.sh | 10 ++++++++++ FreeOP Servers/kill.sh | 14 +++++++++----- FreeOP Servers/spigot-restart.sh | 22 +++++++++++++--------- FreeOP Servers/start.sh | 19 +++++++++++++++---- FreeOP Servers/stop.sh | 20 ++++++++++++-------- 5 files changed, 59 insertions(+), 26 deletions(-) create mode 100644 FreeOP Servers/.env.sh diff --git a/FreeOP Servers/.env.sh b/FreeOP Servers/.env.sh new file mode 100644 index 0000000..39d30b9 --- /dev/null +++ b/FreeOP Servers/.env.sh @@ -0,0 +1,10 @@ +#! + +# These ones should be server specific +JVM_HEAP="18G" +PAPER_JAR_NAME="paperclip.jar" + +# DO NOT Change these ones +SCREEN_NAME="TotalFreedom" +SARCASTIC_MESSAGE="The server is not running... Why don't you try starting it? <3" +RESET_FILE=/home/tfserver/.resetting \ No newline at end of file diff --git a/FreeOP Servers/kill.sh b/FreeOP Servers/kill.sh index cab5686..ca7b624 100644 --- a/FreeOP Servers/kill.sh +++ b/FreeOP Servers/kill.sh @@ -1,13 +1,17 @@ #! -if screen -list | grep -q "TotalFreedom"; + +#Pull in the .env file for variables. +source .env.sh + +if screen -list | grep -q "$SCREEN_NAME"; then - screen -X -S "TotalFreedom" stuff "^C^C^C^C^C^C^C^C^C^C^C^C^C" + screen -X -S "$SCREEN_NAME" stuff "^C^C^C^C^C^C^C^C^C^C^C^C^C" sleep 5 else - echo "The server is not running... Try starting it <3" + echo "$SARCASTIC_MESSAGE" fi -if screen -list | grep -q "TotalFreedom"; +if screen -list | grep -q "$SCREEN_NAME"; then fuser -k 25565/tcp rm -f /home/tfserver/world/session.lock @@ -20,7 +24,7 @@ then sleep 5 fi -if screen -list | grep -q "TotalFreedom"; +if screen -list | grep -q "$SCREEN_NAME"; then echo "Kill Command Failed. Please try again" else diff --git a/FreeOP Servers/spigot-restart.sh b/FreeOP Servers/spigot-restart.sh index 9ff85ea..460d11f 100644 --- a/FreeOP Servers/spigot-restart.sh +++ b/FreeOP Servers/spigot-restart.sh @@ -1,31 +1,35 @@ #! + +#Pull in the .env file for variables. +source .env.sh + sleep 10 -if screen -list | grep -q "TotalFreedom"; +if screen -list | grep -q "$SCREEN_NAME"; then - screen -X -S "TotalFreedom" stuff "stop^M" + screen -X -S "$SCREEN_NAME" stuff "stop^M" sleep 5 fi -if screen -list | grep -q "TotalFreedom"; +if screen -list | grep -q "$SCREEN_NAME"; then - screen -X -S "TotalFreedom" stuff "^C" + screen -X -S "$SCREEN_NAME" stuff "^C" sleep 5 fi -if screen -list | grep -q "TotalFreedom"; +if screen -list | grep -q "$SCREEN_NAME"; then - screen -X -S "TotalFreedom" stuff "^C^C^C^C^C^C^C^C" + screen -X -S "$SCREEN_NAME" stuff "^C^C^C^C^C^C^C^C" fi -if screen -list | grep -q "TotalFreedom"; +if screen -list | grep -q "$SCREEN_NAME"; then echo "Graceful Shutdown Failed. Please run tf!kill" fi -if screen -list | grep -q "TotalFreedom"; +if screen -list | grep -q "$SCREEN_NAME"; then echo "ERROR - We have been unable to re-start the server... Please execute this manually" else - screen -dmS TotalFreedom java -Xms18G -Xmx18G -XX:+CMSClassUnloadingEnabled -XX:ParallelGCThreads=2 -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10 -jar paperclip.jar + screen -dmS $SCREEN_NAME java -Xms$JVM_HEAP -Xmx$JVM_HEAP -XX:+CMSClassUnloadingEnabled -XX:ParallelGCThreads=2 -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10 -jar $PAPER_JAR_NAME echo "Server Started" fi diff --git a/FreeOP Servers/start.sh b/FreeOP Servers/start.sh index f6625eb..631dabb 100644 --- a/FreeOP Servers/start.sh +++ b/FreeOP Servers/start.sh @@ -1,8 +1,19 @@ #! -if screen -list | grep -q "TotalFreedom"; + +#Pull in the .env file for variables. +source .env.sh + +if test -f "$RESET_FILE"; then - echo "ERROR - There is an instance of the server already running. Make sure it is killed first and try again" + echo "CRITICAL ERORR - Server is currently re-setting. Please wait for this action to complete." else - screen -dmS TotalFreedom java -Xms18G -Xmx18G -XX:+CMSClassUnloadingEnabled -XX:ParallelGCThreads=2 -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10 -jar paperclip.jar - echo "Server Started" + if screen -list | grep -q "$SCREEN_NAME"; + then + echo "ERROR - There is an instance of the server already running. Make sure it is killed first and try again" + else + screen -dmS $SCREEN_NAME java -Xms$JVM_HEAP -Xmx$JVM_HEAP -XX:+CMSClassUnloadingEnabled -XX:ParallelGCThreads=2 -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10 -jar $PAPER_JAR_NAME + echo "Server Started" + fi fi + + diff --git a/FreeOP Servers/stop.sh b/FreeOP Servers/stop.sh index 3c22887..0cd5a8e 100644 --- a/FreeOP Servers/stop.sh +++ b/FreeOP Servers/stop.sh @@ -1,21 +1,25 @@ #! -if screen -list | grep -q "TotalFreedom"; then - screen -X -S "TotalFreedom" stuff "stop^M" + +#Pull in the .env file for variables. +source .env.sh + +if screen -list | grep -q "$SCREEN_NAME"; then + screen -X -S "$SCREEN_NAME" stuff "stop^M" sleep 5 - if screen -list | grep -q "TotalFreedom"; then - screen -X -S "TotalFreedom" stuff "^C" + if screen -list | grep -q "$SCREEN_NAME"; then + screen -X -S "$SCREEN_NAME" stuff "^C" sleep 5 fi - if screen -list | grep -q "TotalFreedom"; then - screen -X -S "TotalFreedom" stuff "^C^C^C^C^C^C^C^C" + if screen -list | grep -q "$SCREEN_NAME"; then + screen -X -S "$SCREEN_NAME" stuff "^C^C^C^C^C^C^C^C" fi - if screen -list | grep -q "TotalFreedom"; then + if screen -list | grep -q "$SCREEN_NAME"; then echo "Graceful Shutdown Failed. Please run tf!kill" else echo "Server has been shut down succesfully." fi else - echo "The server is not running... Try starting it <3" + echo "$SARCASTIC_MESSAGE" fi