Gentoo Archives: gentoo-commits

From: Slawek Lis <slis@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: net-analyzer/suricata/files/
Date: Tue, 27 Dec 2016 10:43:18
Message-Id: 1482835383.46b93f31143ddd9e2c0d2d45332a0feeefc3df84.slis@gentoo
1 commit: 46b93f31143ddd9e2c0d2d45332a0feeefc3df84
2 Author: Slawomir Lis <slis <AT> gentoo <DOT> org>
3 AuthorDate: Tue Dec 27 10:43:03 2016 +0000
4 Commit: Slawek Lis <slis <AT> gentoo <DOT> org>
5 CommitDate: Tue Dec 27 10:43:03 2016 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=46b93f31
7
8 net-analyzer/suricata: Updated init script
9
10 Now it's able to override config filename and point to log directory.
11 Related to #602590
12
13 Thanks to Vieri <rentorbuy <AT> yahoo.com>
14
15 Package-Manager: Portage-2.3.3, Repoman-2.3.1
16
17 net-analyzer/suricata/files/suricata-3.2-conf | 23 ++++++++++++++++++--
18 net-analyzer/suricata/files/suricata-3.2-init | 30 +++++++++++++++++++++------
19 2 files changed, 45 insertions(+), 8 deletions(-)
20
21 diff --git a/net-analyzer/suricata/files/suricata-3.2-conf b/net-analyzer/suricata/files/suricata-3.2-conf
22 index 61715ba..d900ade 100644
23 --- a/net-analyzer/suricata/files/suricata-3.2-conf
24 +++ b/net-analyzer/suricata/files/suricata-3.2-conf
25 @@ -19,9 +19,17 @@
26 # ln -s /etc/init.d/suricata /etc/init.d/suricata.q1
27 # cp /etc/suricata/suricata.yaml /etc/suricata/suricata-q0.yaml
28 # cp /etc/suricata/suricata.yaml /etc/suricata/suricata-q1.yaml
29 +#
30 # Edit both suricata-q{0,1}.yaml files and set values accordingly.
31 -#
32 -# You can then define the following options here:
33 +# You can override these yaml config file names with SURICATA_CONF* below (optional).
34 +# This allows you to use the same yaml config file for multiple instances as long as you override
35 +# sensible options such as the log file paths.
36 +# SURICATA_CONF_q0="suricata-queues.yaml"
37 +# SURICATA_CONF_q1="suricata-queues.yaml"
38 +# SURICATA_CONF="suricata.yaml"
39 +
40 +# You can define the options here:
41 +# NB: avoid using -l, -c and setting logging.outputs.1.file.filename as the init script will try to set them for you.
42
43 # SURICATA_OPTS_q0="-q 0"
44 # SURICATA_OPTS_q1="-q 1"
45 @@ -30,3 +38,14 @@
46 # then you can set:
47
48 SURICATA_OPTS="-i eth0"
49 +
50 +# Log paths listed here will be created by the init script and will override the log path
51 +# set in the yaml file, if present.
52 +# SURICATA_LOG_PATH_q0="/var/log/suricata/q0"
53 +# SURICATA_LOG_PATH_q1="/var/log/suricata/q1"
54 +# SURICATA_LOG_PATH="/var/log/suricata"
55 +# SURICATA_LOG_FILE="suricata.log"
56 +
57 +# You can view all the available options you can set with --set
58 +# and check the full config settings in an easily parsable format.
59 +# SURICATA_DUMP=1
60
61 diff --git a/net-analyzer/suricata/files/suricata-3.2-init b/net-analyzer/suricata/files/suricata-3.2-init
62 index d612815..3ec6afd 100644
63 --- a/net-analyzer/suricata/files/suricata-3.2-init
64 +++ b/net-analyzer/suricata/files/suricata-3.2-init
65 @@ -8,13 +8,17 @@ SURICATA_DIR=${SURICATA_DIR:-/etc/suricata}
66 SURICATA=${SVCNAME#*.}
67 SURICATAID=$(shell_var "${SURICATA}")
68 if [ -n "${SURICATA}" ] && [ ${SVCNAME} != "suricata" ]; then
69 - SURICATACONF="${SURICATA_DIR}/suricata-${SURICATA}.yaml"
70 + eval SURICATACONF=\$SURICATA_CONF_${SURICATAID}
71 + [ ${#SURICATACONF} -eq 0 ] && SURICATACONF="${SURICATA_DIR}/suricata-${SURICATA}.yaml" || SURICATACONF="${SURICATA_DIR}/${SURICATACONF}"
72 SURICATAPID="/var/run/suricata/suricata.${SURICATA}.pid"
73 eval SURICATAOPTS=\$SURICATA_OPTS_${SURICATAID}
74 + eval SURICATALOGPATH=\$SURICATA_LOG_PATH_${SURICATAID}
75 else
76 - SURICATACONF="${SURICATA_DIR}/suricata.yaml"
77 + SURICATACONF=${SURICATA_CONF}
78 + [ ${#SURICATACONF} -eq 0 ] && SURICATACONF="${SURICATA_DIR}/suricata.yaml" || SURICATACONF="${SURICATA_DIR}/${SURICATACONF}"
79 SURICATAPID="/var/run/suricata/suricata.pid"
80 SURICATAOPTS=${SURICATA_OPTS}
81 + SURICATALOGPATH=${SURICATA_LOG_PATH}
82 fi
83 [ -e ${SURICATACONF} ] && SURICATAOPTS="${SURICATAOPTS} -c ${SURICATACONF}"
84
85 @@ -36,6 +40,14 @@ checkconfig() {
86 if [ ! -d "/var/run/suricata" ] ; then
87 checkpath -d /var/run/suricata
88 fi
89 + if [ ${#SURICATALOGPATH} -gt 0 ]; then
90 + if [ ! -d "${SURICATALOGPATH}" ] ; then
91 + checkpath -d "${SURICATALOGPATH}"
92 + fi
93 + SURICATALOGFILE=${SURICATA_LOG_FILE:-suricata.log}
94 + SURICATAOPTS="${SURICATAOPTS} --set logging.outputs.1.file.filename=${SURICATALOGPATH}/${SURICATALOGFILE}"
95 + SURICATALOGPATH="-l ${SURICATALOGPATH}"
96 + fi
97 }
98
99 initpidinfo() {
100 @@ -65,13 +77,19 @@ checkpidinfo() {
101
102 start() {
103 checkconfig || return 1
104 + if [ $((SURICATA_DUMP)) -eq 1 ]; then
105 + einfo "Dumping ${SVCNAME} config values and quitting."
106 + ${SURICATA_BIN} --dump-config --pidfile ${SURICATAPID} ${SURICATAOPTS} ${SURICATALOGPATH}
107 + einfo "You need to disable SURICATA_DUMP to start ${SVCNAME}."
108 + return 1
109 + fi
110 ebegin "Starting ${SVCNAME}"
111 start-stop-daemon --start --quiet --exec ${SURICATA_BIN} \
112 - -- --pidfile ${SURICATAPID} -D ${SURICATAOPTS} >/dev/null 2>&1
113 + -- --pidfile ${SURICATAPID} -D ${SURICATAOPTS} ${SURICATALOGPATH} >/dev/null 2>&1
114 local SUR_EXIT=$?
115 if [ $((SUR_EXIT)) -ne 0 ]; then
116 einfo "Could not start ${SURICATA_BIN} with:"
117 - einfo "--pidfile ${SURICATAPID} -D ${SURICATAOPTS}"
118 + einfo "--pidfile ${SURICATAPID} -D ${SURICATAOPTS} ${SURICATALOGPATH}"
119 einfo "Exit code ${SUR_EXIT}"
120 fi
121 eend ${SUR_EXIT}
122 @@ -87,7 +105,7 @@ stop() {
123 while [ -e ${SURICATAPID} ] && [ $cnt -gt 0 ]; do
124 cnt=$(expr $cnt - 1)
125 sleep 1
126 - einfo -ne "$cnt seconds left before we give up checking the PID file...\r"
127 + echo -ne "$cnt seconds left before we give up checking the PID file...\r"
128 done
129 # under certain conditions suricata can be pretty slow and the PID can persist long after the pidfile has been removed
130 # max wait for process to terminate: 1 minute
131 @@ -105,7 +123,7 @@ stop() {
132 break
133 fi
134 sleep 1
135 - einfo -ne "$cnt seconds left before we give up checking PID ${SUR_PID}...\r"
136 + echo -ne "$cnt seconds left before we give up checking PID ${SUR_PID}...\r"
137 SUR_PID_CHECK="$(ps -eo pid | grep -c ${SUR_PID})"
138 done
139 fi