updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / pump / pump.rc
blob39f3b08af74f87d47d7e109152068d65ebd1173a
1 #!/bin/bash
3 daemon_name="pump"
5 . /etc/rc.conf
6 . /etc/rc.d/functions
7 . /etc/conf.d/$daemon_name
9 get_pid() {
10 _pid=$(pidof -o %PPID $daemon_name)
11 if [[ -n $_pid ]]; then
12 echo $_pid
13 return 0
14 else
15 echo
16 return 1
20 initvars() {
21 if [[ -n $NOHOSTNAME ]]; then
22 [[ -n $HOSTNAME ]] && unset HOSTNAME
23 else
24 if [[ -n $HOSTNAME ]]; then
25 HOSTNAME="-h ${HOSTNAME}"
26 else
27 HOSTNAME="-h $(hostname)"
31 if [[ -n $INTERFACE ]]; then
32 INTERFACE="-i ${INTERFACE}"
33 else
34 INTERFACE="-i eth0"
36 [[ -n $CONFIG ]] && CONFIG="-c $CONFIG"
37 [[ -n $NODNS ]] && NODNS="-d"
38 [[ -n $NOGW ]] && NOGW="--no-gateway"
39 [[ -n $NOBOOTP ]] && NOBOOTP="--no-bootp"
40 [[ -n $WINCI ]] && WINCI="--win-client-ident"
42 if [[ -n $LEASEHOURS && -n $LEASESECS ]]; then
43 stat_append "Error: LEASEHOURS and LEASESECS should not both be set in /etc/conf.d/$daemon_name.conf"
44 stat_fail
45 elif [[ -z $LEASEHOURS && -z $LEASESECS ]]; then
46 # default to one hour
47 LEASESECS="-L 3600"
48 elif [[ -n $LEASEHOURS && -z $LEASESECS ]]; then
49 LEASESECS="-L $((LEASEHOURS*3600))"
50 elif [[ -z $LEASEHOURS && -n $LEASESECS ]]; then
51 LEASESECS="-L $LEASESECS"
55 initvars
56 case "$1" in
57 start)
58 stat_busy "Starting $daemon_name daemon"
60 PID=$(get_pid)
61 if [[ -z $PID ]]; then
62 [[ -f /var/run/$daemon_name.pid ]] &&
63 rm -f /var/run/$daemon_name.pid
65 $daemon_name ${CONFIG} ${HOSTNAME} ${INTERFACE} ${LEASESECS} ${NODNS} ${NOGW} ${NOBOOTP} ${WINCI}
67 if [[ $? -gt 0 ]]; then
68 stat_fail
69 exit 1
70 else
71 echo $PID > /var/run/$daemon_name.pid
72 add_daemon $daemon_name
73 stat_done
75 else
76 stat_fail
77 exit 1
81 stop)
82 stat_busy "Stopping $daemon_name daemon"
83 PID=$(get_pid)
84 # KILL
85 if [[ -n $PID ]]; then
86 $daemon_name ${INTERFACE} -k &>/dev/null
87 if [[ $? -gt 0 ]]; then
88 stat_die
89 else
90 [[ -e /var/run/$daemon_name.pid ]] && rm -f /var/run/$daemon_name.pid &> /dev/null
91 rm_daemon $daemon_name
92 stat_done
94 else
95 stat_fail
99 restart)
100 $0 stop
101 sleep 3
102 $0 start
105 renew|reload)
106 if get_pid &>/dev/null; then
107 stat_busy "Reloading $daemon_name"
108 $daemon_name -R
109 [[ $? == 0 ]] && stat_done || stat_fail
110 else
111 echo "pump does not seem to be running." >&2
115 status)
116 # ck_status $daemon_name
117 if get_pid &>/dev/null; then
118 $daemon_name -s
119 else
120 echo "pump does not seem to be running." >&2
121 exit 1
123 #stat_done
127 echo "usage: $0 {start|stop|restart|renew|status}"
128 esac
130 exit 0
132 # vim:set ts=2 sw=2 et ft=sh: