|
|
|
|
|
|
|
|
#!/bin/sh |
|
|
#!/bin/sh |
|
|
# |
|
|
# |
|
|
# SNFServer This shell script takes care of starting and stopping |
|
|
|
|
|
# the MicroNeil SNFServer daemon for OpenBSD systems. |
|
|
|
|
|
|
|
|
# snf-server. Starts and stops the SNFServer daemon (OpenBSD). |
|
|
|
|
|
# |
|
|
# Author: Alban Deniz |
|
|
# Author: Alban Deniz |
|
|
# |
|
|
# |
|
|
# Copyright (C) 2008 ARM Research Labs, LLC. |
|
|
# Copyright (C) 2008 ARM Research Labs, LLC. |
|
|
# See www.armresearch.com for the copyright terms. |
|
|
# See www.armresearch.com for the copyright terms. |
|
|
# |
|
|
# |
|
|
|
|
|
|
|
|
|
|
|
# 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 |
|
|
|
|
|
|
|
|
|
|
|
# ktrace output file. |
|
|
|
|
|
ktraceOutputFile=/var/log/PACKAGE_NAME/ktrace.out |
|
|
|
|
|
|
|
|
# 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" |
|
|
|
|
|
|
|
|
# Start command. |
|
|
|
|
|
snfStartCmd="$dir/$prog $configFile > /dev/null 2>&1 &" |
|
|
|
|
|
|
|
|
# |
|
|
|
|
|
# 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 |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
start(){ |
|
|
start(){ |
|
|
SNFPID=`ps -axww | grep $dir/$prog | grep -v grep | awk '{print $1}'` |
|
|
|
|
|
echo -n " $prog " |
|
|
|
|
|
if [ -n "$SNFPID" ] ; then |
|
|
|
|
|
echo "already running" |
|
|
|
|
|
return 1 |
|
|
|
|
|
|
|
|
echo -n " $productionProg " |
|
|
|
|
|
|
|
|
|
|
|
for prog in $productionProg $debugProg |
|
|
|
|
|
do |
|
|
|
|
|
SNFPID=`ps -axww | grep $dir/$prog | grep -v grep | awk '{print $1}'` |
|
|
|
|
|
if [ -n "$SNFPID" ] ; then |
|
|
|
|
|
echo "already running" |
|
|
|
|
|
return 1 |
|
|
|
|
|
fi |
|
|
|
|
|
done |
|
|
|
|
|
|
|
|
|
|
|
# Start. |
|
|
|
|
|
if [ $debugMode ] |
|
|
|
|
|
then |
|
|
|
|
|
|
|
|
|
|
|
# Enable core dumps and start with ktrace and output redirected. |
|
|
|
|
|
(ulimit -c unlimited; \ |
|
|
|
|
|
su -m $userName -c \ |
|
|
|
|
|
"echo Starting $dir/$debugProg on $(date) >> $debugOutputFile"; \ |
|
|
|
|
|
cd PREFIX/share/PACKAGE_NAME; \ |
|
|
|
|
|
su -m $userName -c \ |
|
|
|
|
|
"ktrace -f $ktraceOutputFile $dir/$debugProg $configFile >> $debugOutputFile 2>&1 &") |
|
|
|
|
|
|
|
|
else |
|
|
else |
|
|
su -m $userName -c "$snfStartCmd" > /dev/null 2>&1 |
|
|
|
|
|
RETVAL=$? |
|
|
|
|
|
if [ $RETVAL -eq 0 ]; then |
|
|
|
|
|
$dir/$clientProg -status.second > /dev/null 2>&1 |
|
|
|
|
|
RETVAL=$? |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(cd PREFIX/share/PACKAGE_NAME; \ |
|
|
|
|
|
su -m $userName -c "$dir/$productionProg $configFile > /dev/null 2>&1 &" \ |
|
|
|
|
|
> /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 |
|
|
echo "started " |
|
|
echo "started " |
|
|
|
|
|
|
|
|
return $RETVAL |
|
|
return $RETVAL |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getPID(){ |
|
|
|
|
|
ps -axww | grep $1 | grep -v grep | awk '{print $1}' |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
stopFunction(){ |
|
|
stopFunction(){ |
|
|
echo -n " $prog " |
|
|
echo -n " $prog " |
|
|
SNFPID=`ps -axww | grep $dir/$prog | grep -v grep | awk '{print $1}'` |
|
|
|
|
|
if [ -n "$SNFPID" ]; then |
|
|
|
|
|
|
|
|
DEBUG_SNFPID=`getPID $dir/$debugProg` |
|
|
|
|
|
PRODUCTION_SNFPID=`getPID $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=`ps -axww | grep $dir/$prog | grep -v grep | awk '{print $1}'` |
|
|
|
|
|
if [ -n "$SNFPID" ]; then |
|
|
|
|
|
kill $SNFPID |
|
|
|
|
|
RETVAL=$? |
|
|
|
|
|
else |
|
|
|
|
|
RETVAL=0 |
|
|
|
|
|
fi |
|
|
|
|
|
echo -n "stopped" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Check that the programs are no longer running. |
|
|
|
|
|
RETVAL=0 |
|
|
|
|
|
for prog in $debugProg $productionProg |
|
|
|
|
|
do |
|
|
|
|
|
|
|
|
|
|
|
SNFPID=`getPID $dir/$prog` |
|
|
|
|
|
if [ -n "$SNFPID" ]; then |
|
|
|
|
|
kill $SNFPID |
|
|
|
|
|
RETVAL=$(($RETVAL+$?)) |
|
|
|
|
|
fi |
|
|
|
|
|
done |
|
|
|
|
|
echo -n "stopped" |
|
|
else |
|
|
else |
|
|
echo -n "not running" |
|
|
echo -n "not running" |
|
|
RETVAL=1 |
|
|
RETVAL=1 |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
|
echo "" |
|
|
echo "" |
|
|
return $RETVAL |
|
|
return $RETVAL |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
status(){ |
|
|
status(){ |
|
|
SNFPID=`ps -axww | grep $dir/$prog | grep -v grep | awk '{print $1}'` |
|
|
|
|
|
if [ -n "$SNFPID" ] ; then |
|
|
|
|
|
echo "$prog (pid $SNFPID) is running" |
|
|
|
|
|
return 0 |
|
|
|
|
|
else |
|
|
|
|
|
echo "$prog is not running" |
|
|
|
|
|
return 0 |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
# Check whether the programs are running. |
|
|
|
|
|
RETVAL=0 |
|
|
|
|
|
for progName in $debugProg $productionProg |
|
|
|
|
|
do |
|
|
|
|
|
|
|
|
|
|
|
SNFPID=`getPID $dir/$progName` |
|
|
|
|
|
if [ -n "$SNFPID" ]; then |
|
|
|
|
|
echo "$progName (pid $SNFPID) is running" |
|
|
|
|
|
RETVAL=$(($RETVAL+1)) |
|
|
|
|
|
else |
|
|
|
|
|
echo "$progName is not running" |
|
|
|
|
|
fi |
|
|
|
|
|
done |
|
|
|
|
|
return 0 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
# See how we were called. |
|
|
# See how we were called. |
|
|
|
|
|
|
|
|
stopFunction |
|
|
stopFunction |
|
|
;; |
|
|
;; |
|
|
status) |
|
|
status) |
|
|
status $prog |
|
|
|
|
|
|
|
|
status |
|
|
;; |
|
|
;; |
|
|
restart) |
|
|
restart) |
|
|
restart |
|
|
restart |
|
|
;; |
|
|
;; |
|
|
|
|
|
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 debug_mode file. |
|
|
|
|
|
# |
|
|
|
|
|
echo "Switching to production mode" |
|
|
|
|
|
createModeFile $productionModeFile |
|
|
|
|
|
;; |
|
|
*) |
|
|
*) |
|
|
echo "Usage: $0 {start|stop|status|restart}" |
|
|
|
|
|
|
|
|
echo "Usage: $0 {start|stop|status|restart|production_mode|debug_mode}" |
|
|
exit 1 |
|
|
exit 1 |
|
|
esac |
|
|
esac |
|
|
|
|
|
|