#!/bin/sh
#
### BEGIN INIT INFO
# Provides: netplugd
# Short-Description: start and stop network plug daemon
# Description: netplugd is a daemon for managing non-static network
#              interfaces.
### END INIT INFO
#
# netplugd     This shell script takes care of starting and stopping
#              the network plug management daemon.
#
# chkconfig: - 11 89
# description: netplugd is a daemon for managing non-static network \
#              interfaces.
# processname: netplugd
# pidfile: /var/run/netplugd.pid

# Copyright 2003 Key Research, Inc.

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

# Source networking configuration.
. /etc/sysconfig/network

[ -f /etc/sysconfig/netplugd ] && . /etc/sysconfig/netplugd


prog=netplugd
exec=/sbin/netplugd
config=/etc/netplug.d/netplugd.conf
lockfile=/var/lock/subsys/netplugd
pidfile=/var/run/netplugd.pid

check() {
	# Check that we're a privileged user
	[ `id -u` = 0 ] || exit 4
	
	# Check if netplugd is executable
	[ -x $exec ] || exit 5
}

start () {
        check

	[ ${NETWORKING} = "no" ] && exit 1
	[ -f $config ] || exit 6

	echo -n $"Starting $prog: "
	daemon $exec ${NETPLUGDARGS} -p $pidfile
	RETVAL=$?
	echo

	[ $RETVAL -eq 0 ] && touch $lockfile
	return $RETVAL
}

stop () {
        check

	echo -n $"Shutting down $prog: "
	killproc $prog
	RETVAL=$?
	echo

	[ $RETVAL -eq 0 ] && rm -f $lockfile
	return $RETVAL
}

restart() {
	stop
	start
}

rh_status() {
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

if [ $# -gt 1 ]; then
    exit 2
fi

case "$1" in
  start)
	rh_status_q && exit 0
	start
	;;
  stop)
	rh_status_q || exit 0
	stop
	;;
  restart|force-reload)
	restart
	;;
  reload)
        rh_status_q || exit 7
        restart
        ;;
  condrestart|try-restart)
	rh_status_q || exit 0
	restart
	;;
  status)
	rh_status
	;;
  *)
	echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
	exit 2
	;;
esac

exit $?
