Debian Codegraph @

debian/mlat-client-adsbfi.init

raw
1 #!/bin/bash
2 ### BEGIN INIT INFO
3 # Provides: mlat-client-adsbfi
4 # Required-Start: $remote_fs
5 # Required-Stop: $remote_fs
6 # Default-Start: 2 3 4 5
7 # Default-Stop: 0 1 6
8 # Short-Description: Multilateration client
9 # Description: Receives ADS-B messages from a receiver
10 # and forwards them to a server for multilateration of
11 # the aircraft position.
12 ### END INIT INFO
13
14 # Do NOT "set -e"
15
16 # PATH should only include /usr/* if it runs after the mountnfs.sh script
17 PATH=/sbin:/usr/sbin:/bin:/usr/bin
18 NAME=mlat-client-adsbfi
19 DESC="$NAME daemon"
20 DAEMON=/usr/bin/$NAME
21 ARGS=""
22 PIDFILE=/var/run/$NAME.pid
23 SCRIPTNAME=/etc/init.d/$NAME
24
25 # Exit if the package is not installed
26 [ -x "$DAEMON" ] || exit 0
27
28 # Read configuration variable file if it is present
29 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
30
31 # work out daemon args
32
33 # sanitize missing settings
34 badconfig=""
35 [ -z "$START_CLIENT" ] && START_CLIENT=no
36 [ -z "$RUN_AS_USER" ] && RUN_AS_USER="missing-RUN_AS_USER-setting-in-config"
37 [ -z "$SERVER_USER" ] && badconfig="$badconfig SERVER_USER"
38 [ -z "$LAT" ] && badconfig="$badconfig LAT"
39 [ -z "$LON" ] && badconfig="$badconfig LON"
40 [ -z "$ALT" ] && badconfig="$badconfig ALT"
41 [ -z "$INPUT_TYPE" ] && INPUT_TYPE=dump1090
42 [ -z "$INPUT_HOSTPORT" ] && badconfig="$badconfig INPUT_HOSTPORT"
43 [ -z "$SERVER_HOSTPORT" ] && badconfig="$badconfig SERVER_HOSTPORT"
44
45 ARGS="--user $SERVER_USER --lat $LAT --lon $LON --alt $ALT --input-type $INPUT_TYPE --input-connect $INPUT_HOSTPORT --server $SERVER_HOSTPORT"
46
47 for r in $RESULTS
48 do
49 if [ "$r" != "none" ]
50 then
51 ARGS="$ARGS --results $r"
52 fi
53 done
54
55 ARGS="$ARGS $EXTRA_ARGS"
56
57 # Load the VERBOSE setting and other rcS variables
58 . /lib/init/vars.sh
59
60 # Define LSB log_* functions.
61 # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
62 # and status_of_proc is working.
63 . /lib/lsb/init-functions
64
65 #
66 # Function that starts the daemon/service
67 #
68 do_start()
69 {
70 # Return
71 # 0 if daemon has been started
72 # 1 if daemon was already running
73 # 2 if daemon could not be started
74
75 if [ "x$START_CLIENT" != "xyes" ]; then
76 log_warning_msg "Not starting $NAME daemon, disabled via /etc/default/$NAME"
77 return 2
78 fi
79
80 if [ -n "$badconfig" ]; then
81 log_warning_msg "Not starting $NAME daemon, missing configuration options ($badconfig)"
82 return 2
83 fi
84
85 start-stop-daemon --start --quiet --pidfile $PIDFILE --user "$RUN_AS_USER" --startas $DAEMON --test > /dev/null \
86 || return 1
87
88 start-stop-daemon --start --nicelevel 5 --quiet --pidfile $PIDFILE --user "$RUN_AS_USER" --chuid "$RUN_AS_USER" --make-pidfile --background --no-close --startas $DAEMON -- \
89 $ARGS >>$LOGFILE 2>&1 \
90 || return 2
91 sleep 1
92 }
93
94 #
95 # Function that stops the daemon/service
96 #
97 do_stop()
98 {
99 # Return
100 # 0 if daemon has been stopped
101 # 1 if daemon was already stopped
102 # 2 if daemon could not be stopped
103 # other if a failure occurred
104 start-stop-daemon --stop --retry=TERM/30/KILL/5 --pidfile $PIDFILE --user "$RUN_AS_USER"
105 RETVAL="$?"
106 [ "$RETVAL" = 2 ] && return 2
107 sleep 1
108 # Many daemons don't delete their pidfiles when they exit.
109 rm -f $PIDFILE
110 return "$RETVAL"
111 }
112
113 case "$1" in
114 start)
115 [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
116 do_start
117 case "$?" in
118 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
119 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
120 esac
121 ;;
122 stop)
123 [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
124 do_stop
125 case "$?" in
126 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
127 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
128 esac
129 ;;
130 status)
131 status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
132 ;;
133 restart|force-reload)
134 log_daemon_msg "Restarting $DESC" "$NAME"
135 do_stop
136 case "$?" in
137 0|1)
138 do_start
139 case "$?" in
140 0) log_end_msg 0 ;;
141 1) log_end_msg 1 ;; # Old process is still running
142 *) log_end_msg 1 ;; # Failed to start
143 esac
144 ;;
145 *)
146 # Failed to stop
147 log_end_msg 1
148 ;;
149 esac
150 ;;
151 *)
152 echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
153 exit 3
154 ;;
155 esac
156
157 :