|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- #! /bin/sh
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- runDir=PREFIX/share/PACKAGE_NAME
-
-
- debugModeFile=$runDir/debug_mode
- productionModeFile=$runDir/production_mode
-
-
- if [ -f $debugModeFile ]
- then
- debugMode=true
- fi
-
-
- debugOutputFile=/var/log/PACKAGE_NAME/debug.log
-
-
- installedDir="PREFIX"
-
-
- dir="$installedDir/sbin"
-
-
- configFile="CONFFILE"
-
-
- debugProg="SNFDebugServer"
- productionProg="SNFServer"
-
-
- clientProg="SNFClient"
-
-
- userName="snfuser"
-
-
- groupName=$userName
-
-
- lockFile="/var/lock/subsys/$productionProg"
-
-
- clientProg="SNFClient"
-
-
-
-
- PATH=/usr/sbin:/usr/bin:/sbin:/bin
- DESC="SNFServer providing email filtering"
- NAME="snf-server"
-
- DEBUG_DAEMON="/usr/bin/strace"
- DEBUG_DAEMON_ARGS="-r -tt -v $dir/$debugProg $configFile"
-
- PRODUCTION_DAEMON=$dir/$productionProg
- PRODUCTION_DAEMON_ARGS="$configFile"
-
- SCRIPTNAME=/etc/init.d/$NAME
-
-
- [ -x "$PRODUCTION_DAEMON" ] || exit 0
-
-
- [ -r /etc/default/$NAME ] && . /etc/default/$NAME
-
-
- [ -f /etc/default/rcS ] && . /etc/default/rcS
-
-
-
- . /lib/lsb/init-functions
-
-
-
-
- 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
-
- }
-
-
-
-
- do_start()
- {
-
-
-
-
- start-stop-daemon --chuid $userName --start --quiet \
- --exec $PRODUCTION_DAEMON --test > /dev/null 2>&1 \
- || return 1
-
- if [ $debugMode ]
- then
-
-
- ulimit -c unlimited
-
-
- echo "Starting $DEBUG_DAEMON $DEBUG_DAEMON_ARGS on " $(date) >> \
- $debugOutputFile
- chown $userName:$groupName $debugOutputFile
-
-
- start-stop-daemon --chuid $userName --start --quiet \
- --chdir $runDir \
- --exec $DEBUG_DAEMON -- $DEBUG_DAEMON_ARGS >> \
- $debugOutputFile 2>&1 \
- || return 2 &
- else
-
- start-stop-daemon --chuid $userName --start --quiet \
- --chdir $runDir \
- --background --exec $PRODUCTION_DAEMON -- \
- $PRODUCTION_DAEMON_ARGS > /dev/null 2>&1 || return 2
- fi
-
-
- $dir/$clientProg -status.second > /dev/null 2>&1
- RETVAL=$?
- if [ $RETVAL -ne 0 ]; then
- RETVAL=2
- fi
- return $RETVAL
- }
-
-
-
-
- do_stop()
- {
-
-
-
-
-
-
- start-stop-daemon --chuid $userName --start --quiet \
- --exec $PRODUCTION_DAEMON --test > /dev/null
- RETVAL=$?
-
- if [ $RETVAL -ne 1 ]; then
- return 1
- fi
-
-
- $dir/$clientProg -shutdown > /dev/null 2>&1
- sleep 10
-
-
- start-stop-daemon --chuid $userName --start --quiet \
- --exec $PRODUCTION_DAEMON --test > /dev/null
- RETVAL=$?
-
- if [ $RETVAL -eq 1 ] ; then
-
- start-stop-daemon --stop --quiet --retry=TERM/5 --exec $PRODUCTION_DAEMON
- RETVAL="$?"
- [ "$RETVAL" = 2 ] && return 2
- return "$RETVAL"
- fi
-
-
- return 0
-
- }
-
- case "$1" in
- start)
- [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
- do_start
- case "$?" in
- 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
- 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
- esac
- ;;
- stop)
- [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
- do_stop
- case "$?" in
- 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
- 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
- esac
- ;;
- status)
- start-stop-daemon --chuid $userName --start --quiet \
- --exec $PRODUCTION_DAEMON --test > /dev/null
- RETVAL=$?
- if [ $RETVAL -eq 0 ]; then
-
- echo "$productionProg is stopped"
- else
-
- echo "$productionProg (pid $(pidof $PRODUCTION_DAEMON)) is running"
- fi
- ;;
- restart|force-reload)
-
-
-
-
- log_daemon_msg "Restarting $DESC" "$NAME"
- do_stop
- case "$?" in
- 0|1)
- do_start
- case "$?" in
- 0) log_end_msg 0 ;;
- 1) log_end_msg 1 ;;
- *) log_end_msg 1 ;;
- esac
- ;;
- *)
-
- log_end_msg 1
- ;;
- esac
- ;;
- debug_mode)
-
-
-
- log_daemon_msg "Switching to debug mode $DESC" "$NAME"
- createModeFile $debugModeFile
- ;;
- production_mode)
-
-
-
- log_daemon_msg "Switching to production mode $DESC" "$NAME"
- createModeFile $productionModeFile
- ;;
- *)
- echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload|production_mode|debug_mode}" >&2
- exit 3
- ;;
- esac
|