summaryrefslogtreecommitdiffstats
path: root/source/n/dnsmasq/rc.dnsmasq
blob: f19a1723945d65075896eaf95fe32669158b69a2 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/sh
# Start/stop/restart dnsmasq (a small DNS/DHCP server):

# Start dnsmasq:
dnsmasq_start() {
  if [ -x /usr/sbin/dnsmasq ]; then
    echo "Starting dnsmasq:  /usr/sbin/dnsmasq"
    /usr/sbin/dnsmasq
  fi
}

# Stop dnsmasq:
dnsmasq_stop() {
  # Try to use the .pid file first:
  if pgrep -l -F /var/run/dnsmasq.pid 2> /dev/null | grep -q dnsmasq ; then
    echo "Stopping dnsmasq."
    pkill -F /var/run/dnsmasq.pid 2> /dev/null
  else # kill any dnsmasq processes in this namespace:
    echo "Stopping dnsmasq."
    killall --ns $$ dnsmasq 2> /dev/null  
  fi
}

# Restart dnsmasq:
dnsmasq_restart() {
  dnsmasq_stop
  sleep 1
  dnsmasq_start
}

case "$1" in
'start')
  dnsmasq_start
  ;;
'stop')
  dnsmasq_stop
  ;;
'restart')
  dnsmasq_restart
  ;;
*)
  echo "usage rc.dnsmasq: start|stop|restart"
esac