xref: /OK3568_Linux_fs/yocto/meta-openembedded/meta-networking/recipes-support/dnsmasq/files/init (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1#!/bin/sh
2DAEMON=/usr/bin/dnsmasq
3NAME=dnsmasq
4DESC="DNS forwarder and DHCP server"
5ARGS="-7 /etc/dnsmasq.d"
6
7test -f $DAEMON || exit 0
8
9set -e
10
11if [ -r /etc/default/$NAME ]
12then
13	. /etc/default/$NAME
14fi
15
16DNSMASQ_CONF="/etc/dnsmasq.conf"
17test "/etc/dnsmasq.d/*" != '/etc/dnsmasq.d/*' && DNSMASQ_CONF="${DNSMASQ_CONF} /etc/dnsmasq.d/*"
18
19test -z "${PIDFILE}" && PIDFILE="/run/dnsmasq.pid"
20
21if [ -z "$IGNORE_RESOLVCONF" ]
22then
23	egrep -h -q '^no-resolv' ${DNSMASQ_CONF} && IGNORE_RESOLVCONF="yes"
24fi
25
26# RESOLV_CONF:
27# If the resolvconf package is installed then use the resolv conf file
28# that it provides as the default.  Otherwise use /etc/resolv.conf as
29# the default.
30#
31# If IGNORE_RESOLVCONF is set in /etc/default/dnsmasq or an explicit
32# filename is set there then this inhibits the use of the resolvconf-provided
33# information.
34#
35# Note that if the resolvconf package is installed it is not possible to
36# override it just by configuration in /etc/dnsmasq.conf, it is necessary
37# to set IGNORE_RESOLVCONF=yes in /etc/default/dnsmasq.
38
39test -z "$RESOLV_CONF" -a "$IGNORE_RESOLVCONF" != "yes" -a -x /sbin/resolvconf && \
40	RESOLV_CONF=/run/dnsmasq/resolv.conf
41
42start_resolvconf()
43{
44        if [ "$IGNORE_RESOLVCONF" != "yes" -a -x /sbin/resolvconf ]
45	then
46		echo "nameserver 127.0.0.1" | /sbin/resolvconf -a lo.$NAME
47	fi
48	:
49}
50
51stop_resolvconf()
52{
53	if [ "$IGNORE_RESOLVCONF" != "yes" -a -x /sbin/resolvconf ]
54	then
55		/sbin/resolvconf -d lo.$NAME
56	fi
57	:
58}
59
60case "$1" in
61    start)
62        echo -n "starting $DESC: $NAME... "
63	test -d /var/lib/misc/ || mkdir /var/lib/misc/
64	start-stop-daemon -S -x $DAEMON -- $ARGS \
65		${RESOLV_CONF:+ -r $RESOLV_CONF} \
66		${PIDFILE:+ -x $PIDFILE}
67	test $? -eq 0 && start_resolvconf
68	echo "done."
69	;;
70    stop)
71        echo -n "stopping $DESC: $NAME... "
72	stop_resolvconf
73	start-stop-daemon -K -x $DAEMON
74	echo "done."
75	;;
76    status)
77	echo -n "dnsmasq "
78	start-stop-daemon -q -K -t -x $DAEMON
79	RET=$?
80	if [ "$RET" = "0" ]; then
81		PID=`cat ${PIDFILE}`
82		echo "($PID) is running"
83	else
84		echo "is not running"
85		exit $RET
86	fi
87	;;
88    restart)
89        echo "restarting $DESC: $NAME... "
90 	$0 stop
91	$0 start
92	echo "done."
93	;;
94    reload)
95    	echo -n "reloading $DESC: $NAME... "
96    	killall -HUP $(basename ${DAEMON})
97	echo "done."
98	;;
99    systemd-start-resolvconf)
100	start_resolvconf
101	;;
102    systemd-stop-resolvconf)
103	stop_resolvconf
104	;;
105    systemd-exec)
106	test -d /var/lib/misc/ || mkdir /var/lib/misc/
107	exec $DAEMON --keep-in-foreground $ARGS \
108		${RESOLV_CONF:+ -r $RESOLV_CONF} \
109		${PIDFILE:+ -x $PIDFILE}
110	;;
111    *)
112	echo "Usage: $0 {start|stop|status|restart|reload}"
113	exit 1
114	;;
115esac
116
117exit 0
118