updated on Wed Jan 11 20:01:35 UTC 2012
[aur-mirror.git] / bumblebee-git / bumblebeed.in
blobb7a67a00b9e6749ba885ab65e0a572204904f7d9
1 #!/bin/bash
2 # Bumblebee daemon handler script. Distro-independent script to start/stop
3 # daemon. Should be runnable in any distro but won't give any feedback.
5 . /etc/rc.d/functions
6 . /etc/rc.conf
8 NAME=bumblebeed
9 BIN='/usr/bin/bumblebeed'
10 PIDFILE=/var/run/$NAME.pid
12 # returns 0 if running, non-zero otherwise
13 status() {
14 local pid
15 # program is not running
16 [ -s "$PIDFILE" ] || return 3
18 pid="$(cat "$PIDFILE" 2>/dev/null)"
20 # process is not running, pid file not properly cleared
21 kill -0 "$pid" 2>/dev/null || return 1
23 # process is running
24 return 0
27 start() {
28 # program is not installed
29 [ -x "$BIN" ] || return 5
31 # return if already started
32 status && return 0 || true
33 "$BIN" --daemon 2>/dev/null
34 status && return 0 || return 1
37 stop() {
38 local retries=10
39 local pid="$(cat "$PIDFILE" 2>/dev/null)"
41 # not running, we're done
42 status || return 0
44 # first ask the daemon nicely to quit
45 kill "$pid" || true
46 # and check whether it listened
47 while [ $retries -gt 0 ]; do
48 retries=$((retries - 1))
50 # process has gone, return success
51 status || return 0
52 # wait for half a minut before polling again
53 sleep .5
54 done
55 # failed to stop or timeout
56 return 1
59 restart() {
60 stop && start
63 case "$1" in
64 start)
65 stat_busy "Starting Bumblebee"
66 if start; then
67 stat_done
68 add_daemon $NAME
69 else
70 stat_fail
73 stop)
74 stat_busy "Stopping Bumblebee"
75 if stop; then
76 stat_done
77 rm_daemon $NAME
78 else
79 stat_fail
82 restart)
83 stat_busy "Stopping Bumblebee"
84 if stop; then
85 stat_done
86 rm_daemon $NAME
87 else
88 stat_fail
90 sleep 1
91 stat_busy "Starting Bumblebee"
92 if start; then
93 stat_done
94 add_daemon $NAME
95 else
96 stat_fail
100 echo "Usage: $0 {start|stop|restart|status}"
101 exit 1
103 esac