Files
g15daemon/debian/g15daemon.init
T

144 lines
3.2 KiB
Bash
Raw Normal View History

2007-08-28 20:09:54 +02:00
#! /bin/sh
### BEGIN INIT INFO
# Provides: g15daemon
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Should-Start: $remote_fs
# Should-Stop: $remote_fs
2009-08-13 08:20:02 +02:00
# X-Start-Before: xdm kdm gdm ldm sdm
2007-08-28 20:09:54 +02:00
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: load deamon for Logitech G15 keyboard lcd display
# Description: load deamon for Logitech G15 keyboard lcd display
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/g15daemon
NAME=g15daemon
DESC=g15daemon
2009-08-13 08:20:02 +02:00
[ -x "$DAEMON" ] || exit 0
2007-08-28 20:09:54 +02:00
# Include g15daemon defaults if available
if [ -f /etc/default/g15daemon ] ; then
. /etc/default/g15daemon
fi
2008-01-28 09:12:16 +01:00
if [ "$SWITCH_KEY" = "MR" ]; then
2007-08-30 23:31:18 +02:00
DAEMON_OPTS="-s $DAEMON_OPTS"
fi
2007-08-28 20:09:54 +02:00
set -e
2009-08-06 08:32:33 +02:00
2009-08-13 08:20:02 +02:00
wait_for_file() {
local file=$1
local timeout=$2
[ "$timeout" ] || timeout=120
local count=$(($timeout * 10))
while [ $count != 0 ]; do
[ -e "$file" ] && return 0
sleep 0.1
count=$(($count - 1))
2009-08-06 08:32:33 +02:00
done
2009-08-13 08:20:02 +02:00
return 1
}
load_uinput() {
if [ ! -e /dev/input/uinput ] ; then
modprobe -q uinput || true
wait_for_file /dev/input/uinput 3 || return 1
2009-08-06 08:32:33 +02:00
fi
}
2009-08-13 08:20:02 +02:00
wait_usr_mount() {
if [ ! -e "$DAEMON" ] ; then
wait_for_file "$DAEMON" 7 || return 1
fi
}
is_running() {
start-stop-daemon --stop --test --quiet --pidfile \
/var/run/$NAME.pid --exec $DAEMON
}
do_start() {
start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
--exec $DAEMON -- $DAEMON_OPTS
}
do_stop() {
$DAEMON -k
start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
--oknodo --retry 5 --exec $DAEMON
}
2009-08-06 08:32:33 +02:00
2007-08-28 20:09:54 +02:00
case "$1" in
start)
echo -n "Starting $DESC: "
2009-08-13 08:20:02 +02:00
load_uinput || echo -n ".../dev/input/uinput not found ..."
do_start
2007-08-28 20:09:54 +02:00
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
2009-08-13 08:20:02 +02:00
do_stop
2007-08-28 20:09:54 +02:00
echo "$NAME."
;;
#reload)
#
# If the daemon can reload its config files on the fly
# for example by sending it SIGHUP, do it here.
#
# If the daemon responds to changes in its config file
# directly anyway, make this a do-nothing entry.
#
# echo "Reloading $DESC configuration files."
# start-stop-daemon --stop --signal 1 --quiet --pidfile \
# /var/run/$NAME.pid --exec $DAEMON
2009-08-13 08:20:02 +02:00
#;;
2007-08-28 20:09:54 +02:00
force-reload)
#
# If the "reload" option is implemented, move the "force-reload"
# option to the "reload" entry above. If not, "force-reload" is
# just the same as "restart" except that it does nothing if the
# daemon isn't already running.
# check wether $DAEMON is running. If so, restart
2009-08-13 08:20:02 +02:00
is_running && $0 restart || exit 0
;;
2007-08-28 20:09:54 +02:00
restart)
echo -n "Restarting $DESC: "
2009-08-13 08:20:02 +02:00
do_stop
# the device is slow to shut-down
sleep 0.5
do_start
2007-08-28 20:09:54 +02:00
echo "$NAME."
;;
2009-08-13 08:20:02 +02:00
udev)
if [ "x$ACTION" = "xadd" ] ; then
load_uinput || true
wait_usr_mount || true
# it seems udev will not release a device if userspace is still
# connected
is_running && ( do_stop; sleep 0.5 )
do_start
elif [ "x$ACTION" = "xremove" ] ; then
do_stop
else
echo "unknow udev action '$ACTION'"
exit 1
fi
;;
2007-08-28 20:09:54 +02:00
*)
N=/etc/init.d/$NAME
2009-08-13 08:20:02 +02:00
echo "Usage: $N {start|stop|restart|force-reload|udev}" >&2
2007-08-28 20:09:54 +02:00
exit 1
;;
esac
exit 0