File smstools3-init of Package smstools3

#!/bin/sh
# This script can be used to start/stop smsd
# as a daemon in Linux, Solaris, Cygwin, FreeBSD
# and MAC OS X Terminal window (Darwin).
# This script is to be used with smsd version >= 3.0.3. 
#
# /etc/init.d/smsd
#   and its symbolic link
# /usr/sbin/rcsmsd
#
### BEGIN INIT INFO
# Provides:          smsd
# Required-Start:    $syslog $remote_fs
# Should-Start:      $time smtp
# Required-Stop:     $syslog $remote_fs
# Should-Stop: $time smtp
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: Start/Stop smsd - a SMS Gateway software
# Description:       Start smsd to send and receive short 
#	messages through GSM modems and mobile phones.
### END INIT INFO

DAEMON="/usr/sbin/smsd"
CONFFILE="/etc/sysconfig/smstools3"

test -x $DAEMON || { echo "$DAEMON not installed";
    if [ "$1" = "stop" ]; then exit 0;
    else exit 5; fi; }

test -r $CONFFILE || { echo "$CONFFILE not existing";
    if [ "$1" = "stop" ]; then exit 0;
    else exit 6; fi; }

# Read config
. $CONFFILE

# If an unpriviledged user is selected, make sure that next two
# files are writable by that user:
PIDFILE="/var/run/smsd/smsd.pid"
PIDDIR=$(dirname $PIDFILE)
INFOFILE="/var/run/smsd/smsd.working"
# Logfile can also be defined in here:
LOGFILE="/var/log/smsd/smsd.log"

# A program which turns power off for couple of seconds:
RESETMODEMS=/usr/sbin/smsd_resetmodems
NAME=smsd

# Shell functions sourced from /etc/rc.status:
. /etc/rc.status

# Reset status of this service
rc_reset

ARGS="-n MAINPROCESS -p${PIDFILE} -i${INFOFILE} -u${SMSD_USER} -g${SMSD_GROUP} ${SMSD_ARGS} -l${LOGFILE}"

case "$1" in
  start)
	echo -n "Starting SMS Daemon: "
	if [ ! -d $(dirname "$PIDFILE") ]; then
		install -d -m 755 -o ${SMSD_USER} -g ${SMSD_GROUP} $(dirname "$PIDFILE")
	fi
	if checkproc $DAEMON ; then
		echo -n "already running"
		rc_failed 7
	else
			if [ -f "${INFOFILE}" ]; then
				rm "${INFOFILE}"
			fi
			if [ -f "${PIDFILE}" ]; then
    	        rm "${PIDFILE}"
	        fi
			# Delete lock files if they exist
			find /var/spool/sms -name '*.LOCK' -exec rm \{\} \;
			# Check and create piddir 
			if [ ! -d "$PIDDIR" ]; then
				install -d -m 755 -u${SMSD_USER} -g${SMSD_GROUP} "$PIDDIR"
			fi
			$DAEMON $ARGS
	fi
	rc_status -v
	;;

  stop)
	echo -n "Shutting down SMS Daemon: "
	if checkproc $DAEMON ; then
		/sbin/killproc -p "$PIDFILE" -TERM $DAEMON 
		if [ -e "$PIDFILE" ]; then
			echo "Warning - SMS Daemon did not exit in a timely manner. Waiting..."
			while [ -e "$PIDFILE" ] && [ $SMSD_MAXWAIT -qt 0 ] ; do
				sleep 1
				SMSD_MAXWAIT=$[SMSD_MAXWAIT-1]
				echo -n '.'
				[ $SMSD_MAXWAIT -eq 41 ] && echo
			done
		fi
		if checkproc $DAEMON ; then
			/sbin/killproc -p "$PIDFILE" -SIGKILL $DAEMON
			echo -n "Warning: SMS Daemon killed"
		fi
	else
		echo -n " SMS Daemon not running"
		rc_failed 7
	fi
    rc_status -v
	;;

  try-restart|condrestart)
    ## Do a restart only if the service was active before.
    if test "$1" = "condrestart"; then
        echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
    fi
    $0 status
    if test $? = 0; then
        $0 restart
    else
        rc_reset    # Not running is not a failure.
    fi
    rc_status
    ;;

  restart|reload)
	$0 stop
	$0 start
    # Remember status and be quiet
    rc_status
	;;

  status)
    echo -n "Checking for SMS Daemon "
    /sbin/checkproc $DAEMON
    rc_status -v
    ;;

  probe)
    test /etc/smsd.conf -nt "$PIDFILE" && echo reload
    ;;

  *)
	echo "Usage: $0 {start|stop|status|try-restart|restart|reload|probe}"
	exit 1
    ;;
esac
rc_exit
openSUSE Build Service is sponsored by