#!/bin/bash # # osgird # # chkconfig: 2345 80 30 # description: osgrid start/stop script # Source function library. . /lib/lsb/init-functions OSGRID=osgrid OSDIR=/home/osgrid/opensim/bin PRGFL=/etc/init.d/$OSGRID SLEEPTM=90 CHKTM=30 export MONO_THREADS_PER_CPU=512 ulimit -s 262144 SCRNID=$OSGRID PIDFL=/var/run/opensim_region_shell$OSGRID.pid USER=osgrid EXEFILE=/tmp/tmp$OSGRID.sh start() { echo \#\!/bin/bash > $EXEFILE echo export MONO_THREADS_PER_CPU=512 >> $EXEFILE echo ulimit -s 262144 >> $EXEFILE echo cd $OSDIR >> $EXEFILE echo screen -S $OSGRID -d -m mono $OSDIR/OpenSim.exe >> $EXEFILE chmod +x $EXEFILE #EXEFILE="" #EXEFILE=$OSDIR/bin/osgrid1_exec.sh su $USER -c $EXEFILE echo "OpenSim Region Server Start." sleep 5 #make pid-file #ps afxu | grep mono |grep -w $OSGRID | awk {'print $2'} > $PIDFL #rm -f $EXEFILE } stop() { su $USER -c "screen -S $SCRNID -p 0 -X stuff $'quit\n' 1> /dev/null 2>&1" echo "OpenSim Region Server Stoped." } kill_loop() { PID=`cat $PIDFL 2> /dev/null` if [ "$PID" != "" ]; then kill -9 $PID 2> /dev/null rm -f $PIDFL fi } loop_check() { kill_loop echo $$ >| $PIDFL while [ "" = "" ]; do sleep $CHKTM CHECK=`ps ax|grep SCREEN |grep $SCRNID` if [ "$CHECK" = "" ]; then start fi done } case "$1" in start) start #/bin/bash $PRGFL check & ;; stop) kill_loop stop ;; restart|reload) kill_loop stop sleep $SLEEPTM start #/bin/bash $PRGFL check & ;; *) echo $"Usage: $0 {start|stop|restart}" exit 1 esac exit $?