summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/README.restart55
-rwxr-xr-xtools/bin/restart-all21
-rw-r--r--tools/bin/restart-config25
-rwxr-xr-xtools/bin/restart-login3
-rwxr-xr-xtools/bin/restart-pid44
-rwxr-xr-xtools/bin/restart-world28
6 files changed, 176 insertions, 0 deletions
diff --git a/tools/README.restart b/tools/README.restart
new file mode 100644
index 00000000..0bd147e2
--- /dev/null
+++ b/tools/README.restart
@@ -0,0 +1,55 @@
+There are 3 front-facing scripts for this new pidfile-based restart system.
+
+All of them belong in ~/bin/, although one of them is not actually a script.
+(it is source'd, which follows $PATH)
+
+restart-all Call this on first boot
+ if REBUILD is not empty, it will first pull, build, and install
+ from the tmw-eathena repository.
+ In bash you can do this like: REBUILD=sure restart-all
+restart-world Call this if you only want to restart one server.
+ The first argument is the directory, e.g. ~/tmwa-server-data/
+ After that, you may pass --manual or --auto to not-pull or pull
+ script updates. If neither is specified, the value of PULL is
+ used.
+ This does NOT use AUTO_WORLDS or MANUAL_WORLDS.
+restart-config Contains configuration settings.
+ SERVER_SOURCE is the location of the tmw-eathena clone.
+ LOGIN_WORLD is the location of the clone that contains the
+ account data. It does not necessarily have to correspond to
+ a world that actually starts, although it does in the
+ current configuration
+ AUTO_WORLDS is an array (space separated, surrounded by
+ parentheses) of world directories that will have updates
+ pulled when calling restart-all.
+ MANUAL_WORLDS is an array of world directories that will not
+ have updates pulled when calling restart-all
+ VERBOSE controls whether the servers will print their output
+ to the tty or have it redirected to /dev/null. Use if if
+ you have any problems. It is inspected by the low-level
+ command restart-pid.
+ REBUILD controls whether the server sources will be rebuilt
+ during restart-all.
+ PULL controls whether updates should be pulled by
+ restart-world. It is ignored if --auto or --manual
+ is specified, which is the case during restart-all.
+ All of these variables (except probably the arrays) can be
+ specified in the environment, but the values in restart-config
+ override them. However, since restart-config is a bash script,
+ you could conditionally set the variables by using if test ...
+
+There are also two commands you'll probably never have to call yourself:
+restart-login is self-explanatory and is usually called only by restart-all
+restart-pid is the low-level command that maintains the PID file and kills
+ the old servers. In order for the server to be killed, three
+ things must match: the PID, and name, and the user.
+ This will keep errors to a minimum in case PID files continue
+ to exist after the processes have died and new processes have
+ taken their IDs.
+
+ There's a theoretical case in which the replacing process will
+ be a new instance of the same process by the same user in a
+ different world directory. The odds of this happening are
+ theoretically 1 in 32767-ish, but in practice might be a bit
+ more common than that. If you find your newly-spawned children
+ did not survive, try running restart-all again.
diff --git a/tools/bin/restart-all b/tools/bin/restart-all
new file mode 100755
index 00000000..5d7e2425
--- /dev/null
+++ b/tools/bin/restart-all
@@ -0,0 +1,21 @@
+#!/bin/bash -e
+source restart-config
+if test -n "$REBUILD"
+then
+ cd $SERVER_SOURCE
+ git pull
+ make
+ make install prefix=${HOME}
+fi
+
+restart-login $LOGIN_WORLD
+
+for world in ${AUTO_WORLDS[@]}
+do
+ restart-world $world --auto
+done
+
+for world in ${MANUAL_WORLDS[@]}
+do
+ restart-world $world --manual
+done
diff --git a/tools/bin/restart-config b/tools/bin/restart-config
new file mode 100644
index 00000000..e19ab314
--- /dev/null
+++ b/tools/bin/restart-config
@@ -0,0 +1,25 @@
+## TMW restart script settings
+## This file must be in ~/bin/ even though it's not executable
+
+## Mandatory filepath settings
+SERVER_SOURCE=~/eathena
+LOGIN_WORLD=~/tmwa-server-data
+AUTO_WORLDS=(
+ ~/tmwa-server-data
+)
+MANUAL_WORLDS=(
+ ~/tmwa-server-test
+)
+## Boolean settings (nonempty for true)
+## if not specified here, the value from the environment is used,
+## which is probably empty (false). However, some scripts may
+## provide command-line options to override the defaults.
+
+## Should the servers print their output to the terminal?
+# VERBOSE=yep
+
+## Should server sources be rebuilt?
+# REBUILD=sure
+
+## Should server data be pulled?
+# PULL=certainly
diff --git a/tools/bin/restart-login b/tools/bin/restart-login
new file mode 100755
index 00000000..765fe248
--- /dev/null
+++ b/tools/bin/restart-login
@@ -0,0 +1,3 @@
+#!/bin/bash -e
+cd "$1"
+restart-pid login-server
diff --git a/tools/bin/restart-pid b/tools/bin/restart-pid
new file mode 100755
index 00000000..498bdcc4
--- /dev/null
+++ b/tools/bin/restart-pid
@@ -0,0 +1,44 @@
+#!/bin/bash -e
+# do nasty work here
+# The job of this script is twofold:
+# 1. kill the existing server, if it exists
+# 2. write the PID file and start the new server
+
+source restart-config
+
+PROCESS=$1
+
+if test -f $PROCESS.pid
+then
+ # if the process ID may change its name (e.g. via exec),
+ # then remove '$PROCESS' on the following line
+ PID=$(pgrep $PROCESS -u $UID -F $PROCESS.pid || true)
+ if test -n "$PID"
+ then
+ kill $PID
+ echo waiting for $PID to die so I can restart $PROCESS
+ while
+ ! kill -s 0 $PID
+ do
+ echo -n .
+ sleep 1
+ done
+ # This shouldn't be necessary, but somehow is
+ sleep 2
+ echo
+ else
+ echo $PROCESS.pid does not point to a valid process - nothing killed
+ fi
+else
+ echo No PID file $PROCESS.pid found - nothing killed
+fi
+
+if test -z "$VERBOSE"
+then
+ exec >/dev/null 2>&1
+fi
+
+{
+ # $$ is not reset in subshells
+ exec sh -c 'echo $$ > '$PROCESS'.pid; exec ./'$PROCESS
+} &
diff --git a/tools/bin/restart-world b/tools/bin/restart-world
new file mode 100755
index 00000000..7fead17f
--- /dev/null
+++ b/tools/bin/restart-world
@@ -0,0 +1,28 @@
+#!/bin/bash -e
+cd "$1"
+shift
+
+source restart-config
+
+for ARG
+do
+ if [ "$ARG" = --auto ]
+ then
+ PULL=y
+ elif [ "$ARG" = --manual ]
+ then
+ PULL=
+ else
+ echo unknown argument
+ exit 1
+ fi
+done
+
+if test -n "$PULL"
+then
+ git pull
+ (cd world/map/conf; cat magic.conf.template | ./spells-build > magic.conf)
+fi
+
+restart-pid char-server
+restart-pid map-server