#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions
. /etc/conf.d/${0##*/}

DAEMON=/usr/share/backuppc/bin/BackupPC

PIDFILE=${PIDFILE:-/var/log/backuppc/BackupPC.pid}
DAEMON_OPTS=${DAEMON_OPTS:--d}
DAEMON_USER=${DAEMON_USER:-backuppc}
DAEMON_GROUP=${DAEMON_GROUP:-nobody}

case "$1" in
  start)
    stat_busy "Starting ${0##*/} daemon"
    if start-stop-daemon --start --quiet --pidfile "$PIDFILE" \
      -c $DAEMON_USER -g $DAEMON_GROUP --startas $DAEMON -- \
      $DAEMON_OPTS; then
        stat_done
        add_daemon ${0##*/}
        exit 0
    else
        stat_fail
        exit 1
    fi
  ;;
  stop)
    stat_busy "Stopping ${0##*/} daemon"
    if start-stop-daemon --stop --quiet --pidfile "$PIDFILE"; then
      rm_daemon ${0##*/}
      rm "$PIDFILE"
      stat_done
      exit 0
    else
      stat_fail
      exit 1
    fi
  ;;
  reload)
    stat_busy "Reloading ${0##*/} dameon"
    start-stop-daemon --stop --signal HUP --quiet --pidfile "$PIDFILE" \
      && { stat_done; exit 0; } || { stat_fail; exit 1; }
  ;;
  restart)
    $0 stop && sleep 2
    $0 start
  ;;
  *)
    echo "usage: ${0##*/} {start|stop|restart}" >&2
  ;;
esac

# vim:set ts=2 sw=2 ft=sh et:
