File: arpon.init

package info (click to toggle)
arpon 3.0-ng%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 728 kB
  • sloc: ansic: 3,416; sh: 166; makefile: 6
file content (182 lines) | stat: -rw-r--r-- 3,875 bytes parent folder | download | duplicates (3)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/bin/sh
#
### BEGIN INIT INFO
# Provides:          arpon
# Required-Start:    $network $remote_fs
# Required-Stop:     $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Anti ARP poisoning daemon
# Description:       Anti ARP poisoning daemon
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin
NAME=arpon
DAEMON=/usr/sbin/$NAME
DESC="anti ARP poisoning daemon"
LOGDIR=/var/log/arpon  # Log directory to use
PIDDIR=/run/

test -x $DAEMON || exit 0

. /lib/lsb/init-functions

# Load arpon defaults
if [ -f /etc/default/$NAME ] ; then
	. /etc/default/$NAME
fi

#
# Function that starts the daemon
#
start_instances()
{
	# Return
	#   0 if daemons for all interfaces have been started
	#   1 if daemons for all interfaces have been started, but at least one
	#     was already running
	#   2 if at least one daemon could not have been stopped
	local RET=0
	local IFACE
	local EXITCODE
	# make sure the log directory exists
	mkdir -p "${LOGDIR}"
	for IFACE in $INTERFACES ; do
		log_progress_msg "$IFACE"
		start-stop-daemon --start --quiet --background --make-pidfile \
			--pidfile "${PIDDIR}/${NAME}-${IFACE}.pid" \
			--exec "$DAEMON" -- -i "$IFACE" $DAEMON_ARGS
		EXITCODE=$?
		RET=$(($RET|$EXITCODE))
	done
	return $RET
}

stop_instances()
{
	# Return
	#   0 if daemons for all interfaces have been stopped
	#   1 if daemons for all interfaces have been stopped, but for at least one
	#     interface it was stopped already
	#   2 if at least one daemon could not have been stopped
	local RET=0
	local IFACE
	local EXITCODE
	for IFACE in $INTERFACES ; do
		log_progress_msg "$IFACE"
		start-stop-daemon --stop --quiet --remove-pidfile \
			--pidfile "${PIDDIR}/${NAME}-${IFACE}.pid" \
			--exec "$DAEMON" --retry=TERM/30/KILL/5
		EXITCODE=$?
		RET=$(($RET|$EXITCODE))
	done
	return $RET
}

reload_instances()
{
	# no return value as there is no suitable way to determine if the signal
	# was processed properly
	local IFACE
	for IFACE in $INTERFACES ; do
		log_progress_msg "$IFACE"
		start-stop-daemon --stop --quiet \
			--pidfile "${PIDDIR}/${NAME}-${IFACE}.pid" \
			--exec "$DAEMON" --signal=HUP
	done
	return 0
}

get_status()
{
	# Return
	#   0      if daemons for all interfaces are running
	#   1/3    if the daemon for at least one interface is not running
	#   4/5/7  if the status of at least one daemon could not be determined
	local RET=0
	local IFACE
	local EXITCODE
	for IFACE in $INTERFACES ; do
		start-stop-daemon --status --quiet \
			--pidfile "${PIDDIR}/${NAME}-${IFACE}.pid" \
			--exec "$DAEMON"
		EXITCODE=$?
		RET=$(($RET|$EXITCODE))
	done
	return $RET
}

case "$1" in
	start)
		log_daemon_msg "Starting $NAME ($DESC) on interfaces"
		start_instances
		case "$?" in
			0|1)
				log_end_msg 0
				;;
			*)
				log_end_msg 1
				;;
		esac
		;;
	stop)
		log_daemon_msg "Stopping $NAME ($DESC) on interfaces"
		stop_instances
		case "$?" in
			0|1)
				log_end_msg 0
				;;
			*)
				log_end_msg 1
				;;
		esac
		;;
	restart)
		log_daemon_msg "Restarting $NAME ($DESC) on interfaces"
		log_progress_msg "stopping:"
		stop_instances
		case "$?" in
			0|1)
				log_progress_msg "starting:"
				start_instances
				case "$?" in
					0)
						log_end_msg 0
						;;
					*)
						log_end_msg 1
						;;
				esac
				;;
			*)
				log_end_msg 1
				;;
		esac
		;;
	reload|force-reload)
		log_daemon_msg "Reloading $NAME ($DESC) configuration for interfaces"
		reload_instances
		log_end_msg 0
		;;
	status)
		get_status
		case "$?" in
			0)
				log_success_msg "$NAME is running on all configured interfaces"
				;;
			1|3)
				log_failure_msg "$NAME is not running on all configured interfaces"
				;;
			*)
				log_failure_msg "Could not determine if $NAME is running"
				;;
		esac
		;;
	*)
		N=/etc/init.d/$NAME
		echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2
		exit 1
		;;
esac

exit 0