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.
### BEGIN INIT INFO
# Short-Description: Check and update your IP to dynamic DNS Server
# Provides: ez-ipupdate
# Required-Start: $local_fs $network
# Required-Stop: $local_fs
# Should-Start: $time
### END INIT INFO

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`
	    if [ -f $ez_piddir/$ez_name.pid ]; then
		if status -p $ez_piddir/$ez_name.pid; then
		    continue
		fi
	    fi	
	    echo -n $"Starting $prog for $ez_name: "
	    daemon $ez_bin --daemon --config-file $ez_configfile --pid-file $ez_piddir/$ez_name.pid
	    [ $? -ne 0 ] && RETVAL=1
	    echo
	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
    	    [ $? -ne 0 ] && RETVAL=1
	    echo
	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
	    [ $? -ne 0 ] && RETVAL=1
	    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 ${ez_piddir}/*.pid >/dev/null && 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