File: smartdns

package info (click to toggle)
smartdns 33%2Bdfsg-2.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,556 kB
  • sloc: ansic: 17,882; sh: 1,589; javascript: 360; makefile: 128
file content (99 lines) | stat: -rw-r--r-- 2,309 bytes parent folder | download
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
#!/bin/sh
#
# Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
#
# smartdns is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# smartdns is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

### BEGIN INIT INFO
# Provides:        smartdns
# Required-Start:  $network $local_fs
# Required-Stop:   $network $local_fs
# Default-Start:   2 3 4 5
# Default-Stop:
# Short-Description: Start smartdns server
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin

. /lib/lsb/init-functions
if test -r /etc/default/smartdns; then
. /etc/default/smartdns
fi
SMARTDNS=/usr/sbin/smartdns
PIDFILE=/var/run/smartdns.pid

test -x $SMARTDNS || exit 5

case $1 in
	start)
		$SMARTDNS "$SMART_DNS_OPTS"
		while true; do
			if [ -e "$PIDFILE" ]; then
				break;
			fi
			sleep .5
		done
		PID="$(cat $PIDFILE 2>/dev/null)"
		if [ -z "$PID" ]; then
			echo "start smartdns server failed."
			exit 1
		fi
		if [ ! -e "/proc/$PID" ]; then
			echo "start smartdns server failed."
			exit 1
		fi
		echo "start smartdns server success."
		;;
	stop)
		if [ ! -f "$PIDFILE" ]; then
			echo "smartdns server is stopped."
			exit 0
		fi
		PID="$(cat $PIDFILE 2>/dev/null)"
		if [ ! -e "/proc/$PID" ] || [ -z "$PID" ]; then
			echo "smartdns server is stopped"
			exit 0
		fi

		kill -TERM "$PID"
		if [ $? -ne 0 ]; then
			echo "Stop smartdns server failed."
			exit 1;
		fi
		rm -f "$PIDFILE"
		echo "Stop smartdns server success."
		;;
	restart)
		"$0" stop && sleep 1 && "$0" start
		;;
	status)
		PID="$(cat "$PIDFILE" 2>/dev/null)"
		if [ ! -e "/proc/$PID" ] || [ -z "$PID" ]; then
			echo "smartdns server is not running."
			exit 1
		fi
		echo "smartdns server is running."
		status=$?
		;;
	reload|force-reload)
		$0 restart
		;;
	*)
		echo "Usage: $0 {start|stop|restart|status}"
		exit 2
		;;
esac

exit $status