-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbro-1.5.rc
190 lines (160 loc) · 3.84 KB
/
bro-1.5.rc
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
183
184
185
186
187
188
189
190
#!/bin/sh
#
# Bro - Open-source, Unix-based Network Intrusion Detection System
#
# chkconfig: - 57 30
# description: Bro is an open-source, Unix-based Network Intrusion Detection System (NIDS) \
# that passively monitors network traffic and looks for suspicious activity.
#
### BEGIN INIT INFO
# Provides:
# Required-Start:
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start:
# Default-Stop:
# Short-Description:
# Description:
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
exec="/usr/bin/bro"
broctl="/usr/bin/broctl"
brohome="/"
prog="bro"
config="/etc/sysconfig/bro"
syslog_cmd="logger"
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
lockfile=/var/lock/subsys/$prog
fexists () {
[ -f "${1}" ] || exit 1
exit 0
}
dexists () {
[ -d "${1}" ] || exit 1
exit 0
}
start() {
[ -x $exec ] || exit 5
[ -x $broctl ] || exit 5
[[ -f "${config}" && \
-w "${BROLOGS}" && \
-d "${BRO_BIN_DIR}" && \
-d "${BRO_LOG_ARCHIVE}" && \
-d "${BRO_SIG_DIR}" && \
-d "${BROSITE}" && \
-d "${BROHOST}" && \
-f "${BRO}" ]] || exit 6
local current_date
local trace_file
local cmd_opts
cmd_opts="${BRO_OPTS}"
current_date="$(date +%y-%m-%d_%H.%M.%S)"
export \
BRO_LOG_SUFFIX="${BRO_HOSTNAME}.${current_date}"
trace_file="${BROLOGS}/trace.${BRO_LOG_SUFFIX}"
info_file="${BROLOGS}/info.${BRO_LOG_SUFFIX}"
if [ "${BRO_CREATE_TRACE_FILE}" = 'YES' -o "${BRO_CREATE_TRACE_FILE}" = 'yes' ]; then
cmd_opts="${cmd_opts} -w \"${trace_file}\""
fi
if [ -n "${BRO_CAPTURE_INTERFACE}" ]; then
for _intf in ${BRO_CAPTURE_INTERFACE}; do
cmd_opts="${cmd_opts} -i ${_intf}"
done
fi
if [ -n "${BRO_START_POLICY}" ]; then
cmd_opts="${cmd_opts} ${BRO_START_POLICY}"
else
echo "${prog}: No start policy file specified." >&2
fi
cd "${BROLOGS}" || exit 6
echo -n $"Starting $prog: "
#"${exec}" ${cmd_opts} >> "${info_file}" 2>&1 &
HOME="$brohome" "${broctl}" start >> /dev/null 2>&1
retval=$?
newpid=$!
#if [ "${retval}" = '0' -o -z "${retval}" ]; then
# for ((i=1; i < 11; i++)); do
# if [ -f "${info_file}" ]; then
# if [ -n "$(grep -E '^listening on' "${info_file}")" ]; then
# break
# fi
# fi
#
# # break now if the process returned a non-zero value
# if [ -n "${retval}" -a "${retval}" != '0' ]; then
# break
# fi
# sleep 1
# done
#fi
if [ "${retval}" != '0' ]; then
${syslog_cmd} -t "${prog}" "Bro has failed to start."
else
${syslog_cmd} -t "${prog}" "Bro process (${newpid}) has started"
fi
if [ $retval -eq 0 ]; then
touch $lockfile
success
else
failure
fi
echo
return $retval
}
stop() {
echo -n $"Stopping $prog: "
HOME="$brohome" "${broctl}" stop >> /dev/null 2>&1
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
stop
start
}
reload() {
restart
}
force_reload() {
restart
}
rh_status() {
HOME="$brohome" "${broctl}" status 2>&1 | grep running
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
exit 2
esac
exit $?