|
|
|
|
|
|
|
|
#!/bin/sh |
|
|
#!/bin/sh |
|
|
# |
|
|
# |
|
|
# SNFServer This shell script takes care of starting and stopping |
|
|
|
|
|
# the ARM Research SNFServer daemon for FreeBSD systems. |
|
|
|
|
|
|
|
|
# snf-server Starts and stops the SNFServer daemon (FreeBSD). |
|
|
# |
|
|
# |
|
|
# Author-- Alban Deniz |
|
|
# Author-- Alban Deniz |
|
|
# |
|
|
# |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
. /etc/rc.subr |
|
|
. /etc/rc.subr |
|
|
|
|
|
|
|
|
# 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. |
|
|
|
|
|
|
|
|
# Name of config file. |
|
|
# Name of config file. |
|
|
configFile="CONFFILE" |
|
|
configFile="CONFFILE" |
|
|
|
|
|
|
|
|
# Name of daemon. |
|
|
|
|
|
prog="SNFServer" |
|
|
|
|
|
|
|
|
|
|
|
# Name of client. |
|
|
# Name of client. |
|
|
clientProg="SNFClient" |
|
|
clientProg="SNFClient" |
|
|
|
|
|
|
|
|
|
|
|
# Names of daemons. |
|
|
|
|
|
debugProg="SNFDebugServer" |
|
|
|
|
|
productionProg="SNFServer" |
|
|
|
|
|
|
|
|
name="snfserver" |
|
|
name="snfserver" |
|
|
rcvar=`set_rcvar` |
|
|
rcvar=`set_rcvar` |
|
|
command=$dir/$prog |
|
|
|
|
|
command_args="$configFile > /dev/null 2>&1 &" |
|
|
|
|
|
required_dirs=$dir |
|
|
required_dirs=$dir |
|
|
required_files="$dir/$prog $dir/$clientProg $configFile" |
|
|
|
|
|
snf_user=snfilter |
|
|
|
|
|
snf_group=snfilter |
|
|
|
|
|
|
|
|
required_files="$dir/$productionProg $dir/$clientProg $configFile" |
|
|
|
|
|
snfserver_user=snfilter |
|
|
|
|
|
snfserver_group=snfilter |
|
|
|
|
|
|
|
|
|
|
|
# Start in a directory that is writable. |
|
|
|
|
|
snfserver_chdir=PREFIX/share/PACKAGE_NAME |
|
|
|
|
|
|
|
|
|
|
|
if [ $debugMode ] |
|
|
|
|
|
then |
|
|
|
|
|
|
|
|
|
|
|
# Enable core dumps. |
|
|
|
|
|
ulimit -c unlimited |
|
|
|
|
|
|
|
|
|
|
|
# Run debug version. |
|
|
|
|
|
command="/usr/local/bin/strace" |
|
|
|
|
|
|
|
|
|
|
|
# Start with output redirected to a file. |
|
|
|
|
|
command_args="-r -tt -v $dir/$debugProg $configFile >> $debugOutputFile 2>&1 &" |
|
|
|
|
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
|
|
|
|
# Run non-debug version. |
|
|
|
|
|
command=$dir/$productionProg |
|
|
|
|
|
|
|
|
|
|
|
# Start with output discarded. |
|
|
|
|
|
command_args="$configFile > /dev/null 2>&1 &" |
|
|
|
|
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
start_postcmd="${name}_poststart" |
|
|
start_postcmd="${name}_poststart" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $? |
|
|
return $? |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
status_cmd="${name}_status" |
|
|
|
|
|
|
|
|
|
|
|
snfserver_status() |
|
|
|
|
|
{ |
|
|
|
|
|
# Check whether the programs are running. |
|
|
|
|
|
RETVAL=0 |
|
|
|
|
|
for progName in $debugProg $productionProg |
|
|
|
|
|
do |
|
|
|
|
|
|
|
|
|
|
|
SNFPID=$(check_process $dir/$progName) |
|
|
|
|
|
if [ -n "$SNFPID" ]; then |
|
|
|
|
|
echo "$progName is running as pid $SNFPID." |
|
|
|
|
|
RETVAL=$(($RETVAL+1)) |
|
|
|
|
|
else |
|
|
|
|
|
echo "$progName is not running." |
|
|
|
|
|
fi |
|
|
|
|
|
done |
|
|
|
|
|
if [ 0 -eq $RETVAL ] |
|
|
|
|
|
then |
|
|
|
|
|
# Not running. |
|
|
|
|
|
return 1 |
|
|
|
|
|
else |
|
|
|
|
|
# At least one program is running. |
|
|
|
|
|
return 0 |
|
|
|
|
|
fi |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
stop_cmd="${name}_stop" |
|
|
stop_cmd="${name}_stop" |
|
|
snfserver_stop() |
|
|
snfserver_stop() |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
snfserver_poststop() |
|
|
snfserver_poststop() |
|
|
{ |
|
|
{ |
|
|
SNFPID=$(check_process $dir/$prog) |
|
|
|
|
|
if [ -n "$SNFPID" ]; then |
|
|
|
|
|
kill $SNFPID |
|
|
|
|
|
RETVAL=$? |
|
|
|
|
|
else |
|
|
|
|
|
RETVAL=0 |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
DEBUG_SNFPID=$(check_process $dir/$debugProg) |
|
|
|
|
|
PRODUCTION_SNFPID=$(check_process $dir/$productionProg) |
|
|
|
|
|
|
|
|
|
|
|
# Check that the programs are no longer running. |
|
|
|
|
|
RETVAL=0 |
|
|
|
|
|
for progName in $debugProg $productionProg |
|
|
|
|
|
do |
|
|
|
|
|
|
|
|
|
|
|
SNFPID=$(check_process $dir/$progName) |
|
|
|
|
|
if [ -n "$SNFPID" ]; then |
|
|
|
|
|
kill $SNFPID |
|
|
|
|
|
RETVAL=$(($RETVAL+$?)) |
|
|
|
|
|
fi |
|
|
|
|
|
done |
|
|
return $RETVAL |
|
|
return $RETVAL |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
# Additional commands. |
|
|
|
|
|
extra_commands="production_mode debug_mode" |
|
|
|
|
|
|
|
|
|
|
|
# |
|
|
|
|
|
# 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 |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
production_mode_cmd="${name}_production_mode" |
|
|
|
|
|
|
|
|
|
|
|
# Switch to production mode. |
|
|
|
|
|
snfserver_production_mode() |
|
|
|
|
|
{ |
|
|
|
|
|
echo "Switching to production mode" |
|
|
|
|
|
createModeFile $productionModeFile |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
debug_mode_cmd="${name}_debug_mode" |
|
|
|
|
|
|
|
|
|
|
|
# Switch to debug mode. |
|
|
|
|
|
snfserver_debug_mode() |
|
|
|
|
|
{ |
|
|
|
|
|
echo "Switching to debug mode" |
|
|
|
|
|
createModeFile $debugModeFile |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
load_rc_config $name |
|
|
load_rc_config $name |
|
|
run_rc_command "$1" |
|
|
run_rc_command "$1" |