Procházet zdrojové kódy

Implemented production/debug mode for snf-server.freebsd.


git-svn-id: https://svn.microneil.com/svn/PKG-SNF-CS-NIX/trunk@39 233e721a-07f6-49eb-a7da-05e0e16828fc
master
adeniz před 15 roky
rodič
revize
e36e05aab2

+ 3
- 0
SNF_CS_Developer_Package/ChangeLog Zobrazit soubor

@@ -1,5 +1,8 @@
2009-06-29 Alban Deniz <adeniz@skidmark.localdomain>

* Scripts/snf-server.freebsd: Implement debug mode and production
mode (Copied from snf-milter.freebsd in snf-milter distribution).

* Scripts/snf-server.suse: Implement debug mode and production
mode (Copied from snf-milter.suse in snf-milter distribution).


+ 149
- 18
SNF_CS_Developer_Package/Scripts/snf-server.freebsd Zobrazit soubor

@@ -1,7 +1,6 @@
#!/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
#
@@ -15,7 +14,23 @@

. /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"

# Location of programs.
@@ -24,20 +39,44 @@ dir="$installedDir/sbin"
# Name of config file.
configFile="CONFFILE"

# Name of daemon.
prog="SNFServer"

# Name of client.
clientProg="SNFClient"

# Names of daemons.
debugProg="SNFDebugServer"
productionProg="SNFServer"

name="snfserver"
rcvar=`set_rcvar`
command=$dir/$prog
command_args="$configFile > /dev/null 2>&1 &"
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"

@@ -47,6 +86,33 @@ snfserver_poststart()
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"
snfserver_stop()
{
@@ -59,15 +125,80 @@ stop_postcmd="${name}_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
}

# 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
run_rc_command "$1"

Načítá se…
Zrušit
Uložit