blob: 05d284e72573cd96ef14bc078530d011e4b78246 [file] [log] [blame]
Andrew Geisslerd5838332022-05-27 11:33:10 -05001#! /bin/sh
2### BEGIN INIT INFO
3# Provides: ulogd2 ulogd
4# Required-Start: $local_fs
5# Should-Start:
6# Required-Stop: $local_fs
7# Should-Stop:
8# Default-Start: 2 3 4 5
9# Default-Stop: 0 1 6
10# Short-Description: Userspace logging daemon for netfilter/iptables
11### END INIT INFO
12
13# The definition of actions: (From LSB 3.1.0)
14# start start the service
15# stop stop the service
16# restart stop and restart the service if the service is already running,
17# otherwise start the service
18# try-restart restart the service if the service is already running
19# reload cause the configuration of the service to be reloaded without
20# actually stopping and restarting the service
21# force-reload cause the configuration to be reloaded if the service supports
22# this, otherwise restart the service if it is running
23# status print the current status of the service
24
25# The start, stop, restart, force-reload, and status actions shall be supported
26# by all init scripts; the reload and the try-restart actions are optional
27
28# PATH should only include /usr/* if it runs after the mountnfs.sh script
29PATH=/sbin:/usr/sbin:/bin:/usr/bin
30
31DESC="Userspace logging daemon for netfilter/iptables"
32NAME="ulogd"
33DAEMON=/usr/sbin/$NAME
34DAEMON_ARGS="-d"
35PIDFILE=/var/run/$NAME.pid
36
37. /etc/init.d/functions || exit 1
38
39# Exit if the package is not installed
40[ -x "$DAEMON" ] || exit 0
41
42# Read configuration variable file if it is present
43[ -r /etc/default/$NAME ] && . /etc/default/$NAME
44
45#
46# Function that starts the daemon/service
47#
48do_start() {
49 local status pid
50
51 status=0
52 pid=`pidofproc $NAME` || status=$?
53 case $status in
54 0)
55 echo "$DESC already running ($pid)."
56 exit 1
57 ;;
58 *)
59 echo "Starting $DESC ..."
60 exec $DAEMON $DAEMON_ARGS >/dev/null 2>&1 || status=$?
61 echo "ERROR: Failed to start $DESC."
62 exit $status
63 ;;
64 esac
65
66 # Add code here, if necessary, that waits for the process to be ready
67 # to handle requests from services started subsequently which depend
68 # on this one. As a last resort, sleep for some time.
69}
70
71#
72# Function that stops the daemon/service
73#
74do_stop() {
75 local pid status
76
77 status=0
78 pid=`pidofproc $NAME` || status=$?
79 case $status in
80 0)
81 # Exit when fail to stop, the kill would complain when fail
82 kill -s 15 $pid >/dev/null && rm -f $PIDFILE && \
83 echo "Stopped $DESC ($pid)." || exit $?
84 ;;
85 *)
86 echo "$DESC is not running; none killed." >&2
87 ;;
88 esac
89
90 # Wait for children to finish too if this is a daemon that forks
91 # and if the daemon is only ever run from this initscript.
92 # If the above conditions are not satisfied then add some other code
93 # that waits for the process to drop all resources that could be
94 # needed by services started subsequently. A last resort is to
95 # sleep for some time.
96 return $status
97}
98
99#
100# Function that sends a SIGHUP to the daemon/service
101#
102do_reload() {
103 local pid status
104
105 status=0
106 # If the daemon can reload its configuration without
107 # restarting (for example, when it is sent a SIGHUP),
108 # then implement that here.
109 pid=`pidofproc $NAME` || status=$?
110 case $status in
111 0)
112 echo "Reloading $DESC ..."
113 kill -s 1 $pid || exit $?
114 ;;
115 *)
116 echo "$DESC is not running; none reloaded." >&2
117 ;;
118 esac
119 exit $status
120}
121
122
123#
124# Function that shows the daemon/service status
125#
126status_of_proc () {
127 local pid status
128
129 status=0
130 # pidof output null when no program is running, so no "2>/dev/null".
131 pid=`pidofproc $NAME` || status=$?
132 case $status in
133 0)
134 echo "$DESC is running ($pid)."
135 exit 0
136 ;;
137 *)
138 echo "$DESC is not running." >&2
139 exit $status
140 ;;
141 esac
142}
143
144case "$1" in
145start)
146 do_start
147 ;;
148stop)
149 do_stop || exit $?
150 ;;
151status)
152 status_of_proc
153 ;;
154restart)
155 # Always start the service regardless the status of do_stop
156 do_stop
157 do_start
158 ;;
159try-restart|force-reload)
160 # force-reload is the same as reload or try-restart according
161 # to its definition, the reload is not implemented here, so
162 # force-reload is the alias of try-restart here, but it should
163 # be the alias of reload if reload is implemented.
164 #
165 # Only start the service when do_stop succeeds
166 do_stop && do_start
167 ;;
168reload)
169 # If the "reload" action is implemented properly, then let the
170 # force-reload be the alias of reload, and remove it from
171 # try-restart|force-reload)
172 #
173 do_reload
174 ;;
175*)
176 echo "Usage: $0 {start|stop|status|restart|try-restart|force-reload}" >&2
177 exit 3
178 ;;
179esac
180