|
|
|
|
|
|
|
|
#! /bin/sh |
|
|
#! /bin/sh |
|
|
# |
|
|
# |
|
|
# snfServer. This shell script takes care of starting and stopping |
|
|
|
|
|
# the ARM Research SNFServer daemon for Ubuntu systems. |
|
|
|
|
|
|
|
|
# snf-server Starts and stops the SNFServer daemon (Ubuntu). |
|
|
# |
|
|
# |
|
|
# Author: Alban Deniz |
|
|
# Author: Alban Deniz |
|
|
# |
|
|
# |
|
|
|
|
|
|
|
|
# blacklist IP addresses, etc. |
|
|
# blacklist IP addresses, etc. |
|
|
### END INIT INFO |
|
|
### END INIT INFO |
|
|
|
|
|
|
|
|
|
|
|
# Directory to run in. |
|
|
|
|
|
runDir=PREFIX/share/PACKAGE_NAME |
|
|
|
|
|
|
|
|
|
|
|
# Define mode files. |
|
|
|
|
|
debugModeFile=$runDir/debug_mode |
|
|
|
|
|
productionModeFile=$runDir/production_mode |
|
|
|
|
|
|
|
|
|
|
|
# Set debug mode flag. |
|
|
|
|
|
if [ -f $debugModeFile ] |
|
|
|
|
|
then |
|
|
|
|
|
debugMode=true |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
# Debug output file. |
|
|
|
|
|
debugOutputFile=/var/log/PACKAGE_NAME/debug.log |
|
|
|
|
|
|
|
|
# Location of installation. |
|
|
# Location of installation. |
|
|
installedDir="PREFIX" |
|
|
installedDir="PREFIX" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configFile="CONFFILE" |
|
|
configFile="CONFFILE" |
|
|
|
|
|
|
|
|
# Name of daemon. |
|
|
# Name of daemon. |
|
|
prog="SNFServer" |
|
|
|
|
|
|
|
|
debugProg="SNFDebugServer" |
|
|
|
|
|
productionProg="SNFServer" |
|
|
|
|
|
|
|
|
# Name of client. |
|
|
# Name of client. |
|
|
clientProg="SNFClient" |
|
|
clientProg="SNFClient" |
|
|
|
|
|
|
|
|
# Name of user to run as. |
|
|
# Name of user to run as. |
|
|
userName="snfilter" |
|
|
userName="snfilter" |
|
|
|
|
|
|
|
|
|
|
|
# Name of group. |
|
|
|
|
|
groupName=$userName |
|
|
|
|
|
|
|
|
# Name of lockfile. |
|
|
# Name of lockfile. |
|
|
lockFile="/var/lock/subsys/$prog" |
|
|
|
|
|
|
|
|
lockFile="/var/lock/subsys/$productionProg" |
|
|
|
|
|
|
|
|
# Name of client. |
|
|
# Name of client. |
|
|
clientProg="SNFClient" |
|
|
clientProg="SNFClient" |
|
|
|
|
|
|
|
|
# Start command. |
|
|
|
|
|
snfStartCmd="$dir/$prog $configFile > /dev/null 2>&1 &" |
|
|
|
|
|
|
|
|
|
|
|
# Do NOT "set -e" |
|
|
# Do NOT "set -e" |
|
|
|
|
|
|
|
|
# PATH should only include /usr/* if it runs after the mountnfs.sh script |
|
|
# PATH should only include /usr/* if it runs after the mountnfs.sh script |
|
|
PATH=/usr/sbin:/usr/bin:/sbin:/bin |
|
|
PATH=/usr/sbin:/usr/bin:/sbin:/bin |
|
|
DESC="SNFServer providing email filtering" |
|
|
DESC="SNFServer providing email filtering" |
|
|
NAME="snfServer" |
|
|
|
|
|
DAEMON=$dir/$prog |
|
|
|
|
|
DAEMON_ARGS="$configFile" |
|
|
|
|
|
|
|
|
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 |
|
|
SCRIPTNAME=/etc/init.d/$NAME |
|
|
|
|
|
|
|
|
# Exit if the package is not installed |
|
|
# Exit if the package is not installed |
|
|
[ -x "$DAEMON" ] || exit 0 |
|
|
|
|
|
|
|
|
[ -x "$PRODUCTION_DAEMON" ] || exit 0 |
|
|
|
|
|
|
|
|
# Read configuration variable file if it is present |
|
|
# Read configuration variable file if it is present |
|
|
[ -r /etc/default/$NAME ] && . /etc/default/$NAME |
|
|
[ -r /etc/default/$NAME ] && . /etc/default/$NAME |
|
|
|
|
|
|
|
|
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present. |
|
|
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present. |
|
|
. /lib/lsb/init-functions |
|
|
. /lib/lsb/init-functions |
|
|
|
|
|
|
|
|
|
|
|
# |
|
|
|
|
|
# Function to create the mode file. |
|
|
|
|
|
# |
|
|
|
|
|
createModeFile() |
|
|
|
|
|
{ |
|
|
|
|
|
fileName=$1 |
|
|
|
|
|
|
|
|
|
|
|
# Remove any existing mode files. |
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
# |
|
|
# |
|
|
# Function that starts the daemon/service |
|
|
# Function that starts the daemon/service |
|
|
# |
|
|
# |
|
|
|
|
|
|
|
|
# 1 if daemon was already running |
|
|
# 1 if daemon was already running |
|
|
# 2 if daemon could not be started |
|
|
# 2 if daemon could not be started |
|
|
start-stop-daemon --chuid $userName --start --quiet \ |
|
|
start-stop-daemon --chuid $userName --start --quiet \ |
|
|
--exec $DAEMON --test > /dev/null 2>&1 \ |
|
|
|
|
|
|| return 1 |
|
|
|
|
|
start-stop-daemon --chuid $userName --start --quiet \ |
|
|
|
|
|
--background --exec $DAEMON -- $DAEMON_ARGS > /dev/null 2>&1 \ |
|
|
|
|
|
|| return 2 |
|
|
|
|
|
|
|
|
--exec $PRODUCTION_DAEMON --test > /dev/null 2>&1 \ |
|
|
|
|
|
|| return 1 |
|
|
|
|
|
|
|
|
|
|
|
if [ $debugMode ] |
|
|
|
|
|
then |
|
|
|
|
|
|
|
|
|
|
|
# Enable core dumps. |
|
|
|
|
|
ulimit -c unlimited |
|
|
|
|
|
|
|
|
|
|
|
# Add date to the debug file. |
|
|
|
|
|
echo "Starting $DEBUG_DAEMON $DEBUG_DAEMON_ARGS on " $(date) >> \ |
|
|
|
|
|
$debugOutputFile |
|
|
|
|
|
chown $userName:$groupName $debugOutputFile |
|
|
|
|
|
|
|
|
|
|
|
# Start with output redirected. |
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
# Check that process started. |
|
|
# Check that process started. |
|
|
$dir/$clientProg -status.second > /dev/null 2>&1 |
|
|
$dir/$clientProg -status.second > /dev/null 2>&1 |
|
|
RETVAL=$? |
|
|
RETVAL=$? |
|
|
|
|
|
|
|
|
# other if a failure occurred |
|
|
# other if a failure occurred |
|
|
# Check whether SNFServer is running. |
|
|
# Check whether SNFServer is running. |
|
|
start-stop-daemon --chuid $userName --start --quiet \ |
|
|
start-stop-daemon --chuid $userName --start --quiet \ |
|
|
--exec $DAEMON --test > /dev/null |
|
|
|
|
|
|
|
|
--exec $PRODUCTION_DAEMON --test > /dev/null |
|
|
RETVAL=$? |
|
|
RETVAL=$? |
|
|
|
|
|
|
|
|
if [ $RETVAL -ne 1 ]; then |
|
|
if [ $RETVAL -ne 1 ]; then |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Check again whether SNFServer is running. |
|
|
# Check again whether SNFServer is running. |
|
|
start-stop-daemon --chuid $userName --start --quiet \ |
|
|
start-stop-daemon --chuid $userName --start --quiet \ |
|
|
--exec $DAEMON --test > /dev/null |
|
|
|
|
|
|
|
|
--exec $PRODUCTION_DAEMON --test > /dev/null |
|
|
RETVAL=$? |
|
|
RETVAL=$? |
|
|
|
|
|
|
|
|
if [ $RETVAL -eq 1 ] ; then |
|
|
if [ $RETVAL -eq 1 ] ; then |
|
|
# Send TERM signal to stop SNFServer. |
|
|
# Send TERM signal to stop SNFServer. |
|
|
start-stop-daemon --stop --quiet --retry=TERM/5 --exec $DAEMON |
|
|
|
|
|
|
|
|
start-stop-daemon --stop --quiet --retry=TERM/5 --exec $PRODUCTION_DAEMON |
|
|
RETVAL="$?" |
|
|
RETVAL="$?" |
|
|
[ "$RETVAL" = 2 ] && return 2 |
|
|
[ "$RETVAL" = 2 ] && return 2 |
|
|
return "$RETVAL" |
|
|
return "$RETVAL" |
|
|
|
|
|
|
|
|
;; |
|
|
;; |
|
|
status) |
|
|
status) |
|
|
start-stop-daemon --chuid $userName --start --quiet \ |
|
|
start-stop-daemon --chuid $userName --start --quiet \ |
|
|
--exec $DAEMON --test > /dev/null |
|
|
|
|
|
|
|
|
--exec $PRODUCTION_DAEMON --test > /dev/null |
|
|
RETVAL=$? |
|
|
RETVAL=$? |
|
|
if [ $RETVAL -eq 0 ]; then |
|
|
if [ $RETVAL -eq 0 ]; then |
|
|
# Stopped |
|
|
# Stopped |
|
|
echo "$prog is stopped" |
|
|
|
|
|
|
|
|
echo "$productionProg is stopped" |
|
|
else |
|
|
else |
|
|
# Running |
|
|
# Running |
|
|
echo "$prog (pid $(pidof $dir/$prog)) is running" |
|
|
|
|
|
|
|
|
echo "$productionProg (pid $(pidof $PRODUCTION_DAEMON)) is running" |
|
|
fi |
|
|
fi |
|
|
;; |
|
|
;; |
|
|
restart|force-reload) |
|
|
restart|force-reload) |
|
|
|
|
|
|
|
|
;; |
|
|
;; |
|
|
esac |
|
|
esac |
|
|
;; |
|
|
;; |
|
|
|
|
|
debug_mode) |
|
|
|
|
|
# |
|
|
|
|
|
# Remove any mode flags, and create the debug_mode file. |
|
|
|
|
|
# |
|
|
|
|
|
log_daemon_msg "Switching to debug mode $DESC" "$NAME" |
|
|
|
|
|
createModeFile $debugModeFile |
|
|
|
|
|
;; |
|
|
|
|
|
production_mode) |
|
|
|
|
|
# |
|
|
|
|
|
# Remove any mode flags, and create the production_mode file. |
|
|
|
|
|
# |
|
|
|
|
|
log_daemon_msg "Switching to production mode $DESC" "$NAME" |
|
|
|
|
|
createModeFile $productionModeFile |
|
|
|
|
|
;; |
|
|
*) |
|
|
*) |
|
|
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 |
|
|
|
|
|
|
|
|
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload|production_mode|debug_mode}" >&2 |
|
|
exit 3 |
|
|
exit 3 |
|
|
;; |
|
|
;; |
|
|
esac |
|
|
esac |