From b307be0488b871d3c7fa07fcb65e8b9cccb1a84a Mon Sep 17 00:00:00 2001 From: Marcus Whybrow Date: Thu, 24 May 2012 03:12:21 +0100 Subject: [PATCH] Implemented server restart. Also added output for the server_worlds_to_ram function to match server_worlds_to_disk in output. --- msm | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/msm b/msm index 7be9860..1d24668 100755 --- a/msm +++ b/msm @@ -238,6 +238,7 @@ server_ensure_links() { server_worlds_to_ram() { # Only proceed if there is a ramdisk path set in config if $RAMDISK_STORAGE_PATH; then + echo -n "Synchronising flagged worlds on disk to RAM... " local i=${server_world_offset[$1]} local max=$(( $i + ${server_num_worlds[$1]} )) @@ -249,6 +250,7 @@ server_worlds_to_ram() { i=$(( $i + 1 )) done + echo "Done." fi } @@ -256,7 +258,7 @@ server_worlds_to_ram() { # $1: The ID of the server server_worlds_to_disk() { if $RAMDISK_STORAGE_PATH; then - echo -n "Synchronising worlds to disk... " + echo -n "Synchronising worlds in RAM to disk... " local i=${server_world_offset[$1]} local max=$(( $i + ${server_num_worlds[$1]} )) @@ -623,7 +625,7 @@ server_rename() { } # Starts a single server -# $1: The ID of the server to start +# $1: The ID of the server server_start() { if server_is_running $1; then echo "Server \"${server_name[$1]}\" is already running!" @@ -659,7 +661,7 @@ server_save_all() { } # Stops a single server -# $1: The ID of the server to stop +# $1: The ID of the server server_stop() { if server_is_running $1; then server_save_all $1 @@ -671,11 +673,25 @@ server_stop() { server_wait_for_stop $1 echo "Done." + + # Synchronise all worlds in RAM to disk + server_worlds_to_disk $1 else echo "Server \"${server_name[$1]}\" was not running." fi } +# Restarts a single server +# $1: The ID of the server +server_restart() { + # Restarts the server if it is already running + if server_is_running $1; then + server_stop $1 + fi + + server_start $1 +} + ### Main Functions @@ -1022,7 +1038,6 @@ main() { if server_is_running $id; then if [[ $3 != "now" ]]; then server_eval $id "say ${server_stop_message[$id]}" - echo "Issued the warning \"${server_stop_message[$id]}\" to players." echo -n "Shutting down... " @@ -1040,12 +1055,30 @@ main() { fi server_stop $id - server_worlds_to_disk $id else echo "Server \"${server_name[$id]}\" was not running." fi ;; restart) + if server_is_running $id && [[ $3 != "now" ]]; then + server_eval $id "say ${server_restart_message[$id]}" + echo "Issued the warning \"${server_restart_message[$id]}\" to players." + + echo -n "Restarting... " + + for ((i=${server_restart_delay[$id]}; i>0; i--)); do + tput sc # Save cursor position + echo -n "in $i seconds." + sleep 1 + + tput rc # Restore cursor to position of last `sc' + tput el # Clear to end of line + done + + echo -e "Now." + fi + + server_restart $id ;; worlds) ;;