updated on Sun Jan 22 20:01:29 UTC 2012
[aur-mirror.git] / badvpn / badvpn-ncd.rc.d
blob83e6ee3a15e64cefe23e6a36fd892821bc591c50
1 #!/bin/bash
3 SVCNAME=badvpn-ncd
5 . /etc/rc.conf
6 . /etc/rc.d/functions
7 . /etc/conf.d/${SVCNAME}
9 NCD_PIDFILE="/var/run/${SVCNAME}.pid"
10 NCD_NAME=${NCD_NAME:-"Network Configuration Daemon"}
11 NCD_SYSLOG_IDENT=${NCD_SYSLOG_IDENT:-"ncd"}
12 NCD_EXEC="/usr/bin/badvpn-ncd"
14 PID=
15 if [[ -e ${NCD_PIDFILE} ]]; then
16 PID=$(cat "${NCD_PIDFILE}" 2>/dev/null)
17 if ! [[ $( readlink /proc/$PID/exe 2>/dev/null ) =~ ^${NCD_EXEC}(" (deleted)")?$ ]]; then
18 PID=
19 rm "${NCD_PIDFILE}" 2>/dev/null
23 case $1 in
24 start)
25 if ! [[ -e ${NCD_CONFIG} ]]; then
26 echo "Error: configuration file (${NCD_CONFIG}) missing"
27 exit 1
30 stat_busy "Starting ${NCD_NAME}"
32 args=( "${NCD_ARGS[@]}" --config-file "${NCD_CONFIG}" )
33 if [[ -n ${NCD_SYSLOG_IDENT} ]]; then
34 args=( "${args[@]}" --logger syslog --syslog-ident "${NCD_SYSLOG_IDENT}" )
37 res=0
38 if [[ -z ${PID} ]]; then
40 cd / &&
41 exec "${NCD_EXEC}" "${args[@]}"
42 ) 1>/dev/null 2>&1 &
43 res=$?
44 [[ ${res} -eq 0 ]] && echo "$!" > "${NCD_PIDFILE}"
46 if [[ ${res} -eq 0 ]]; then
47 add_daemon ${SVCNAME}
48 stat_done
49 else
50 stat_fail
51 exit 1
55 stop)
56 stat_busy "Stopping ${NCD_NAME}"
57 if [[ ! -z $PID ]] && kill "${PID}" &>/dev/null; then
58 while kill -0 "${PID}" &>/dev/null; do sleep 0.01; done
59 rm "${NCD_PIDFILE}"
60 rm_daemon ${SVCNAME}
61 stat_done
62 else
63 stat_fail
64 exit 1
68 restart)
69 $0 stop
70 $0 start
74 echo "Usage: $0 {start|stop|restart}" >&2
75 exit 1
77 esac