#! /bin/sh
### BEGIN INIT INFO
# Provides:          accounting
# Required-Start:    $network $remote_fs $syslog
# Required-Stop:     $network $remote_fs $syslog
# Should-Start:      network-manager
# Should-Stop:       network-manager
# X-Start-Before:    openvpn
# X-Interactive:     true
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Accounting daemon for Openvpn VPN service
# Description: This script will start the accounting script for OpenVPN
### END INIT INFO

PATH=/sbin:/bin

. /lib/lsb/init-functions

case "$1" in
  start)
    /usr/bin/python2 /etc/openvpn/vpn_acct.py -s graphite-dev.illyse.org /var/run/openvpn/acct vpn1
    ;;
  restart|reload|force-reload)
    shift
    $0 stop ${@}
    sleep 1
    $0 start ${@}
    ;;
  stop)
    kill `cat /var/run/vpn_acct.pid`
    rm -f /var/run/vpn_acct.pid
    ;;
  *)
    echo "Usage: $0 start|stop|restart" >&2
    exit 3
    ;;
esac
