Implemented server restart.

Also added output for the server_worlds_to_ram function to match
server_worlds_to_disk in output.
This commit is contained in:
Marcus Whybrow 2012-05-24 03:12:21 +01:00
parent 7a272e8026
commit b307be0488

43
msm
View File

@ -238,6 +238,7 @@ server_ensure_links() {
server_worlds_to_ram() { server_worlds_to_ram() {
# Only proceed if there is a ramdisk path set in config # Only proceed if there is a ramdisk path set in config
if $RAMDISK_STORAGE_PATH; then if $RAMDISK_STORAGE_PATH; then
echo -n "Synchronising flagged worlds on disk to RAM... "
local i=${server_world_offset[$1]} local i=${server_world_offset[$1]}
local max=$(( $i + ${server_num_worlds[$1]} )) local max=$(( $i + ${server_num_worlds[$1]} ))
@ -249,6 +250,7 @@ server_worlds_to_ram() {
i=$(( $i + 1 )) i=$(( $i + 1 ))
done done
echo "Done."
fi fi
} }
@ -256,7 +258,7 @@ server_worlds_to_ram() {
# $1: The ID of the server # $1: The ID of the server
server_worlds_to_disk() { server_worlds_to_disk() {
if $RAMDISK_STORAGE_PATH; then 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 i=${server_world_offset[$1]}
local max=$(( $i + ${server_num_worlds[$1]} )) local max=$(( $i + ${server_num_worlds[$1]} ))
@ -623,7 +625,7 @@ server_rename() {
} }
# Starts a single server # Starts a single server
# $1: The ID of the server to start # $1: The ID of the server
server_start() { server_start() {
if server_is_running $1; then if server_is_running $1; then
echo "Server \"${server_name[$1]}\" is already running!" echo "Server \"${server_name[$1]}\" is already running!"
@ -659,7 +661,7 @@ server_save_all() {
} }
# Stops a single server # Stops a single server
# $1: The ID of the server to stop # $1: The ID of the server
server_stop() { server_stop() {
if server_is_running $1; then if server_is_running $1; then
server_save_all $1 server_save_all $1
@ -671,11 +673,25 @@ server_stop() {
server_wait_for_stop $1 server_wait_for_stop $1
echo "Done." echo "Done."
# Synchronise all worlds in RAM to disk
server_worlds_to_disk $1
else else
echo "Server \"${server_name[$1]}\" was not running." echo "Server \"${server_name[$1]}\" was not running."
fi 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 ### Main Functions
@ -1022,7 +1038,6 @@ main() {
if server_is_running $id; then if server_is_running $id; then
if [[ $3 != "now" ]]; then if [[ $3 != "now" ]]; then
server_eval $id "say ${server_stop_message[$id]}" server_eval $id "say ${server_stop_message[$id]}"
echo "Issued the warning \"${server_stop_message[$id]}\" to players." echo "Issued the warning \"${server_stop_message[$id]}\" to players."
echo -n "Shutting down... " echo -n "Shutting down... "
@ -1040,12 +1055,30 @@ main() {
fi fi
server_stop $id server_stop $id
server_worlds_to_disk $id
else else
echo "Server \"${server_name[$id]}\" was not running." echo "Server \"${server_name[$id]}\" was not running."
fi fi
;; ;;
restart) 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) worlds)
;; ;;