summaryrefslogtreecommitdiff
path: root/contrib/djbdns/tinydns.init
blob: 7bcbb4773582f428b95e530caf43f7d2f02c065d (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#! /bin/bash
### BEGIN INIT INFO
# Provides:          tinydns
# Required-Start:    $local_fs $remote_fs $network
# Required-Stop:     $local_fs $remote_fs $network
# Should-Start:      $syslog
# Should-Stop:       $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: tinydns daemon processes
# Description:       Start the TinyDNS resolver
### END INIT INFO

# Documentation
#  man tinydns

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
. /lib/lsb/init-functions

NAME=tinydns
DAEMON=/usr/bin/$NAME
DAEMON_USER=djbdns
DESC="the tinydns daemon"
ROOTDIR=/var/lib/djbdns
PATH=/sbin:/bin:/usr/sbin:/usr/bin
LAUNCHER=/usr/bin/envuidgid
LAUNCHER_ARGS="$DAEMON_USER envdir ./env softlimit -d300000 $DAEMON"

PIDFILE=/run/$NAME.pid

# Exit if executable is not installed
[ -x "$DAEMON" ] || exit 0

set -x

case "$1" in
  start)
	if [ ! -d "$ROOTDIR" ]; then
		log_action_msg "Not starting $DESC: $ROOTDIR is missing."
		exit 0
	fi

	log_action_begin_msg "Starting $DESC"

	if start-stop-daemon --stop --signal 0 --quiet --pidfile $PIDFILE --exec $DAEMON; then
		log_action_end_msg 0 "already running"
	else
		if start-stop-daemon --start --verbose --make-pidfile --chdir $ROOTDIR --pidfile $PIDFILE  --exec $LAUNCHER -- $LAUNCHER_ARGS
		then
			log_action_end_msg 0
		else
			log_action_end_msg 1
			exit 1
		fi
	fi
	;;
  stop)
	log_action_begin_msg "Stopping $DESC"
	pid=$(cat $PIDFILE 2>/dev/null) || true
	if test ! -f $PIDFILE -o -z "$pid"; then
		log_action_end_msg 0 "not running - there is no $PIDFILE"
		exit 0
	fi

	if start-stop-daemon --stop --signal INT --quiet --pidfile $PIDFILE --exec $DAEMON; then
		rm -f $PIDFILE
	elif kill -0 $pid 2>/dev/null; then
		log_action_end_msg 1 "Is $pid not $NAME?  Is $DAEMON a different binary now?"
		exit 1
	else
		log_action_end_msg 1 "$DAEMON died: process $pid not running; or permission denied"
		exit 1
	fi
	;;
  reload)
	echo "Not implemented, use restart"
	exit 1
	;;
  restart|force-reload)
	$0 stop
	$0 start
	;;
  status)
	if test ! -r $(dirname $PIDFILE); then
		log_failure_msg "cannot read PID file $PIDFILE"
		exit 4
	fi
	pid=$(cat $PIDFILE 2>/dev/null) || true
	if test ! -f $PIDFILE -o -z "$pid"; then
		log_failure_msg "$NAME is not running"
		exit 3
	fi
	if ps "$pid" >/dev/null 2>&1; then
		log_success_msg "$NAME is running"
		exit 0
	else
		log_failure_msg "$NAME is not running"
		exit 1
	fi
	;;
  *)
	log_action_msg "Usage: $0 {start|stop|restart|force-reload|status}" >&2
	exit 1
	;;
esac

exit 0