#!/bin/sh
#
# gammu-smsd: gammu SMS daemon
#
# chkconfig: - 65 35
# description: gammu SMS daemon
# processname: gammu-smsd
# config: /etc/gammu-smsdrc
# pidfile: /var/run/gammu-smsd.pid

# Source function library.
. /etc/init.d/functions

# Additional environment file
if [ -f /etc/sysconfig/gammu-smsd ]; then
      . /etc/sysconfig/gammu-smsd
fi

RETVAL=0
prog="gammu-smsd"
config="/etc/gammu-smsdrc"
pidfile=${PIDFILE-/var/run/gammu-smsd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/gammu-smsd}

start () {
	echo -n $"Starting $prog: "
	dir=$(dirname ${pidfile})
	[ -d $dir ] || mkdir $dir
	$prog -c $config -p ${pidfile} -d
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch ${lockfile}
}


stop () {
	echo -n $"Stopping $prog: "
	killproc -p ${pidfile} php-fpm
	RETVAL=$?
	echo
	if [ $RETVAL -eq 0 ] ; then
		rm -f ${lockfile} ${pidfile}
	fi
}

restart () {
        stop
        start
}


case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
	status -p ${pidfile} gammu-smsd
	RETVAL=$?
	;;
  restart)
	restart
	;;
  *)
	echo $"Usage: $0 {start|stop|status|restart}"
	RETVAL=2
        ;;
esac

exit $RETVAL
