#!/bin/sh
# /etc/init.d/zcip: Start, stop and restart ZeroConf deamon on SliTaz, at boot
# time or with the command line.
#
# To start daemon at boot time, just put the right name in the $RUN_DAEMONS
# variable of /etc/rcS.conf and configure options with /etc/daemons.conf.
#
. /etc/init.d/rc.functions
. /etc/daemons.conf
. /etc/network.conf

NAME=Zcip
DESC="ZeroConf deamon"
DAEMON=/sbin/zcip
OPTIONS=$ZCIP_OPTIONS
PIDFILE=/var/run/zcip.pid
[ -n "$OPTIONS" ] || OPTIONS="$INTERFACE /etc/zcip.script"

case "$1" in
  start)
    if active_pidfile $PIDFILE zcip ; then
      echo "$NAME already running."
      exit 1
    fi
    echo -n "Starting $DESC: $NAME... "
    $DAEMON $OPTIONS && echo `pidof $DAEMON` > $PIDFILE
    status
    ;;
  stop)
    if ! active_pidfile $PIDFILE zcip ; then
      echo "$NAME is not running."
      exit 1
    fi
    echo -n "Stopping $DESC: $NAME... "
    kill `cat $PIDFILE`
    rm $PIDFILE
    status
    ;;
  restart)
    if ! active_pidfile $PIDFILE zcip ; then
      echo "$NAME is not running."
      exit 1
    fi
    echo -n "Restarting $DESC: $NAME... "
    kill `cat $PIDFILE`
    rm $PIDFILE
    sleep 2
    $DAEMON $OPTIONS
    status
    ;;
  *)
    echo ""
    echo -e "\033[1mUsage:\033[0m /etc/init.d/`basename $0` [start|stop|restart]"
    echo ""
    exit 1
    ;;
esac

exit 0
