|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- #!/bin/bash
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- runDir=PREFIX/share/PACKAGE_NAME
-
-
- debugModeFile=$runDir/debug_mode
- productionModeFile=$runDir/production_mode
-
-
- if [ -f $debugModeFile ]
- then
- debugMode=true
- fi
-
-
- . /etc/rc.d/init.d/functions
-
-
- . /etc/sysconfig/network
-
-
- debugOutputFile=/var/log/PACKAGE_NAME/debug.log
-
-
- installedDir="PREFIX"
-
-
- dir="$installedDir/sbin"
-
-
- configFile="CONFFILE"
-
-
- debugProg="SNFDebugServer"
- productionProg="SNFServer"
-
-
- clientProg="SNFClient"
-
-
- userName="snfuser"
-
-
- lockFile="/var/lock/subsys/PACKAGE_NAME"
-
-
-
-
- createModeFile()
- {
- fileName=$1
-
-
- rm -f $productionModeFile $debugModeFile $fileName
- (
- echo $"PACKAGE_NAME mode file"
- echo
- echo $"This file specifies whether PACKAGE_NAME is configured to run in"
- echo $"production mode or debug mode. If the name of this file is"
- echo $"'production_mode', then PACKAGE_NAME is configured to run in"
- echo $"production mode. If the name is 'debug_mode', then PACKAGE_NAME is"
- echo $"configured to run in debug mode."
- echo
- echo $"To run in debug mode:"
- echo
- echo $" 1) Run 'PACKAGE_NAME debug_mode'"
- echo
- echo $" 2) Run 'PACKAGE_NAME restart' (if PACKAGE_NAME is already running),"
- echo $" or 'PACKAGE_NAME start' (to start PACKAGE_NAME)"
- echo
- echo $"To run in production mode:"
- echo
- echo $" 1) Run 'PACKAGE_NAME production_mode'"
- echo
- echo $" 2) Run 'PACKAGE_NAME restart' (if PACKAGE_NAME is already running),"
- echo $" or 'PACKAGE_NAME start' (to start PACKAGE_NAME)"
- echo
- echo $"By default, PACKAGE_NAME is configured to run in production mode."
- ) > $fileName
-
- }
-
- start(){
- echo -n $"Starting $productionProg: "
- for prog in $productionProg $debugProg
- do
- SNFPID=$(pidof -s $dir/$prog)
- if [ -n "$SNFPID" ] ; then
- echo -n $"$productionProg is already running"
- failure
- echo
- return 1
- fi
- done
-
-
- if [ $debugMode ]
- then
-
-
- (ulimit -c unlimited; \
- su $userName -s /bin/sh -c \
- "echo Starting $dir/$debugProg on $(date) >> $debugOutputFile"; \
- cd PREFIX/share/PACKAGE_NAME; \
- su $userName -c \
- "strace -r -tt -v $dir/$debugProg $configFile >> $debugOutputFile 2>&1 &" \
- -s /bin/sh)
-
- else
-
- (cd PREFIX/share/PACKAGE_NAME; \
- su $userName -c "$dir/$productionProg $configFile > /dev/null 2>&1 &" \
- -s /bin/sh > /dev/null 2>&1)
- fi
-
- RETVAL=$?
- if [ $RETVAL -eq 0 ]; then
- $dir/$clientProg -status.second > /dev/null 2>&1
- RETVAL=$?
- fi
-
- if [ $RETVAL -eq 0 ]; then
- touch $lockFile
- success
- echo
- else
- failure
- echo
- fi
- return $RETVAL
- }
-
- stop(){
- echo -n $"Stopping $productionProg: "
- DEBUG_SNFPID=$(pidof -s $dir/$debugProg)
- PRODUCTION_SNFPID=$(pidof -s $dir/$productionProg)
- if [ -n "$DEBUG_SNFPID" ] || [ -n "$PRODUCTION_SNFPID" ]; then
- $dir/$clientProg -shutdown > /dev/null 2>&1
- sleep 10
-
-
- RETVAL=0
- for prog in $debugProg $productionProg
- do
-
- SNFPID=$(pidof -s $dir/$prog)
- if [ -n "$SNFPID" ]; then
- kill $SNFPID
- RETVAL=$(($RETVAL+$?))
- fi
- done
- else
- echo -n $"$productionProg is not running"
- RETVAL=1
- failure
- echo
- fi
- if [ $RETVAL -eq 0 ]; then
- success
- echo
- rm -f $lockFile
- fi
- return $RETVAL
- }
-
- restart(){
- stop
- start
- }
-
-
-
- case "$1" in
- start)
- start
- ;;
- stop)
- stop
- ;;
- status)
- status $productionProg
- status $debugProg
- ;;
- restart)
- restart
- ;;
- debug_mode)
-
-
-
- echo $"Switching to debug mode"
- createModeFile $debugModeFile
- ;;
- production_mode)
-
-
-
- echo $"Switching to production mode"
- createModeFile $productionModeFile
- ;;
- *)
- echo $"Usage: $0 {start|stop|status|restart|production_mode|debug_mode}"
- exit 1
- esac
-
- exit $?
|