Script Name: solstop
Script Description: Bash script to warn and save player chars before a reboot or stop of server
Original Author(s): Poutch
#! /bin/bash
# Author : Poutch (www.pleez.fr)
# This script was created to manage rpg style mod servers
# with a 1 minute warning before stop or reboot of server
# and a auto save of chars 10 seconds before shutdown
# Usage : ./solstop CMD IP PORT PASS
# CMD can be stop or restart
# in the script $SAVE is a command that will be executed 10 seconds before server reboot
# It should be used to save chars, and syntax depend on the soldat mod you are using
SAVE='/update'
SERVERPATH=$HOME'/soldatserver263/soldatserver -d'
case $# in
4)
CMD=$1
IP=$2
PORT=$3
PASS=$4
{
echo $PASS
echo '/say Server is going to reboot in 1 minute...'
sleep 10
for i in 50 40 30 20
do
echo "/say Server is going to reboot in $i sec..."
sleep 10
done
echo $SAVE
for ((i = 10; i > 0; i -= 1))
do
echo "/say Server rebooting in $i sec..."
sleep 1
done
echo '/say Server rebooting NOW !'
sleep 1
echo 'SHUTDOWN'
} | netcat $IP $PORT -w 1;
if [ "$CMD" = "restart" ]
then
sleep 5
$SERVERPATH
echo 'Server Restarted'
else
echo 'Server Stopped'
fi
exit 1;
;;
*)
echo "usage : ./solstop CMD IP PORT ADMINPASS"
echo "CMD can be stop or restart"
exit 0;
;;
esac
For example i have a server that run a zombie mod with player getting experience, so i use this script to restart the server automaticcaly every 3 hours (with a crontab) and i'm sure that the players exp is saved before restart or shutdown.