Mercurial > hg > batmud > maputils
changeset 2089:6fbd7ff22922
Add SysV init script and configuration examples for mapsearch.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 01 Sep 2019 19:15:55 +0300 |
parents | a0eb0ccd6458 |
children | a8684a02f42e |
files | scripts/mapsearch.sysvinit scripts/mapsearch.sysvinit.cfg scripts/testrunmapsearch.sh |
diffstat | 3 files changed, 186 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/mapsearch.sysvinit Sun Sep 01 19:15:55 2019 +0300 @@ -0,0 +1,145 @@ +#! /bin/sh + +### BEGIN INIT INFO +# Provides: mapsearch +# Required-Start: $remote_fs +# Required-Stop: $remote_fs +# Default-Start: 2 3 4 5 +# Default-Stop: +# Short-Description: PupuMaps map search server +### END INIT INFO + +# SysV init script for MapSearch + +set -e + +MAPSEARCH_CFG="/etc/default/mapsearch" +MAPSEARCH_BIN="/usr/sbin/mapsearch" +MAPSEARCH_PIDFILE="/var/run/mapsearch.pid" + + +if test ! -x "$MAPSEARCH_BIN"; then + echo "$MAPSEARCH_BIN does not exist or is not executable." + exit 0 +fi + +umask 022 + +if test -f "$MAPSEARCH_CFG"; then + . "$MAPSEARCH_CFG" +else + echo "$MAPSEARCH_CFG does not exist." + exit 0 +fi + +if test "x$MAPSEARCH_DIR" = "x"; then + echo "MAPSEARCH_DIR not configured." + exit 0 +fi + +if test ! -d "$MAPSEARCH_DIR"; then + echo "$MAPSEARCH_DIR does not exist." + exit 0 +fi + +. /lib/lsb/init-functions + + +update_map_data() +{ + if test ! -d "$MAPSEARCH_DIR/.hg"; then + hg clone "$MAPSEARCH_REPO" "$MAPSEARCH_DIR" + else + cd "$MAPSEARCH_DIR" && hg pull && hg update + fi +} + + +MAPSEARCH_ARGS="" +for SPEC in ${MAPSEARCH_MAPLIST}; do + MAP=$(echo "$SPEC"|cut -d : -f 1) + WXC=$(echo "$SPEC"|cut -d : -f 2) + WYC=$(echo "$SPEC"|cut -d : -f 3) + MAPSEARCH_ARGS="$MAPSEARCH_ARGS ${MAPSEARCH_DIR}/world/${MAP}.map:${MAPSEARCH_DIR}/world/${MAP}.loc:${MAP}:$WXC:$WYC" +done + + +#export PATH="${PATH:+$PATH:}/usr/sbin:/sbin" + +case "$1" in + start) + update_map_data + log_daemon_msg "Starting PupuMaps map search server" "mapsearch" || true + if start-stop-daemon --start --quiet --oknodo -m --background --pidfile "$MAPSEARCH_PIDFILE" --exec "$MAPSEARCH_BIN" -- $MAPSEARCH_ARGS $MAPSEARCH_OPTS; then + log_end_msg 0 || true + else + log_end_msg 1 || true + fi + ;; + stop) + log_daemon_msg "Stopping PupuMaps map search server" "mapsearch" || true + if start-stop-daemon --stop --quiet --oknodo --remove-pidfile --pidfile "$MAPSEARCH_PIDFILE"; then + log_end_msg 0 || true + else + log_end_msg 1 || true + fi + ;; + + reload|force-reload) + update_map_data + log_daemon_msg "Reloading PupuMaps map search server's configuration" "mapsearch" || true + if start-stop-daemon --stop --signal 1 --quiet --oknodo --remove-pidfile --pidfile "$MAPSEARCH_PIDFILE" --exec "$MAPSEARCH_BIN"; then + log_end_msg 0 || true + else + log_end_msg 1 || true + fi + ;; + + restart) + update_map_data + log_daemon_msg "Restarting PupuMaps map search server" "mapsearch" || true + start-stop-daemon --stop --quiet --oknodo --retry 30 --remove-pidfile --pidfile "$MAPSEARCH_PIDFILE" + if start-stop-daemon --start --quiet --oknodo -m --background --pidfile "$MAPSEARCH_PIDFILE" --exec "$MAPSEARCH_BIN" -- $MAPSEARCH_ARGS $MAPSEARCH_OPTS; then + log_end_msg 0 || true + else + log_end_msg 1 || true + fi + ;; + + try-restart) + update_map_data + log_daemon_msg "Restarting PupuMaps map search server" "mapsearch" || true + RET=0 + start-stop-daemon --stop --quiet --retry 30 --remove-pidfile --pidfile "$MAPSEARCH_PIDFILE" || RET="$?" + case $RET in + 0) + # old daemon stopped + if start-stop-daemon --start --quiet --oknodo -m --background --pidfile "$MAPSEARCH_PIDFILE" --exec "$MAPSEARCH_BIN" -- $MAPSEARCH_ARGS $MAPSEARCH_OPTS; then + log_end_msg 0 || true + else + log_end_msg 1 || true + fi + ;; + 1) + # daemon not running + log_progress_msg "(not running)" || true + log_end_msg 0 || true + ;; + *) + # failed to stop + log_progress_msg "(failed to stop)" || true + log_end_msg 1 || true + ;; + esac + ;; + + status) + status_of_proc -p "$MAPSEARCH_PIDFILE" "$MAPSEARCH_BIN" mapsearch && exit 0 || exit $? + ;; + + *) + log_action_msg "Usage: /etc/init.d/mapsearch {start|stop|reload|force-reload|restart|try-restart|status}" || true + exit 1 +esac + +exit 0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/mapsearch.sysvinit.cfg Sun Sep 01 19:15:55 2019 +0300 @@ -0,0 +1,24 @@ +# Configuration file /etc/default/mapsearch +# for Pupunen MapSearch daemon SysV init script + +# Use mapsearch user and group to drop privileges to +MAPSEARCH_OPTS="-U mapsearch -G mapsearch" + +# Use log file and be verbose +MAPSEARCH_OPTS="$MAPSEARCH_OPTS -L /var/log/mapsearch.log -v -v" + +# Set listening interface(s) + port and SSL certificates +MAPSEARCH_OPTS="$MAPSEARCH_OPTS -l *:4200=tnsp.org:/etc/ssl/certs/tnsp.org.pem:/etc/ssl/private/tnsp.org.key:/etc/ssl/certs/ca-certificates.crt" + + +# Cache data directory, if -U/-G is used this needs write permission for that user/group +MAPSEARCH_DIR="/var/cache/mapsearch" + +MAPSEARCH_REPO="http://pupunen.net/hg/maputils" + + +# Set world center / origin +MAPSEARCH_OPTS="$MAPSEARCH_OPTS -w 8192:8192" + +# List of maps with offsets to world origin +MAPSEARCH_MAPLIST="laenor:1:1 rothikgen:1311:-1255 lucentium:-634:2345 furnachia:1211:1155 desolathya:-1210:820 renardy:2070:-910"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/testrunmapsearch.sh Sun Sep 01 19:15:55 2019 +0300 @@ -0,0 +1,17 @@ +#!/bin/sh +MAPS="laenor:1:1 rothikgen:1311:-1255 lucentium:-634:2345 furnachia:1211:1155 desolathya:-1210:820" + +ARGS="-l *:4202" +#ARGS="$ARGS -l lo:4200=tnsp.org:tnsp.org.pem:tnsp.org.key:/etc/ssl/certs/ca-certificates.crt" +ARGS="$ARGS -w 8192:8192 old/hcbat.map:old/hcbat.loc:hcbat:-8192:-8192" + +for SPEC in ${MAPS}; do + MAP=$(echo "$SPEC"|cut -d : -f 1) + WXC=$(echo "$SPEC"|cut -d : -f 2) + WYC=$(echo "$SPEC"|cut -d : -f 3) + ARGS="$ARGS world/${MAP}.map:world/${MAP}.loc:${MAP}:$WXC:$WYC" +done + +echo bin/mapsearch $ARGS "$@" +bin/mapsearch $ARGS "$@" +