Skip to content

Commit 5886170

Browse files
committed
- [+] add the lib/init/init-d-script from sysvinit-utils_2.88dsf-58 in, as a private copy, lib/init/dbab-init-d-script, so as to avoid potential conflicts. Details in README.Debian
1 parent 4cc3a0d commit 5886170

File tree

6 files changed

+310
-3
lines changed

6 files changed

+310
-3
lines changed

debian/README.Debian

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# About starting dbab on machine starts
2+
3+
This has not been an issue until things get complicated. OK, here was my goal:
4+
5+
- Start the dbab service on on machine starts.
6+
- Make it possible by using the SysV init.d script.
7+
- But also support those systems that uses Systemd.
8+
- And most importantly, support as many systems in different version as
9+
possible.
10+
11+
This sounds good, but only on paper, because there have to be some serious
12+
compromises to make. Here is a list of all issues that need to dealt with:
13+
14+
- This original init script that I provided myself
15+
lacks error handling, and is fragile and racy, too.
16+
17+
- There is a ready-made solution, `/lib/init/init-d-script` from
18+
`sysvinit-utils` (ver 2.88dsf-58), that provides out-of-box solution.
19+
20+
- However, that solution is not available in Ubuntu, even in latest 14.10.
21+
22+
- If I borrow that ready-made code into my own package, Sid will be upset
23+
if I still call it `/lib/init/init-d-script`.
24+
25+
- However if I do not call it `/lib/init/init-d-script`, then the
26+
package can't even be built. lintian will complain loudly:
27+
28+
~~~
29+
E: dbab: init.d-script-does-not-implement-required-option etc/init.d/dbab start
30+
E: dbab: init.d-script-does-not-implement-required-option etc/init.d/dbab stop
31+
E: dbab: init.d-script-does-not-implement-required-option etc/init.d/dbab restart
32+
E: dbab: init.d-script-does-not-implement-required-option etc/init.d/dbab force-reload
33+
W: dbab: init.d-script-does-not-source-init-functions etc/init.d/dbab
34+
~~~
35+
36+
- So the only option that I have is to have a renamed private
37+
/lib/init/init-d-script file, then override the above lintian errors.
38+
Otherwise, I can't make all the following three happy: Debian Sid,
39+
Debian wheezy and Ubuntu.
40+
41+
- That's the compromises regarding SysV init.d script. The Systemd is
42+
not much different.
43+
44+
- In order to have Systemd support, the `debian/rules` has to use
45+
46+
dh $@ --with systemd
47+
48+
- However, that will introduce a installation dependency `init-system-helpers`,
49+
and it's version has to `>= 1.18~`.
50+
51+
- But if you take a look at Debian & Ubuntu, neither Debian Wheezy nor
52+
Ubuntu Trusty (14.04LTS) support that (at least by default).
53+
54+
- So I *have to* drop that v1.18 `init-system-helpers` dependency,
55+
meaning that I have to build without the `--with systemd`.
56+
57+
- I believe that the impact on the systemd systems is that the dbab service
58+
will not starts on machine starts, unless you, the systemd user, manually
59+
symlink the `/lib/systemd/system/dbab.service` file into
60+
`/etc/systemd/system/`.
61+
62+
OK, hopefully for now, most if not all people are happy.

debian/dbab.lintian-overrides

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dbab binary: init.d-script-does-not-implement-required-option *
2+
dbab binary: init.d-script-does-not-source-init-functions *

debian/rules

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
#export DH_VERBOSE=1
66

77
%:
8-
dh $@ --with systemd
8+
dh $@
9+
# --with systemd

src/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ exec_prefix = ${prefix}
66
mandir = ${prefix}/share/man
77
docdir = ${prefix}/share/doc/dbab
88
bindir = ${exec_prefix}/sbin
9+
libdir = ${DESTDIR}/lib
910
etcdir = ${DESTDIR}/etc
1011
astdir = ${etcdir}/dbab
1112
ssddir = ${DESTDIR}/lib/systemd/system
@@ -26,6 +27,7 @@ install:
2627
$(INSTALL) -m 755 -d $(mandir)/man1
2728
$(INSTALL) -m 755 -d $(mandir)/man8
2829
$(INSTALL) -m 755 -d $(docdir)
30+
$(INSTALL) -m 755 -d $(libdir)/init
2931
$(INSTALL) -m 755 -d $(etcdir)
3032
$(INSTALL) -m 755 -d $(etcdir)/init.d
3133
$(INSTALL) -m 755 -d $(astdir)
@@ -36,6 +38,7 @@ install:
3638
$(INSTALL) -m 755 bin/dbab-chk-list $(bindir)
3739
$(INSTALL) -m 755 bin/dhcp-add-wpad $(bindir)
3840
$(INSTALL) -m 755 bin/dbab-svr $(bindir)
41+
$(INSTALL) -m 755 bin/dbab-init-d-script $(libdir)/init
3942
$(INSTALL) -m 755 bin/dbab $(etcdir)/init.d
4043
$(INSTALL) -m 644 assets/dbab.service $(ssddir)
4144

src/bin/dbab

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /bin/sh
22
# kFreeBSD do not accept scripts as interpreters, using #!/bin/sh and sourcing.
33
if [ true != "$INIT_D_SCRIPT_SOURCED" ] ; then
4-
set "$0" "$@"; INIT_D_SCRIPT_SOURCED=true . /lib/init/init-d-script
4+
set "$0" "$@"; INIT_D_SCRIPT_SOURCED=true . /lib/init/dbab-init-d-script
55
fi
66
### BEGIN INIT INFO
77
# Provides: dbab
@@ -14,6 +14,6 @@ fi
1414
### END INIT INFO
1515

1616
DESC="dnsmasq-based ad-blocker"
17-
DAEMON=/usr/sbin/dbab-srv
17+
DAEMON=/usr/sbin/dbab-svr
1818

1919
START_ARGS="--background --make-pidfile"

src/bin/dbab-init-d-script

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
#!/bin/sh
2+
# See init-d-script(5) for instructions on how to use this library.
3+
#=============================================================================
4+
# Define LSB log_* functions.
5+
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
6+
# and status_of_proc is working.
7+
. /lib/lsb/init-functions
8+
9+
# PATH should only include /usr/* if it runs after the mountnfs.sh
10+
# script. Scripts running before mountnfs.sh should remove the /usr/*
11+
# entries.
12+
PATH=/sbin:/usr/sbin:/bin:/usr/bin
13+
export PATH
14+
15+
is_call_implemented() {
16+
command -V $1 > /dev/null 2>&1
17+
}
18+
19+
do_usage() {
20+
if is_call_implemented do_reload ; then
21+
echo "Usage: $SCRIPTNAME {start|stop|status|reload|restart|try-restart|force-reload}" >&2
22+
else
23+
echo "Usage: $SCRIPTNAME {start|stop|status|restart|try-restart|force-reload}" >&2
24+
fi
25+
}
26+
27+
call() {
28+
cmd="$1"
29+
shift
30+
if is_call_implemented ${cmd}_override ; then
31+
${cmd}_override "$@"
32+
else
33+
${cmd} "$@"
34+
fi
35+
}
36+
37+
#
38+
# Function that starts the daemon/service
39+
#
40+
41+
# Return
42+
# 0 if daemon has been started
43+
# 1 if daemon was already running
44+
# 2 if daemon could not be started
45+
do_start_cmd() {
46+
start-stop-daemon --start --quiet ${PIDFILE:+--pidfile ${PIDFILE}} \
47+
$START_ARGS \
48+
--startas $DAEMON --name $NAME --exec $DAEMON --test > /dev/null \
49+
|| return 1
50+
start-stop-daemon --start --quiet ${PIDFILE:+--pidfile ${PIDFILE}} \
51+
$START_ARGS \
52+
--startas $DAEMON --name $NAME --exec $DAEMON -- $DAEMON_ARGS \
53+
|| return 2
54+
# Add code here, if necessary, that waits for the process to be ready
55+
# to handle requests from services started subsequently which depend
56+
# on this one. As a last resort, sleep for some time.
57+
}
58+
59+
do_start()
60+
{
61+
if is_call_implemented do_start_prepare ; then
62+
call do_start_prepare
63+
fi
64+
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
65+
call do_start_cmd
66+
case "$?" in
67+
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
68+
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
69+
esac
70+
if is_call_implemented do_start_cleanup ; then
71+
call do_start_cleanup
72+
fi
73+
}
74+
75+
#
76+
# Function that stops the daemon/service
77+
#
78+
79+
# Return
80+
# 0 if daemon has been stopped
81+
# 1 if daemon was already stopped
82+
# 2 if daemon could not be stopped
83+
# other if a failure occurred
84+
do_stop_cmd() {
85+
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 \
86+
$STOP_ARGS \
87+
${PIDFILE:+--pidfile ${PIDFILE}} --name $NAME --exec $DAEMON
88+
RETVAL="$?"
89+
[ "$RETVAL" = 2 ] && return 2
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+
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 \
97+
$STOP_ARGS \
98+
--exec $DAEMON
99+
[ "$?" = 2 ] && return 2
100+
# Many daemons don't delete their pidfiles when they exit.
101+
rm -f $PIDFILE
102+
return $RETVAL
103+
}
104+
105+
do_stop()
106+
{
107+
if is_call_implemented do_stop_prepare ; then
108+
call do_stop_prepare
109+
fi
110+
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
111+
call do_stop_cmd
112+
case "$?" in
113+
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
114+
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
115+
esac
116+
if is_call_implemented do_stop_cleanup ; then
117+
call do_stop_cleanup
118+
fi
119+
}
120+
121+
do_restart() {
122+
[ "$VERBOSE" != no ] && log_daemon_msg "Restarting $DESC" "$NAME"
123+
call do_stop_cmd
124+
call do_start_cmd
125+
case "$?" in
126+
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
127+
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
128+
esac
129+
}
130+
131+
do_force_reload() {
132+
if is_call_implemented do_reload ; then
133+
call do_reload
134+
else
135+
call do_restart
136+
fi
137+
}
138+
139+
# Enable this using
140+
# alias do_reload=do_reload_sigusr1
141+
do_reload_sigusr1() {
142+
log_daemon_msg "Reloading $DESC configuration files" "$NAME"
143+
start-stop-daemon --oknodo --stop --signal 1 --quiet \
144+
--pidfile "$PIDFILE" --exec "$DAEMON"
145+
log_end_msg $?
146+
}
147+
148+
do_status() {
149+
status_of_proc "$DAEMON" "$NAME" && return 0 || return $?
150+
}
151+
152+
if [ "$DEBUG" = "true" ] ; then
153+
set -x
154+
fi
155+
156+
SCRIPTNAME=$1
157+
scriptbasename="$(basename $1)"
158+
if [ "$scriptbasename" != "init-d-script" ] ; then
159+
script="$1"
160+
shift
161+
. $script
162+
else
163+
exit 0
164+
fi
165+
166+
NAME=${NAME:=$(basename $DAEMON)}
167+
DESC=${DESC:=$NAME}
168+
169+
# Do not use pid file if $PIDFILE is 'none'. Otherwise, generate from
170+
# $NAME or use the value provided by the init.d script.
171+
if [ none = "$PIDFILE" ] ; then
172+
PIDFILE=
173+
elif [ -z "$PIDFILE" ] ; then
174+
PIDFILE=/var/run/$NAME.pid
175+
fi
176+
177+
# Exit if the package is not installed
178+
if [ none != "$DAEMON" ] && [ ! -x "$DAEMON" ] ; then
179+
exit 0
180+
fi
181+
182+
# Read configuration variable file if it is present
183+
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
184+
185+
# Load the VERBOSE setting and other rcS variables
186+
. /lib/init/vars.sh
187+
if [ -t 0 ] ; then # Be verbose when called from a terminal
188+
VERBOSE=yes
189+
fi
190+
191+
case "$1" in
192+
start)
193+
call do_start
194+
;;
195+
stop)
196+
call do_stop
197+
;;
198+
status)
199+
call do_status
200+
;;
201+
reload)
202+
if is_call_implemented do_reload ; then
203+
do_reload
204+
else
205+
call do_usage
206+
exit 3
207+
fi
208+
;;
209+
force-reload)
210+
call do_force_reload
211+
;;
212+
restart)
213+
call do_restart
214+
;;
215+
try-restart)
216+
log_daemon_msg "Trying to restart $DESC" "$NAME"
217+
if call do_status > /dev/null 2>&1 ; then
218+
call do_restart
219+
log_end_msg $?
220+
else
221+
log_progress_msg "is not running."
222+
log_end_msg 1
223+
fi
224+
;;
225+
'')
226+
call do_usage
227+
exit 3
228+
;;
229+
*)
230+
if is_call_implemented do_unknown ; then
231+
call do_unknown "$1"
232+
exit 3
233+
else
234+
call do_usage
235+
exit 3
236+
fi
237+
;;
238+
esac
239+
exit 0

0 commit comments

Comments
 (0)