xref: /OK3568_Linux_fs/debian/overlay/etc/Powermanager/triggerhappy (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1#!/bin/sh
2### BEGIN INIT INFO
3# Provides:          triggerhappy
4# Required-Start:    $local_fs $remote_fs
5# Required-Stop:     $remote_fs
6# Default-Start:     2 3 4 5
7# Default-Stop:      0 1 6
8# Short-Description: triggerhappy hotkey daemon
9# Description:       triggerhappy hotkey daemon
10### END INIT INFO
11
12# Author: Stefan Tomanek <stefan.tomanek+th@wertarbyte.de>
13
14PATH=/sbin:/usr/sbin:/bin:/usr/bin
15DESC="input event daemon"
16NAME=thd
17PNAME=triggerhappy
18DAEMON=/usr/sbin/thd
19PIDFILE=/var/run/$NAME.pid
20DAEMON_ARGS="--daemon --triggers /etc/triggerhappy/triggers.d/ --socket /var/run/thd.socket --pidfile $PIDFILE --user root /dev/input/event*"
21DAEMON_OPTS="--user root"
22SCRIPTNAME=/etc/init.d/$PNAME
23
24# Exit if the package is not installed
25# [ -x $DAEMON ] || exit 0
26
27# Read configuration variable file if it is present
28[ -r /etc/default/$PNAME ] && . /etc/default/$PNAME
29
30# Load the VERBOSE setting and other rcS variables
31. /lib/init/vars.sh
32
33# Define LSB log_* functions.
34# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
35. /lib/lsb/init-functions
36
37#
38# Function that starts the daemon/service
39#
40do_start()
41{
42	# Return
43	#   0 if daemon has been started
44	#   1 if daemon was already running
45	#   2 if daemon could not be started
46	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec /usr/sbin/thd --test > /dev/null \
47		|| return 1
48	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec /usr/sbin/thd -- \
49		$DAEMON_ARGS $DAEMON_OPTS \
50		|| return 2
51}
52
53#
54# Function that stops the daemon/service
55#
56do_stop()
57{
58	# Return
59	#   0 if daemon has been stopped
60	#   1 if daemon was already stopped
61	#   2 if daemon could not be stopped
62	#   other if a failure occurred
63	start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
64	RETVAL="$?"
65	[ "$RETVAL" = 2 ] && return 2
66	# Many daemons don't delete their pidfiles when they exit.
67	rm -f $PIDFILE
68	return "$RETVAL"
69}
70
71#
72# Function that sends a SIGHUP to the daemon/service
73#
74do_reload() {
75	#
76	# If the daemon can reload its configuration without
77	# restarting (for example, when it is sent a SIGHUP),
78	# then implement that here.
79	#
80	start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
81	return 0
82}
83
84case "$1" in
85  start)
86    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME"
87    do_start
88    case "$?" in
89		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
90		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
91	esac
92  ;;
93  stop)
94	[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
95	do_stop
96	case "$?" in
97		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
98		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
99	esac
100	;;
101  status)
102       status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
103       ;;
104  reload|force-reload)
105	log_daemon_msg "Reloading $DESC" "$NAME"
106	do_reload
107	log_end_msg $?
108	;;
109  restart)
110	log_daemon_msg "Restarting $DESC" "$NAME"
111	do_stop
112	case "$?" in
113	  0|1)
114		do_start
115		case "$?" in
116			0) log_end_msg 0 ;;
117			1) log_end_msg 1 ;; # Old process is still running
118			*) log_end_msg 1 ;; # Failed to start
119		esac
120		;;
121	  *)
122	  	# Failed to stop
123		log_end_msg 1
124		;;
125	esac
126	;;
127  *)
128	echo "Usage: $SCRIPTNAME {start|stop|status|restart|reload|force-reload}" >&2
129	exit 3
130	;;
131esac
132
133:
134