-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmosdns
executable file
·106 lines (93 loc) · 2.44 KB
/
mosdns
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
#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: mosdns
# REQUIRE: LOGIN FILESYSTEMS
# KEYWORD: shutdown
. /etc/rc.subr
name="mosdns"
desc="mosdns daemon"
rcvar="mosdns_enable"
pidfile="/var/run/mosdns.pid"
procname="/usr/bin/mosdns"
# Set some default values for your application
load_rc_config $name
: ${mosdns_enable=NO}
: ${mosdns_restart=YES}
: ${mosdns_command="/usr/bin/mosdns start"}
: ${mosdns_flags="-c /usr/local/etc/mosdns/config.yml"}
# command="/usr/bin/mosdns"
# command_args="start -c /usr/local/etc/mosdns/config.yml"
command="/usr/sbin/daemon"
command_args="-P ${pidfile} -u root -r -f ${mosdns_command} ${mosdns_flags}"
start_cmd="mosdns_start"
stop_cmd="mosdns_stop"
status_cmd="mosdns_status"
check_pidfile() {
if [ -e "$pidfile" ]; then
pid=$(cat "$pidfile")
if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then
return 0 # The process is running
else
return 1 # The pidfile is stale
fi
else
return 2 # The pidfile does not exist
fi
}
mosdns_start() {
check_pidfile
case $? in
0)
echo "mosdns is already running with PID $(cat $pidfile)."
;;
1)
echo "Stale pidfile found. Removing it."
rm -f "$pidfile"
;;
2)
echo "Starting mosdns..."
cd /usr/local/etc/mosdns
touch cache.dump
chown nobody:nogroup cache.dump
chmod 0755 cache.dump
${command} ${command_args} &
;;
esac
}
mosdns_stop() {
check_pidfile
case $? in
0)
echo "Stopping mosdns..."
kill -TERM $(cat $pidfile)
rm -f "$pidfile"
rm -f /usr/local/etc/mosdns/cache.dump
echo "" > /var/log/mosdns.log
;;
1)
echo "Stale pidfile found. Removing it."
rm -f "$pidfile"
;;
2)
echo "mosdns is not running."
;;
esac
}
mosdns_status() {
echo "Checking mosdns status..."
echo "PID File: $pidfile"
if [ -e "$pidfile" ]; then
pid=$(cat "$pidfile")
if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then
echo "mosdns is running with PID $pid."
else
echo "mosdns is not running, but the PID file exists. Cleaning up stale PID file."
rm -f "$pidfile"
fi
else
echo "mosdns is not running."
fi
}
run_rc_command "$1"