Skip to content

Commit 6c411fd

Browse files
committed
net::dnsmasq: add sysv init file
1 parent 681e2d9 commit 6c411fd

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

recipes/net/dnsmasq.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
inherit: [cpackage, make, install]
1+
inherit: [cpackage, make, install, init]
22

33
metaEnvironment:
44
PKG_VERSION: "2.90"
@@ -31,4 +31,10 @@ buildScript: |
3131
# required at runtime:
3232
mkdir -p install/var/lib/misc
3333
34+
# add init script
35+
if initIsAnySysvinit; then
36+
install -D -m 0755 $<@dnsmasq/S80dnsmasq.sh@> \
37+
install/etc/init.d/S80dnsmasq.sh
38+
fi
39+
3440
packageScript: installPackageTgt "$1/install/"

recipes/net/dnsmasq/S80dnsmasq.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/sh
2+
3+
# This file comes from buildroot and is licensed under GPLv2.
4+
5+
DAEMON="dnsmasq"
6+
PIDFILE="/var/run/$DAEMON.pid"
7+
8+
[ -f /etc/dnsmasq.conf ] || exit 0
9+
10+
case "$1" in
11+
start)
12+
printf "Starting dnsmasq: "
13+
start-stop-daemon -S -p "$PIDFILE" -x "/usr/sbin/$DAEMON" -- \
14+
--pid-file="$PIDFILE"
15+
# shellcheck disable=SC2181
16+
[ $? = 0 ] && echo "OK" || echo "FAIL"
17+
;;
18+
stop)
19+
printf "Stopping dnsmasq: "
20+
start-stop-daemon -K -q -p "$PIDFILE" -x "/usr/sbin/$DAEMON"
21+
# shellcheck disable=SC2181
22+
[ $? = 0 ] && echo "OK" || echo "FAIL"
23+
# wait for dnsmasq process to be gone
24+
while true; do
25+
pid="$( cat "${PIDFILE}" 2>/dev/null || true )"
26+
{ [ -n "${pid}" ] && [ -d "/proc/${pid}" ]; } || break
27+
sleep 0.1
28+
done
29+
rm -f "$PIDFILE"
30+
;;
31+
restart|reload)
32+
$0 stop
33+
$0 start
34+
;;
35+
*)
36+
echo "Usage: $0 {start|stop|restart}"
37+
exit 1
38+
esac
39+
40+
exit 0

0 commit comments

Comments
 (0)