Add shell scripts for auto-starting and operating evennia on a server.

This commit is contained in:
Griatch 2016-12-08 23:53:48 +01:00
parent 293c3b077d
commit bffc8b04d8
2 changed files with 110 additions and 0 deletions

View File

@ -0,0 +1,36 @@
#
# Evennia init.d Screen launcher script (Linux)
#
# This requires a Linux using init.d. I is used togeter
# with the evennia-screen.sh script, which must be working
# before setting this one up. This script is meant to be
# used as part of Linux' automatic services and requires
# root to set up.
#
# Usage:
# 1. sudo cp evennia-screen-initd.sh /etc/init.d/evennia
# 2. cd /etc/init.d
# 3. Edit this script (now renamed to 'evennia') and
# change SCRIPTPATH and USER below to fit your setup.
# 4. sudo chown root:root evennia
# 5. sudo chmod 755 evennia
#
# You can now use (as root) ´services evennia start|stop|reload`
# to operate the server. The server will run as the USER you
# specify and must thus have access to start the server
# (*don't* set it to run as root!).
#
# To make Evennia auto-start when the server reboots, run
# the following:
#
# sudo update-rc.d evennia defaults 91
#
# CHANGE to fit your setup (obs: no spaces around the '=')
SCRIPTPATH="/home/muddev/mud/mygame/server/evennia-screen.sh"
USER="muddev"
#------------------------------------------------------------
su - "$USER" -c "$SCRIPTPATH $1"

View File

@ -0,0 +1,74 @@
#/bin/bash
#------------------------------------------------------------
#
# GNU Screen bash startup script (Linux only)
#
# This script is meant for auto-restarting Evennia on a Linux server
# with the standard GNU Screen program installed. Evennia will be
# launched inside a detached Screen session, you can then connect
# to with screen -r <gamename>. This will make sure that the
# runner reload process is not killed when logging out of the server.
# A Screen session also has the advantage that one can connect to it
# and operate normally on the server after the fact.
#
# Usage:
#
# 1. First make sure Evennia can be started manually.
# 2. Copy this script to mygame/server.
# 3. Edit the GAMENAME, VIRTUALENV and GAMEDIR vars below to
# match your game.
# 4. Make it executable with 'chmod u+x evennia-screen.sh'.
#
# See also evennia-screen-initd.sh for auto-starting evennia
# on the server.
#
#------------------------------------------------------------
# CHANGE to fit your game (obs: no spaces around the '=')
GAMENAME="mygame"
VIRTUALENV="/home/muddev/mud/pyenv"
GAMEDIR="/home/muddev/mud/mygame"
#------------------------------------------------------------
case $1 in
start)
if [ -z "$STY" ]; then
if screen -S "$GAMENAME" -X select .>/dev/null; then
# Session already exists. Send the start command instead.
echo "(Re-)Starting Evennia."
cd "$GAMEDIR"
touch "$GAMEDIR"/server/logs/server.log
screen -S $GAMENAME -p evennia -X stuff 'evennia start --log \n'
else
# start GNU Screen then run it with this same script, making sure to
# not start Screen on the second call
echo "Starting Evennia."
exec screen -d -m -S "$GAMENAME" -t evennia /bin/bash "$0" "$1"
fi
else
# this is executed inside the GNU Screen session
source "$VIRTUALENV"/bin/activate
cd "$GAMEDIR"
touch "$GAMEDIR"/server/logs/server.log
evennia start
exec sh
fi
;;
stop)
cd "$GAMEDIR"
screen -S "$GAMENAME" -p evennia -X stuff 'evennia stop\n'
echo "Stopped Evennia."
;;
reload | restart)
cd "$GAMEDIR"
screen -S "$GAMENAME" -p evennia -X stuff 'evennia reload --log\n'
echo "Reloading Evennia."
;;
*)
echo "Usage: start_evennia {start|stop|restart|reload}"
exit 1
;;
esac