updated on Wed Jan 11 16:09:51 UTC 2012
[aur-mirror.git] / bumblebee-git / bumblebee.handler.archlinux
blob088dd7bd74990a02b4b1c20cd5bece74e2956915
1 #!/bin/bash
3 # Bumblebee daemon handler script. ArchLinux script to start/stop daemon.
4 . /etc/rc.conf
5 . /etc/rc.d/functions
7 NAME=bumblebee
8 BIN="$(which $NAME)"
9 PIDFILE=/var/run/$NAME.pid
11 start() {
12 # Start the daemon only if there is not another instance running
13 stat_busy "Starting Bumblebee"
14 "$BIN" --status >/dev/null
15 case $? in
16 0) ;; # already running
17 1) ;; # already running and X is available
18 3) ;; # already running, but X server cannot be started
19 2) # Can be started
20 "$BIN" -d >/dev/null 2>&1 &
21 add_daemon $NAME
22 stat_done
23 return
25 esac
26 stat_fail
29 stop() {
30 # Stop the daemon only if there is an instance running
31 stat_busy "Stopping Bumblebee"
32 "$BIN" --status >/dev/null
33 case $? in
34 0|1|3) # Alive and running
35 local pid=$(cat $PIDFILE)
36 kill -TERM $pid >/dev/null
37 # give it time to end gracefully...
38 local retries=10
39 while [ $retries -gt 0 ]; do
40 retries=$(expr $retries - 1)
41 "$BIN" --status >/dev/null
42 case $? in
43 0|1|3) # not ready
44 sleep .5
46 *) # no need for polling anymore
47 break
49 esac
50 done
51 # ... otherwhise just terminate it.
52 "$BIN" --status >/dev/null
53 case $? in
54 0|1|3) # still alive > Kill
55 kill -KILL $pid >/dev/null
59 esac
60 rm_daemon $NAME
61 stat_done
63 2) # Not started
64 stat_fail
66 esac
69 restart() {
70 stop
71 sleep 1
72 start
75 case "$1" in
76 start)
77 start
79 stop)
80 stop
82 restart)
83 restart
85 status)
86 # not implemented
89 echo "Usage: $0 {start|stop|restart}"
90 exit 1
92 esac