|
|
|
|
|
|
|
|
#!/bin/bash |
|
|
#!/bin/bash |
|
|
# |
|
|
# |
|
|
# SNFServer This shell script takes care of starting and stopping |
|
|
|
|
|
# the MicroNeil SNFServer daemon for SUSE systems. |
|
|
|
|
|
|
|
|
# snf-server Starts and stops the SNFServer daemon (SUSE). |
|
|
# |
|
|
# |
|
|
# Author-- Alban Deniz |
|
|
# Author-- Alban Deniz |
|
|
# |
|
|
# |
|
|
|
|
|
|
|
|
# Default-Start: 3 4 5 |
|
|
# Default-Start: 3 4 5 |
|
|
# Default-Stop: 0 1 2 6 |
|
|
# Default-Stop: 0 1 2 6 |
|
|
# Short-Description: SNFServer providing email filtering. |
|
|
# Short-Description: SNFServer providing email filtering. |
|
|
# Description: Start SNFServer to filter email for spam, |
|
|
|
|
|
# blacklist IP addresses, etc. |
|
|
|
|
|
|
|
|
# Description: Start SNFServer to filter email for spam and |
|
|
|
|
|
# check IP addresses. |
|
|
### END INIT INFO |
|
|
### END INIT INFO |
|
|
|
|
|
|
|
|
# Location of programs. |
|
|
|
|
|
|
|
|
# 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. |
|
|
installedDir="PREFIX" |
|
|
installedDir="PREFIX" |
|
|
|
|
|
|
|
|
# Location of programs. |
|
|
# Location of programs. |
|
|
|
|
|
|
|
|
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" |
|
|
|
|
|
|
|
|
userName="snfilter" |
|
|
userName="snfilter" |
|
|
|
|
|
|
|
|
# Name of lockfile. |
|
|
# Name of lockfile. |
|
|
lockFile="/var/lock/subsys/$prog" |
|
|
|
|
|
|
|
|
lockFile="/var/lock/subsys/$productionProg" |
|
|
|
|
|
|
|
|
# Start command. |
|
|
|
|
|
snfStartCmd="$dir/$prog $configFile > /dev/null 2>&1 &" |
|
|
|
|
|
|
|
|
# Name of client. |
|
|
|
|
|
clientProg="SNFClient" |
|
|
|
|
|
|
|
|
# Check for missing binaries (stale symlinks should not happen) |
|
|
# Check for missing binaries (stale symlinks should not happen) |
|
|
# Note: Special treatment of stop for LSB conformance |
|
|
# Note: Special treatment of stop for LSB conformance |
|
|
SNFServer_BIN=$dir/$prog |
|
|
|
|
|
test -x $SNFServer_BIN || { echo "$SNFServer_BIN not installed"; |
|
|
|
|
|
|
|
|
SNFServer_BIN=$dir/$productionProg |
|
|
|
|
|
test -x $SNFServer_BIN || { echo $"$SNFServer_BIN not installed"; |
|
|
if [ "$1" = "stop" ]; then exit 0; |
|
|
if [ "$1" = "stop" ]; then exit 0; |
|
|
else exit 5; fi; } |
|
|
else exit 5; fi; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
start_daemon() { return daemon ${1+"$@"}; } |
|
|
start_daemon() { return daemon ${1+"$@"}; } |
|
|
else |
|
|
else |
|
|
# emulate it |
|
|
# emulate it |
|
|
echo_rc() { echo " [${_SMSG[${_RC_RV}]}] "; } |
|
|
|
|
|
|
|
|
echo_rc() { echo $" [${_SMSG[${_RC_RV}]}] "; } |
|
|
fi |
|
|
fi |
|
|
rc_reset() { _RC_RV=0; } |
|
|
rc_reset() { _RC_RV=0; } |
|
|
rc_failed() |
|
|
rc_failed() |
|
|
|
|
|
|
|
|
# Reset status of this service |
|
|
# Reset status of this service |
|
|
rc_reset |
|
|
rc_reset |
|
|
|
|
|
|
|
|
|
|
|
# |
|
|
|
|
|
# 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 |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
# Return values acc. to LSB for all commands but status: |
|
|
# Return values acc. to LSB for all commands but status: |
|
|
# 0 - success |
|
|
# 0 - success |
|
|
# 1 - generic or unspecified error |
|
|
# 1 - generic or unspecified error |
|
|
|
|
|
|
|
|
# considered a success. |
|
|
# considered a success. |
|
|
|
|
|
|
|
|
start(){ |
|
|
start(){ |
|
|
SNFPID=$(pidof -s $dir/$prog) |
|
|
|
|
|
echo -n $"Starting $prog " |
|
|
|
|
|
if [ -n "$SNFPID" ] ; then |
|
|
|
|
|
return 0 |
|
|
|
|
|
|
|
|
echo -n $"Starting $productionProg: " |
|
|
|
|
|
for prog in $productionProg $debugProg |
|
|
|
|
|
do |
|
|
|
|
|
SNFPID=$(pidof -s $dir/$prog) |
|
|
|
|
|
if [ -n "$SNFPID" ] ; then |
|
|
|
|
|
return 0 |
|
|
|
|
|
fi |
|
|
|
|
|
done |
|
|
|
|
|
|
|
|
|
|
|
# Start. |
|
|
|
|
|
if [ $debugMode ] |
|
|
|
|
|
then |
|
|
|
|
|
|
|
|
|
|
|
# Enable core dumps and start with output redirected. |
|
|
|
|
|
(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 |
|
|
else |
|
|
su $userName -c "$snfStartCmd" -s /bin/sh |
|
|
|
|
|
RETVAL=$? |
|
|
|
|
|
if [ $RETVAL -eq 0 ]; then |
|
|
|
|
|
$dir/$clientProg -status.second > /dev/null 2>&1 |
|
|
|
|
|
RETVAL=$? |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(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 |
|
|
fi |
|
|
|
|
|
|
|
|
if [ $RETVAL -eq 0 ]; then |
|
|
if [ $RETVAL -eq 0 ]; then |
|
|
touch $lockFile |
|
|
touch $lockFile |
|
|
else |
|
|
else |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
stop(){ |
|
|
stop(){ |
|
|
echo -n $"Stopping $prog " |
|
|
|
|
|
SNFPID=$(pidof -s $dir/$prog) |
|
|
|
|
|
if [ -n "$SNFPID" ]; then |
|
|
|
|
|
|
|
|
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 |
|
|
$dir/$clientProg -shutdown > /dev/null 2>&1 |
|
|
sleep 10 |
|
|
sleep 10 |
|
|
SNFPID=$(pidof -s $dir/$prog) |
|
|
|
|
|
if [ -n "$SNFPID" ]; then |
|
|
|
|
|
kill $SNFPID |
|
|
|
|
|
RETVAL=$? |
|
|
|
|
|
else |
|
|
|
|
|
RETVAL=0 |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Check that the programs are no longer running. |
|
|
|
|
|
RETVAL=0 |
|
|
|
|
|
for prog in $debugProg $productionProg |
|
|
|
|
|
do |
|
|
|
|
|
|
|
|
|
|
|
SNFPID=$(pidof -s $dir/$prog) |
|
|
|
|
|
if [ -n "$SNFPID" ]; then |
|
|
|
|
|
kill $SNFPID |
|
|
|
|
|
RETVAL=$(($RETVAL+$?)) |
|
|
|
|
|
fi |
|
|
|
|
|
done |
|
|
else |
|
|
else |
|
|
# Process is not running. |
|
|
# Process is not running. |
|
|
RETVAL=0 |
|
|
RETVAL=0 |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
|
if [ $RETVAL -eq 0 ]; then |
|
|
if [ $RETVAL -eq 0 ]; then |
|
|
rm -f $lockFile |
|
|
rm -f $lockFile |
|
|
else |
|
|
else |
|
|
|
|
|
|
|
|
echo -n "Checking for service SNFServer " |
|
|
echo -n "Checking for service SNFServer " |
|
|
checkproc $SNFServer_BIN |
|
|
checkproc $SNFServer_BIN |
|
|
rc_status -v |
|
|
rc_status -v |
|
|
|
|
|
echo -n "Checking for service SNFDebugServer " |
|
|
|
|
|
checkproc $dir/$debugProg |
|
|
|
|
|
rc_status -v |
|
|
;; |
|
|
;; |
|
|
|
|
|
debug_mode) |
|
|
|
|
|
# |
|
|
|
|
|
# Remove any mode flags, and create the debug_mode file. |
|
|
|
|
|
# |
|
|
|
|
|
echo $"Switching to debug mode" |
|
|
|
|
|
createModeFile $debugModeFile |
|
|
|
|
|
;; |
|
|
|
|
|
production_mode) |
|
|
|
|
|
# |
|
|
|
|
|
# Remove any mode flags, and create the production_mode file. |
|
|
|
|
|
# |
|
|
|
|
|
echo $"Switching to production mode" |
|
|
|
|
|
createModeFile $productionModeFile |
|
|
|
|
|
;; |
|
|
try-restart|condrestart|force-reload|reload|probe) |
|
|
try-restart|condrestart|force-reload|reload|probe) |
|
|
# Not supported. |
|
|
# Not supported. |
|
|
echo -n "$0 $1 " |
|
|
echo -n "$0 $1 " |
|
|
|
|
|
|
|
|
rc_status -v |
|
|
rc_status -v |
|
|
;; |
|
|
;; |
|
|
*) |
|
|
*) |
|
|
echo "Usage: $0 {start|stop|status|restart}" |
|
|
|
|
|
|
|
|
echo $"Usage: $0 {start|stop|status|restart|production_mode|debug_mode}" |
|
|
exit 1 |
|
|
exit 1 |
|
|
;; |
|
|
;; |
|
|
esac |
|
|
esac |