#!/bin/bash
#
# ser2net	Start/Stop the ser2net daemon.
#
# chkconfig:	2345 52 48
# description:	Program for allowing network connections to serial ports
# processname:	ser2net
# config:	/etc/ser2net.conf
# pid:		/var/run/ser2net.pid
#
### BEGIN INIT INFO
# Provides:		ser2net
# Default-Stop:		
# Required-Start:	$network
# Required-Stop:	$network
# Short-Description:	Init script for ser2net daemon.
# Description:		This is ser2net, a program for allowing network connections to serial
#			ports.  See the man page for information about using the program.
### END INIT INFO


BIN=ser2net
CONFIG=/etc/$BIN.conf
LOCKFILE=/var/lock/subsys/$BIN
PID=/var/run/$BIN.pid

test -x /usr/sbin/$BIN || { gprintf "%s not installed\n" "$BIN"; }
test -r $CONFIG || { gprintf "%s not existing\n" "$CONFIG"; }

. /etc/rc.d/init.d/functions

start() {
        gprintf "Starting %s: " "$BIN"
        RETVAL=1
        daemon $BIN -c $CONFIG -P $PID
        RETVAL=$?
        [ $RETVAL -eq 0 ] && touch $LOCKFILE
        echo
        return $RETVAL
}

stop() {
        gprintf "Shutting down %s: " "$BIN"
        killproc $BIN
        RETVAL=$?
        [ $RETVAL -eq 0 ] && touch $LOCKFILE
        echo
        return $RETVAL
}

restart() {
        stop
        start
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        restart
        ;;
  reload)
	gprintf "Reload service %s " "$BIN"
	killproc -HUP $BIN
	RETVAL=$?
	status $BIN
	RETVAL=$?
	;;
  condrestart)
        [ -f $LOCKFILE ] && restart || :
        ;;
  status)
        status $BIN
        RETVAL=$?
        ;;
  *)
        gprintf "Usage: %s {start|stop|restart|reload|condrestart|status}\n" "$BIN"
        RETVAL=1
esac

exit $RETVAL
