~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to vivid/etc/init.d/g15daemon

  • Committer: Dimitri John Ledkov
  • Date: 2014-11-19 12:58:41 UTC
  • Revision ID: dimitri.j.ledkov@intel.com-20141119125841-98dr37roy8dvcv3b
auto update

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh
 
2
 
 
3
### BEGIN INIT INFO
 
4
# Provides:          g15daemon
 
5
# Required-Start:    $syslog $local_fs
 
6
# Required-Stop:     $syslog $local_fs
 
7
# Should-Start:      $remote_fs
 
8
# Should-Stop:       $remote_fs
 
9
# X-Start-Before:    xdm kdm gdm ldm sdm
 
10
# Default-Start:     2 3 4 5
 
11
# Default-Stop:      0 1 6
 
12
# Short-Description: load deamon for Logitech G15 keyboard lcd display
 
13
# Description:       load deamon for Logitech G15 keyboard lcd display
 
14
### END INIT INFO
 
15
 
 
16
 
 
17
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 
18
DAEMON=/usr/sbin/g15daemon
 
19
NAME=g15daemon
 
20
DESC=g15daemon
 
21
 
 
22
[ -x "$DAEMON" ] || exit 0
 
23
 
 
24
# Include g15daemon defaults if available
 
25
if [ -f /etc/default/g15daemon ] ; then
 
26
        . /etc/default/g15daemon
 
27
fi
 
28
 
 
29
if [ "$SWITCH_KEY" = "MR" ]; then
 
30
        DAEMON_OPTS="-s $DAEMON_OPTS"
 
31
fi
 
32
 
 
33
set -e
 
34
 
 
35
if [ "$G15DEBUG" = "on" ]; then
 
36
 
 
37
log() {
 
38
    logger -p daemon.debug -t g15 -- "$*"
 
39
}
 
40
else
 
41
 
 
42
log() {
 
43
    true
 
44
}
 
45
 
 
46
fi
 
47
 
 
48
 
 
49
 
 
50
 
 
51
wait_for_file() {
 
52
        local file=$1
 
53
        local timeout=$2
 
54
        [ "$timeout" ] || timeout=120
 
55
 
 
56
        local count=$(($timeout * 10))
 
57
        while [ $count != 0 ]; do
 
58
                [ -e "$file" ] && return 0
 
59
                sleep 0.1
 
60
                count=$(($count - 1))
 
61
        done
 
62
        return 1
 
63
}
 
64
 
 
65
load_uinput() {
 
66
    if [ ! -e /dev/input/uinput ] ; then
 
67
        modprobe -q uinput || true
 
68
        wait_for_file /dev/input/uinput 3  ||  return 1
 
69
    fi
 
70
}
 
71
 
 
72
wait_usr_mount() {
 
73
    if [ ! -e "$DAEMON" ] ; then
 
74
        wait_for_file "$DAEMON" 7  ||  return 1
 
75
    fi
 
76
}
 
77
 
 
78
is_running() {
 
79
        start-stop-daemon --stop --test --quiet --pidfile \
 
80
                /var/run/$NAME.pid --exec $DAEMON 
 
81
}
 
82
 
 
83
do_start() {
 
84
        start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
 
85
                --exec $DAEMON -- $DAEMON_OPTS
 
86
}
 
87
 
 
88
do_stop() {
 
89
        $DAEMON -k
 
90
        start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
 
91
                --oknodo --retry 5 --exec $DAEMON
 
92
}
 
93
 
 
94
 
 
95
case "$1" in
 
96
  start)
 
97
        echo -n "Starting $DESC: "
 
98
        load_uinput || echo -n ".../dev/input/uinput not found ..."
 
99
        do_start
 
100
        echo "$NAME."
 
101
        ;;
 
102
  stop)
 
103
        echo -n "Stopping $DESC: "
 
104
        do_stop
 
105
        echo "$NAME."
 
106
        ;;
 
107
  #reload)
 
108
        #
 
109
        #       If the daemon can reload its config files on the fly
 
110
        #       for example by sending it SIGHUP, do it here.
 
111
        #
 
112
        #       If the daemon responds to changes in its config file
 
113
        #       directly anyway, make this a do-nothing entry.
 
114
        #
 
115
        # echo "Reloading $DESC configuration files."
 
116
        # start-stop-daemon --stop --signal 1 --quiet --pidfile \
 
117
        #       /var/run/$NAME.pid --exec $DAEMON
 
118
        #;;
 
119
  force-reload)
 
120
        #
 
121
        #       If the "reload" option is implemented, move the "force-reload"
 
122
        #       option to the "reload" entry above. If not, "force-reload" is
 
123
        #       just the same as "restart" except that it does nothing if the
 
124
        #   daemon isn't already running.
 
125
        # check wether $DAEMON is running. If so, restart
 
126
        is_running  &&  $0 restart  ||  exit 0
 
127
        ;;
 
128
  restart)
 
129
    echo -n "Restarting $DESC: "
 
130
        do_stop
 
131
        # the device is slow to shut-down
 
132
        sleep 1
 
133
        do_start
 
134
        echo "$NAME."
 
135
        ;;
 
136
  udev)
 
137
        log "calling g15 udev; action: $ACTION, product $PRODUCT"
 
138
        if [ "x$ACTION" = "xadd" ] ; then
 
139
            load_uinput || true
 
140
            wait_usr_mount || true
 
141
            # it seems udev will not release a device if userspace is still
 
142
            # connected
 
143
            is_running && ( do_stop; sleep 1 )
 
144
            do_start
 
145
        elif [ "x$ACTION" = "xremove" ] ; then
 
146
            do_stop
 
147
        else
 
148
            echo "unknow udev action '$ACTION'"
 
149
            exit 1
 
150
 
 
151
        fi
 
152
        ;;
 
153
  shared-udev)
 
154
        # some devices share usb also for audio, which causes some spourios
 
155
        # udev messages.
 
156
        log "calling g15 shared-dev; action: $ACTION, product $PRODUCT"
 
157
        if [ "x$ACTION" = "xadd" ] ; then
 
158
            load_uinput || true
 
159
            wait_usr_mount || true
 
160
            do_start
 
161
        elif [ "x$ACTION" = "xremove" ] ; then
 
162
            do_stop
 
163
        else
 
164
            echo "unknow udev action '$ACTION'"
 
165
            exit 1
 
166
 
 
167
        fi
 
168
        ;;
 
169
 
 
170
  *)
 
171
        N=/etc/init.d/$NAME
 
172
        echo "Usage: $N {start|stop|restart|force-reload|udev}" >&2
 
173
        exit 1
 
174
        ;;
 
175
esac
 
176
 
 
177
exit 0