-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathdocker-entrypoint.sh
executable file
·57 lines (48 loc) · 1.66 KB
/
docker-entrypoint.sh
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
#!/bin/bash
# exit script if an error is encountered
set -e
if [ ! -f /usr/local/zeek/etc/node.cfg ] || [ ! -s /usr/local/zeek/etc/node.cfg ]; then
# node.cfg doesn't exist or is empty
if [ -t 0 ]; then
# at a tty, so start the config wizard
zeekcfg -o /usr/local/zeek/etc/node.cfg --type afpacket --processes 0 --no-pin
fi
if [ ! -f /usr/local/zeek/etc/node.cfg ] || [ ! -s /usr/local/zeek/etc/node.cfg ]; then
# if still doesn't exist
echo
echo "You must first create a node.cfg file and mount it into the container."
exit 1
fi
fi
# do final log rotation
stop() {
echo "Stopping zeek..."
zeekctl stop
trap - SIGINT SIGTERM
exit
}
# run zeekctl diag on error
diag() {
echo "Running zeekctl diag for debugging"
zeekctl diag
trap - ERR
}
trap 'diag' ERR
# ensure Zeek has a valid, updated config, and then start Zeek
echo "Checking your Zeek configuration..."
# generate a single local.zeek from a bunch of partials
#We specifically strip out the line for misc/scan as it's no longer part of zeek and it's darn near impossible to find.
cat /usr/local/zeek/share/zeek/site/autoload/* | grep -v '^#' | grep -v 'misc/scan' >/usr/local/zeek/share/zeek/site/local.zeek
zeekctl check >/dev/null
zeekctl install
zeekctl start
# ensure spool logs are rotated when container is stopped
trap 'stop' SIGINT SIGTERM
# periodically run the Zeek cron monitor to restart any terminated processes
zeekctl cron enable
# disable the zeekctl ERR trap as there are no more zeek commands to fail
trap - ERR
# daemonize cron but log output to stdout
crond -b -L /dev/fd/1
# infinite loop to prevent container from exiting and allow this script to process signals
while :; do sleep 1s; done