xref: /openbmc/openbmc/meta-openembedded/meta-oe/recipes-navigation/gpsd/gpsd/gpsd.init (revision 89770b09490d616883ab728cc628a844ca0e1150)
1#! /bin/sh
2### BEGIN INIT INFO
3# Provides:          gpsd
4# Required-Start:    $remote_fs $syslog $network
5# Should-Start:      bluetooth dbus udev
6# Required-Stop:     $remote_fs $syslog $network
7# Should-Stop:
8# Default-Start:     2 3 4 5
9# Default-Stop:      0 1 6
10# X-Start-Before:    ntp
11# Short-Description: GPS (Global Positioning System) daemon start/stop script
12# Description:       Start/Stop script for the gpsd service daemon,
13#                    which is able to monitor one or more GPS devices
14#                    connected to a host computer, making all data on
15#                    the location and movements of the sensors available
16#                    to be queried on TCP port 2947.
17### END INIT INFO
18
19
20# PATH should only include /usr/* if it runs after the mountnfs.sh script
21PATH=/sbin:/usr/sbin:/bin:/usr/bin
22
23DESC="GPS (Global Positioning System) daemon"
24NAME="gpsd"
25DAEMON=/usr/sbin/$NAME
26PIDFILE=/var/run/$NAME.pid
27
28. /etc/init.d/functions || exit 1
29
30# Exit if the package is not installed
31[ -x "$DAEMON" ] || exit 0
32
33# Read configuration variable file if it is present
34[ -r /etc/default/$NAME ] && . /etc/default/$NAME
35
36if [ -z "$GPSD_SOCKET" ] && [ -z "$DEVICES" ]; then
37	GPSD_SOCKET=/var/run/gpsd.sock
38fi
39
40if [ -n "$GPSD_SOCKET" ]; then
41	GPSD_OPTIONS="$GPSD_OPTIONS -F $GPSD_SOCKET"
42fi
43
44DAEMON_ARGS="$GPSD_OPTIONS $DEVICES"
45
46#
47# Function that starts the daemon/service
48#
49do_start() {
50	local status pid
51
52	status=0
53	pid=`pidofproc $NAME` || status=$?
54	case $status in
55	0)
56		echo "$DESC already running ($pid)."
57		exit 1
58		;;
59	*)
60		echo "Starting $DESC ..."
61		exec $DAEMON $DAEMON_ARGS >/dev/null 2>&1 || status=$?
62		echo "ERROR: Failed to start $DESC."
63		exit $status
64		;;
65	esac
66}
67
68#
69# Function that stops the daemon/service
70#
71do_stop() {
72	local pid status
73
74	status=0
75	pid=`pidofproc $NAME` || status=$?
76	case $status in
77	0)
78		# Exit when fail to stop, the kill would complain when fail
79		kill -s 15 $pid >/dev/null && rm -f $PIDFILE && \
80			echo "Stopped $DESC ($pid)." || exit $?
81		;;
82	*)
83		echo "$DESC is not running; none killed." >&2
84		;;
85	esac
86
87	return $status
88}
89
90#
91# Function that sends a SIGHUP to the daemon/service
92#
93do_reload() {
94	local pid status
95
96	status=0
97	# If the daemon can reload its configuration without
98	# restarting (for example, when it is sent a SIGHUP),
99	# then implement that here.
100	pid=`pidofproc $NAME` || status=$?
101	case $status in
102	0)
103		echo "Reloading $DESC ..."
104		kill -s 1 $pid || exit $?
105		;;
106	*)
107		echo "$DESC is not running; none reloaded." >&2
108		;;
109	esac
110	exit $status
111}
112
113
114#
115# Function that shows the daemon/service status
116#
117status_of_proc () {
118	local pid status
119
120	status=0
121	# pidof output null when no program is running, so no "2>/dev/null".
122	pid=`pidofproc $NAME` || status=$?
123	case $status in
124	0)
125		echo "$DESC is running ($pid)."
126		exit 0
127		;;
128	*)
129		echo "$DESC is not running." >&2
130		exit $status
131		;;
132	esac
133}
134
135case "$1" in
136start)
137	do_start
138	;;
139stop)
140	do_stop || exit $?
141	;;
142status)
143	status_of_proc
144	;;
145restart)
146	# Always start the service regardless the status of do_stop
147	do_stop
148	do_start
149	;;
150force-reload)
151	# Only start the service when do_stop succeeds
152	do_stop && do_start
153	;;
154*)
155	echo "Usage: $0 {start|stop|status|restart|force-reload}" >&2
156	exit 3
157	;;
158esac
159