~ubuntu-branches/ubuntu/lucid/g15daemon/lucid

« back to all changes in this revision

Viewing changes to debian/g15daemon.init

  • Committer: Bazaar Package Importer
  • Author(s): Giacomo Catenazzi
  • Date: 2009-08-13 08:20:02 UTC
  • Revision ID: james.westby@ubuntu.com-20090813082002-deu8imgmi6l5oiov
Tags: 1.9.5.3-5
* Handle keyboard device with udev, so detecting detachement
  and attachment of keyboarda (Closes: #489978).
* init.d LSB header: try to start before xorg, to be able
  to have full access to all extra keys.
* Recent libg15 corrected strange behaviour in new G15 keyboard
  (Closes: #494180)

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
# Required-Stop:     $local_fs
7
7
# Should-Start:      $remote_fs
8
8
# Should-Stop:       $remote_fs
 
9
# X-Start-Before:    xdm kdm gdm ldm sdm
9
10
# Default-Start:     2 3 4 5
10
11
# Default-Stop:      0 1 6
11
12
# Short-Description: load deamon for Logitech G15 keyboard lcd display
18
19
NAME=g15daemon
19
20
DESC=g15daemon
20
21
 
21
 
test -x $DAEMON || exit 0
 
22
[ -x "$DAEMON" ] || exit 0
22
23
 
23
24
# Include g15daemon defaults if available
24
25
if [ -f /etc/default/g15daemon ] ; then
32
33
set -e
33
34
 
34
35
 
35
 
load_uinput () {
36
 
    DEVICE=/dev/input/uinput
37
 
    DEV=".none."
38
 
    if [ ! -e "$DEVICE" ] ; then
39
 
        modprobe -q uinput || true
40
 
        for i in `seq 80`; do
41
 
            if [ -e "$DEVICE" ]; then
42
 
                DEV="$DEVICE"
43
 
                break
44
 
            fi
45
 
            echo -n "."
46
 
            sleep 0.1
 
36
wait_for_file() {
 
37
        local file=$1
 
38
        local timeout=$2
 
39
        [ "$timeout" ] || timeout=120
 
40
 
 
41
        local count=$(($timeout * 10))
 
42
        while [ $count != 0 ]; do
 
43
                [ -e "$file" ] && return 0
 
44
                sleep 0.1
 
45
                count=$(($count - 1))
47
46
        done
48
 
        if [ "$DEV" = ".none." ]; then
49
 
            echo -n "Warning: uinput ($DEVICE) doesn't exist. The G-keys are unsupported..."
50
 
        fi
51
 
    fi
 
47
        return 1
 
48
}
 
49
 
 
50
load_uinput() {
 
51
    if [ ! -e /dev/input/uinput ] ; then
 
52
        modprobe -q uinput || true
 
53
        wait_for_file /dev/input/uinput 3  ||  return 1
 
54
    fi
 
55
}
 
56
 
 
57
wait_usr_mount() {
 
58
    if [ ! -e "$DAEMON" ] ; then
 
59
        wait_for_file "$DAEMON" 7  ||  return 1
 
60
    fi
 
61
}
 
62
 
 
63
is_running() {
 
64
        start-stop-daemon --stop --test --quiet --pidfile \
 
65
                /var/run/$NAME.pid --exec $DAEMON 
 
66
}
 
67
 
 
68
do_start() {
 
69
        start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
 
70
                --exec $DAEMON -- $DAEMON_OPTS
 
71
}
 
72
 
 
73
do_stop() {
 
74
        $DAEMON -k
 
75
        start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
 
76
                --oknodo --retry 5 --exec $DAEMON
52
77
}
53
78
 
54
79
 
55
80
case "$1" in
56
81
  start)
57
82
        echo -n "Starting $DESC: "
58
 
        load_uinput
59
 
        start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
60
 
                --exec $DAEMON -- $DAEMON_OPTS
 
83
        load_uinput || echo -n ".../dev/input/uinput not found ..."
 
84
        do_start
61
85
        echo "$NAME."
62
86
        ;;
63
87
  stop)
64
88
        echo -n "Stopping $DESC: "
65
 
        $DAEMON -k
66
 
        start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
67
 
                --oknodo --retry 5 --exec $DAEMON
 
89
        do_stop
68
90
        echo "$NAME."
69
91
        ;;
70
92
  #reload)
78
100
        # echo "Reloading $DESC configuration files."
79
101
        # start-stop-daemon --stop --signal 1 --quiet --pidfile \
80
102
        #       /var/run/$NAME.pid --exec $DAEMON
81
 
  #;;
 
103
        #;;
82
104
  force-reload)
83
105
        #
84
106
        #       If the "reload" option is implemented, move the "force-reload"
86
108
        #       just the same as "restart" except that it does nothing if the
87
109
        #   daemon isn't already running.
88
110
        # check wether $DAEMON is running. If so, restart
89
 
        start-stop-daemon --stop --test --quiet --pidfile \
90
 
                /var/run/$NAME.pid --exec $DAEMON \
91
 
        && $0 restart \
92
 
        || exit 0
93
 
        ;;
 
111
        is_running  &&  $0 restart  ||  exit 0
 
112
        ;;
94
113
  restart)
95
114
    echo -n "Restarting $DESC: "
96
 
        start-stop-daemon --stop --quiet --pidfile \
97
 
                /var/run/$NAME.pid --exec $DAEMON
98
 
        sleep 1
99
 
        start-stop-daemon --start --quiet --pidfile \
100
 
                /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
 
115
        do_stop
 
116
        # the device is slow to shut-down
 
117
        sleep 0.5
 
118
        do_start
101
119
        echo "$NAME."
102
120
        ;;
 
121
  udev)
 
122
        if [ "x$ACTION" = "xadd" ] ; then
 
123
            load_uinput || true
 
124
            wait_usr_mount || true
 
125
            # it seems udev will not release a device if userspace is still
 
126
            # connected
 
127
            is_running && ( do_stop; sleep 0.5 )
 
128
            do_start
 
129
        elif [ "x$ACTION" = "xremove" ] ; then
 
130
            do_stop
 
131
        else
 
132
            echo "unknow udev action '$ACTION'"
 
133
            exit 1
 
134
 
 
135
        fi
 
136
        ;;
103
137
  *)
104
138
        N=/etc/init.d/$NAME
105
 
        # echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
106
 
        echo "Usage: $N {start|stop|restart|force-reload}" >&2
 
139
        echo "Usage: $N {start|stop|restart|force-reload|udev}" >&2
107
140
        exit 1
108
141
        ;;
109
142
esac