2 # fbmuckctl This script takes care of starting and stopping
3 # FuzzBall Muck servers on this machine.
5 # The format of /etc/fbmucks is:
7 # MUCKNAME USERNAME MUCK_ROOT_PATH SCRIPTNAME PORTS
8 # tygmuck3 tygryss /home/revar/tygmuck restart 8888,8899s
9 # feepmuck foxen /home/foxen/muck restart 8800
11 # Port numbers are separate by commas. An 's' at the end of a port number
12 # means that that port is designated as a secure SSL port.
14 [ -f /etc
/fbmucks
] || exit 0
23 # See how we were called.
30 while read name user path
script ports
; do
31 if [ "x$mucknames" != "x" ]; then
33 for muckname
in $mucknames; do
34 if [ "x$muckname" = "x$name" ]; then
38 if [ $found -eq 0 ]; then
42 if [ "x$who" = "xroot" -o "x$who" = "x$user" ]; then
43 ports
=`echo $ports | sed 's/,/ /g' | sed 's/\([0-9]*\)s/-sport \1/g'`
45 echo -n "Starting $name fbmuck: "
47 if [ "x$who" = "x$user" ]; then
50 echo "started $name fbmuck"
53 echo "failed to start $name fbmuck"
56 rcode
=`su $user -c "$path/$script $ports; echo \\\$?"`
57 if [ "$rcode" == 0 ]; then
58 echo "started $name fbmuck"
61 echo "failed to start $name fbmuck"
64 if [ $failed == 0 ]; then
65 while [ ! -f $path/$pidfile ]; do
66 echo "DEBUG: waiting for $path/$pidfile to exist ..."
79 while read name user path
script ports
; do
80 if [ "x$mucknames" != "x" ]; then
82 for muckname
in $mucknames; do
83 if [ "x$muckname" = "x$name" ]; then
87 if [ $found = 0 ]; then
91 if [ "x$who" = "xroot" -o "x$who" = "x$user" ]; then
93 echo -n "Shutting down $name fbmuck: "
94 if [ -f $path/$pidfile ]; then
95 pid
=`cat $path/$pidfile`
96 if [ -d /proc
/$pid ]; then
102 # Wait for server to complete a clean shutdown.
103 # If the process doesn't change status for a period
104 # longer than sixty seconds, assume it is hung, and exit.
107 while [ -d /proc
/$pid ]; do
108 newstat
=`grep 'State:' /proc/$pid/status|awk '{print $2}'`
109 if [ "x$newstat" != "xR" -a "x$laststat" = "x$newstat" ]; then
110 limitcnt
=`expr $limitcnt - 1`
111 if [ $limitcnt -eq 0 ]; then
125 && echo "stopped $name fbmuck" \
126 || echo "failed to stop $name fbmuck"
143 while read name user path
script ports
; do
144 if [ "x$mucknames" != "x" ]; then
146 for muckname
in $mucknames; do
147 if [ "x$muckname" = "x$name" ]; then
151 if [ $found -eq 0 ]; then
155 if [ "x$who" = "xroot" -o "x$who" = "x$user" ]; then
156 echo -n "fbmuck for $name "
157 if [ -f $path/$pidfile ]; then
158 pid
=`cat $path/$pidfile`
159 if [ -d /proc
/$pid ]; then
160 echo "is running. ($pid)"
162 echo "is not running."
165 echo "is not running."
171 echo -n "Usage: $0 {start|stop|restart|status}"
172 if [ "x$who" = "xroot" ]; then
173 echo " [muckname,[muckname,[..]]]"