#!/bin/sh # # Synchronet BBS detached-screen init script # # User definable options. Edit these as necessary. # # For now, the location of the sbbs install. PREFIX=/usr/local/sbbs # The location of the sbbs executable. SBBSEXEC=$PREFIX/exec # Location of the ctrl directory (where sbbs.ini can be found) export SBBSCTRL=$PREFIX/ctrl # The username for the bbs to change to once it has started. USER=bbs # The group to change to GROUP=bbs # Set this to the home directory of the user that the BBS runs as. export HOME=/home/bbs # # Don't edit anything below this line. # PATH=$SBBSEXEC:/sbin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin EXEC=$SBBSEXEC/sbbs NAME=sbbs DESC="Synchronet BBS Server" PIDFILE=/var/run/sbbs.pid SCREENFILE=/var/run/sbbs.screen set -e (test -f $EXEC) && (test -f `which screen`) || exit 0 if [ -z "`grep ^$USER /etc/passwd`" ]; then echo "User \"$USER\" does not exist in /etc/passwd" exit 1; fi if [ ! -z "$USER" ]; then USER=un$USER; fi if [ ! -z "$GROUP" ]; then GROUP=ug$GROUP; fi if [ -f $PIDFILE ]; then if [ $(ps -ef | grep $EXEC | grep -v grep | grep -c $EXEC) -eq 0 ]; then echo -n "stale lockfile found, removing -- " rm -f $PIDFILE; fi fi case "$1" in start) echo -n "Starting $DESC: " if [ -f $PIDFILE ]; then echo "already running according to $PIDFILE. Not started." else screen -m -D $EXEC $USER $GROUP & # fork process and give it a "screen" echo $! > $SCREENFILE sleep 2 echo $(pidof $EXEC | tr \ \\n | sort | head -n1) > $PIDFILE echo "$NAME" echo "[ detached console ]" fi ;; stop) echo -n "Stopping $DESC: " if [ ! -f $PIDFILE ]; then echo "None found running." exit 1; fi PID=`cat $PIDFILE` kill -TERM `expr $PID + 2` 2>&1 > /dev/null echo "$NAME." ;; force-stop) echo -n "Killing all $DESC: " if [ -f $PIDFILE ]; then kill -KILL `cat $PIDFILE` 2>&1 > /dev/null || true; fi killall -KILL $EXEC 2>&1 > /dev/null rm -f $PIDFILE echo "$NAME." ;; force-reload) echo -n "Reloading $DESC config: " if [ ! -f $PIDFILE ]; then echo "None found running." exit 1; fi PID=`cat $PIDFILE` kill -HUP `expr $PID + 2` 2>&1 > /dev/null echo "$NAME." ;; restart) echo -n "Restarting $DESC: " $0 stop sleep 5 if [ ! $(ps -ef | grep $EXEC | grep -v grep | grep -c $EXEC) -eq 0 ]; then $0 force-stop; fi sleep 1 $0 start echo "$NAME." ;; screen) # run this script with parameter of "screen" to get the virtual console # back that sbbs is running on. To detach from the "screen" and # leave sbbs running, hit Ctrl-A and then D. if [ -f $PIDFILE ]; then screen -r `cat $SCREENFILE` else echo "No $NAME apparently running." fi ;; *) echo "Usage: $0 {start|stop|restart|force-stop|force-reload|screen}" exit 1 esac exit 0