#!/bin/bash
#
# @(#) strlogd,v openss7-0_9_2_F(0.9.2.5) 2006/05/08 03:35:10
# Copyright (c) 2001-2006  OpenSS7 Corporation <http://www.openss7.com>
# Copyright (c) 1997-2000  Brian F. G. Bidulock <bidulock@openss7.org>
# All Rights Reserved.
#
# Distributed by OpenSS7 Corporation.  See the bottom of this script for copying
# permissions.
#
# Redhat chkconfig init script conventions
#
# strlogd:	start and stop strlogd facility
# chkconfig:	- 55 55
# lockfile:	/var/lock/subsys/strlogd
# config:	/etc/default/strlogd
# processname:	strlogd
# pidfile:	/var/run/strlogd.pid
# probe:	true
# hide:		false
# license:	GPL
# description:	This STREAMS init script is part of Linux Fast-STREAMS.  It is \
#		responsible for starting and stopping the STREAMS error \
#		logger.  The STREAMS error logger should only be run under \
#		exceptional circumstances and this init script not activated \
#		automatically.
#
# LSB init script conventions
#
### BEGIN INIT INFO
# Provides: strlogd
# Required-Start: streams
# Required-Stop: streams
# Default-Start: 
# Default-Stop: 0 1 2 3 4 5 6
# X-UnitedLinux-Default-Enabled: no
# Short-Description: start and stop strlogd
# License: GPL
# Description:	This STREAMS init script is part of Linux Fast-STREAMS.  It is
#	responsible for starting and stopping the STREAMS error logger.  The
#	STREAMS error logger should only be run under exceptional circumstances
#	and this init script is not activated in any run level by default.
### END INIT INFO

# Source init script functions library
init_mode="standalone"
  if [ -r /etc/init.d/functions   ] ; then . /etc/init.d/functions   ; init_mode="chkconfig" ;
elif [ -r /etc/rc.status          ] ; then . /etc/rc.status          ; init_mode="insserv"   ;
elif [ -r /lib/lsb/init-functions ] ; then . /lib/lsb/init-functions ; init_mode="lsb"       ;
fi

case "$init_mode" in
    (chkconfig)
	start_daemon() {
	    local force= nicelevel=
	    while [ "$1" != "${1##[-+]}" ] ; do
		case $1 in
		    (-f) force="--force" ; shift 1 ;;
		    (-n) nicelevel="$2"  ; shift 2 ;;
		esac
	    done
	    daemon $force $nicelevel $*
	    RETVAL=$?
	    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$1
	    return $RETVAL
	}
	;;
    (insserv)
	action() {
	    echo -en "$1"
	    shift 1
	    ${1+"$@"} >/dev/null
	    RETVAL=$?
	    [ $RETVAL -eq 0 ] || rc_failed $RETVAL
	    rc_status -v
	    return $RETVAL
	}
	;;
    (lsb)
	action() {
	    echo -en "$1"
	    shift 1
	    ${1+"$@"} >/dev/null
	    RETVAL=$?
	    [ $RETVAL -eq 0 ] && log_success_msg || log_failure_msg
	    return $?
	}
	;;
    (standalone|*)
	start_daemon() {
	    local force= nicecmd=
	    while [ "$1" != "${1##[-+]}" ] ; do
		case $1 in
		    (-f) force="--force"       ; shift 1 ;;
		    (-n) nicecmd="nice -n $2"  ; shift 2 ;;
		esac
	    done
	    ( $* >/dev/null 2>&1 </dev/null & )
	    RETVAL=$?
	    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$1
	    return $RETVAL
	}
	action() {
	    echo -en "$1"
	    shift 1
	    ${1+"$@"} >/dev/null
	    RETVAL=$?
	    [ $RETVAL -eq 0 ] && echo -e "\t...SUCCESS" || echo -e "\t....FAILED"
	    return $?
	}
	if [ -x /sbin/pidof ] ; then
	    pidofproc() {
		/sbin/pidof $@
	    }
	elif [ -x /sbin/pidofproc ] ; then
	    pidofproc() {
		/sbin/pidofproc $@
	    }
	else
	    pidofproc() {
		[ -r $pidfile ] && cat $pidfile
	    }
	fi
	if [ -x /sbin/killproc ] ; then
	    killproc() {
		/sbin/killproc $@
	    }
	elif [ -x /usr/bin/killall ] ; then
	    killproc() {
		/usr/bin/killall $@
	    }
	else
	    killproc() {
		[ -r $pidfile ] && kill "$2" `cat $pidfile`
	    }
	fi
	;;
esac

name='strlogd'
lockfile="/var/lock/subsys/$name"
config="/etc/sysconfig/$name"
processname="$name"
pidfile="/var/run/$processname.pid"
execfile="/usr/sbin/$processname"

if [ ! -x $execfile ] ; then if [ "$1" = "stop" ] ; then exit 0 ; else exit 5 ; fi ; fi

# Disable for the moment

if [ "$1" = "stop" ] ; then exit 0 ; else exit 5 ; fi

# Specify defaults

STRLOGDOPTIONS=
STRLOGD_MAILUID=
STRLOGD_DIRECTORY="/var/log/streams"
STRLOGD_BASENAME="error"
STRLOGD_OUTFILE=
STRLOGD_ERRFILE=
STRLOGD_LOGDEVICE="/dev/streams/log"
STRLOGD_OPTIONS=

# Source redhat and/or debian config file
for file in $config ; do
    [ -f $file ] && . $file
done

RETVAL=0

umask 077

build_options() {
    # Build up the options string
    STRLOGD_OPTIONS=
    [ -n "$STRLOGDOPTIONS" ] && \
	STRLOGD_OPTIONS="${STRLOGD_OPTIONS:+ }${STRLOGDOPTIONS}"
    [ -n "$STRLOGD_MAILUID" ] && \
	STRLOGD_OPTIONS="${STRLOGD_OPTIONS:+ }-a ${STRLOGD_MAILUID}"
    [ -n "$STRLOGD_DIRECTORY" ] && \
	STRLOGD_OPTIONS="${STRLOGD_OPTIONS:+ }-d ${STRLOGD_DIRECTORY}"
    [ -n "$STRLOGD_BASENAME" ] && \
	STRLOGD_OPTIONS="${STRLOGD_OPTIONS:+ }-b ${STRLOGD_BASENAME}"
    [ -n "$STRLOGD_OUTFILE" ] && \
	STRLOGD_OPTIONS="${STRLOGD_OPTIONS:+ }-o ${STRLOGD_OUTFILE}"
    [ -n "$STRLOGD_ERRFILE" ] && \
	STRLOGD_OPTIONS="${STRLOGD_OPTIONS:+ }-e ${STRLOGD_ERRFILE}"
    [ -n "$STRLOGD_LOGDEVICE" ] && \
	STRLOGD_OPTIONS="${STRLOGD_OPTIONS:+ }-l ${STRLOGD_LOGDEVICE}"
}

start() {
    build_options
    start_daemon $processname -p $pidfile $STRLOGD_OPTIONS
    RETVAL=$?
    [ $RETVAL -eq 0 ] && touch $lockfile
    RETVAL=$?
    return $RETVAL
}

stop() {
    killproc $processname
    RETVAL=$?
    [ $RETVAL -eq 0 ] && rm -f -- $lockfile
    RETVAL=$?
    return $RETVAL
}

restart() {
    stop
    start
    return $?
}

reload() {
    echo "Reloading the STREAMS error logger: "
    killproc $processname -HUP
    return $?
}

case "$1" in
    (start|stop|reload|restart)
	$1 || RETVAL=$?
	;;
    (status)
	$1 $name || RETVAL=$?
	;;
    (condrestart)
	[ -f $lockfile ] && restart || RETVAL=$?
	;;
    (probe)
	if pidofproc $processname >/dev/null 2>&1 ; then
	    # running
	    if [ "`pidofproc $processname`" -eq "`cat $pidfile`" ] ; then
		# running with the right pid
		if [ ! -f $lockfile ] ; then
		    # running but subsystem unlocked, need to reload
		    echo 'reload'
		else
		    # subsystem locked
		    for file in $config ; do
			if [ -f $file -a $file -nt $lockfile ] ; then
			    # configuration file updated, need to reload
			    echo 'reload'
			    break
			fi
		    done
		fi
	    else
		# running, but with the wrong pid, need to restart
		echo 'restart'
	    fi
	else
	    # not running
	    if [ ! -f $lockfile ] ; then
		# subsystem unlocked, need to start
		echo 'start'
	    else
		# dead but subsystem locked, need to restart
		echo 'restart'
	    fi
	fi
	# do not need to do anything
	RETVAL=$?
	;;
    (*)
	echo "Usage: $0 (start|stop|status|restart|condrestart|probe)"
	;;
esac

[ "${0##*/}" = "$name" ] && exit $RETVAL

# =============================================================================
# 
# @(#) strlogd,v openss7-0_9_2_F(0.9.2.5) 2006/05/08 03:35:10
#
# -----------------------------------------------------------------------------
#
# Copyright (c) 2001-2006  OpenSS7 Corporation <http://www.openss7.com>
# Copyright (c) 1997-2000  Brian F. G. Bidulock <bidulock@openss7.org>
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 675 Mass
# Ave, Cambridge, MA 02139, USA.
#
# -----------------------------------------------------------------------------
#
# U.S. GOVERNMENT RESTRICTED RIGHTS.  If you are licensing this Software on
# behalf of the U.S. Government ("Government"), the following provisions apply
# to you.  If the Software is supplied by the Department of Defense ("DoD"), it
# is classified as "Commercial Computer Software" under paragraph 252.227-7014
# of the DoD Supplement to the Federal Acquisition Regulations ("DFARS") (or any
# successor regulations) and the Government is acquiring only the license rights
# granted herein (the license rights customarily provided to non-Government
# users).  If the Software is supplied to any unit or agency of the Government
# other than DoD, it is classified as "Restricted Computer Software" and the
# Government's rights in the Software are defined in paragraph 52.227-19 of the
# Federal Acquisition Regulations ("FAR") (or any successor regulations) or, in
# the cases of NASA, in paragraph 18.52.227-86 of the NASA Supplement to the FAR
# (or any successor regulations).
#
# -----------------------------------------------------------------------------
#
# Commercial licensing and support of this software is available from OpenSS7
# Corporation at a fee.  See http://www.openss7.com/
#
# -----------------------------------------------------------------------------
#
# Last Modified 2006/05/08 03:35:10 by brian
#
# =============================================================================

# vim: ft=sh sw=4 tw=80
