#! /bin/sh
# /etc/init.d/isdnlog: start and stop isdnlog
#
# Written by Christian Schwarz <schwarz@debian.org>.
#

# Set run_isdnlog to 1 to start isdnlog at boot or 0 to disable it.
run_isdnlog=0
# Fill in the ISDN driver id here. When you are using the module driver,
# this is the name you specified with `insmod', for example `teles0'.
# If you are using the kernel built-in driver, this is `line0'.
# Sometimes it's necessary to set this to "", though.
DRIVER=line0

# --end-of-configuration-part--

PATH=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=/usr/sbin/isdnlog
NAME=isdnlog

test -f $DAEMON || exit 0

case "$1" in
  start)
    if [ $run_isdnlog = 1 ]; then
      # Rotate log files, if necessary.
      if [ "`find /var/log/isdn -name isdnctrl -ctime 1`"x = ""x ]; then
        # isdnctrl's log file is older than 1 day, so rotate all logs.
        cd /var/log/isdn
        savelog -g adm -m 640 -u root -c 4 isdnctrl isdnlog >/dev/null
      fi
      echo -n "Starting ISDN logging daemon: isdnlog"
      telesctrl $DRIVER 1 4
      isdnlog -vw2 -m1015 /dev/isdnctrl 2>/var/log/isdn/isdnlog &
      echo "."
    fi
    ;;
  stop)
    if [ $run_isdnlog = 1 ]; then
      start-stop-daemon --stop --verbose --pidfile /var/run/$NAME.pid --exec $DAEMON
    fi
    ;;
  *)
    echo "Usage: /etc/init.d/$NAME {start|stop}"
    exit 1
    ;;
esac

exit 0
