Blob Blame History Raw
#!/bin/sh
#
# ez-ipupdate     Starts and stops the ez-ipupdate daemon
#
# chkconfig: - 55 45
#
# processname: ez-ipupdate
# description: Check and update your IP to dynamic DNS Server.

ez_configdir=/etc/ez-ipupdate
ez_piddir=/var/run/ez-ipupdate
ez_bin=/usr/sbin/ez-ipupdate

# Make sure relevant files exist
[ -x "$ez_bin" -a -d "$ez_configdir" ] || exit 0

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

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

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

RETVAL=0
prog=ez-ipupdate

start() {
    # Start daemons.
    for ez_configfile in ${ez_configdir}/*.conf; do
	if [ -r ${ez_configfile} ]; then
	    # Don't run configurations that are not daemons
	    if ! grep -q '^ *daemon' ${ez_configfile}; then continue; fi
	    # Don't run configurations that run in foreground
	    if grep -q '^ *foreground' ${ez_configfile}; then continue; fi
	    ez_name=`basename $ez_configfile .conf`
	    echo -n $"Starting $prog for $ez_name: "
	    daemon $ez_bin --daemon --config-file $ez_configfile --pid-file $ez_piddir/$ez_name.pid
	    error=$?
	    echo
	    [ $error -eq 0 ] && touch /var/lock/subsys/$prog-$ez_name
	    [ $RETVAL -eq 0 ] && RETVAL=$error
	fi
    done
}

stop() {
    # Stop daemons.
    for pidfile in ${ez_piddir}/*.pid; do
	if [ -r ${pidfile} ]; then
	    ez_name=`basename $pidfile .pid`
	    echo -n $"Shutting down $prog for $ez_name: "
	    killproc -p $pidfile $prog -QUIT
	    error=$?
	    echo
    	    [ $error -eq 0 ] && rm -f /var/lock/subsys/$prog-$ez_name && rm -f $ez_piddir/$ez_name
	    [ $RETVAL -eq 0 ] && RETVAL=$error
	fi
    done
}

reload() {
    # Reload config by sending a SIGHUP.
    for pidfile in ${ez_piddir}/*.pid; do
	if [ -r ${pidfile} ]; then
	    ez_name=`basename $pidfile .pid`
	    echo -n $"Reloading $prog for $ez_name: "
	    killproc -p $pidfile $prog -HUP
	    error=$?
	    [ $RETVAL -eq 0 ] && RETVAL=$error
	    echo
	fi
    done
}

restart() {
    stop
    start
    RETVAL=$?
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    restart
    ;;
  reload|force-reload)
    reload
    ;;
  condrestart|try-restart)
    ls /var/lock/subsys/$prog-* 1>/dev/null 2>&1 && restart
    ;;
  status)
    status $prog
    RETVAL=$?
    for ez_config in $ez_configdir/*.conf; do
	if [ -r $ez_config ]; then
	    ez_cache=`grep -E '^[[:space:]]*cache-file' $ez_config | cut -d "=" -f2`
	    ez_host=`grep -E '^[[:space:]]*host' $ez_config | cut -d "=" -f2`
	    ez_iface=`grep -E '^[[:space:]]*interface' $ez_config | cut -d "=" -f2`
	    [ -n "$ez_cache" ] && \
	    echo "Last IP update of $ez_host on $ez_iface: "`cat $ez_cache | cut -d "," -f2`
	fi
    done
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|condrestart|reload|status}"
    exit 1
esac

exit $RETVAL