Skip to content
This repository was archived by the owner on Feb 19, 2020. It is now read-only.

Commit 7d2f5cf

Browse files
committed
start bro in FireMain
1 parent 4e76c63 commit 7d2f5cf

23 files changed

+302
-141
lines changed

buildraw

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function install_walla()
8989

9090
sudo cp $basedir/etc/sysctl.conf /etc/sysctl.conf || perr_and_exit "Failed to replace system sysctl.conf."
9191
sudo cp $basedir/etc/bro-cron /etc/cron.hourly/. || perr_and_exit "Failed to install root bron cronjobs."
92-
crontab $basedir/etc/brotab || perr_and_exit "Failed to install user bro cronjobs."
92+
crontab $basedir/etc/crontab || perr_and_exit "Failed to install user bro cronjobs."
9393

9494
echo "Setting up encipher..."
9595
sudo mkdir -p /encipher.config || perr_and_exit "Failed to create /encipher.config/"

buildraw4

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ function install_walla()
125125
fi
126126
sudo cp $basedir/etc/sysctl.conf /etc/sysctl.conf || perr_and_exit "Failed to replace system sysctl.conf."
127127
sudo cp $basedir/etc/bro-cron /etc/cron.hourly/. || perr_and_exit "Failed to install root bron cronjobs."
128-
crontab $basedir/etc/brotab || perr_and_exit "Failed to install user bro cronjobs."
128+
crontab $basedir/etc/crontab || perr_and_exit "Failed to install user bro cronjobs."
129129

130130
# Enable BBR TCP congestion control
131131
grep "tcp_bbr" /etc/modules-load.d/modules.conf >/dev/null 2>&1

buildraw_aarch64.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function install_walla() {
126126
fi
127127
sudo cp $basedir/etc/sysctl.conf /etc/sysctl.conf || perr_and_exit "Failed to replace system sysctl.conf."
128128
sudo cp $basedir/etc/bro-cron /etc/cron.hourly/. || perr_and_exit "Failed to install root bron cronjobs."
129-
crontab $basedir/etc/brotab || perr_and_exit "Failed to install user bro cronjobs."
129+
crontab $basedir/etc/crontab || perr_and_exit "Failed to install user bro cronjobs."
130130

131131
# Enable BBR TCP congestion control
132132
grep "tcp_bbr" /etc/modules-load.d/modules.conf >/dev/null 2>&1

etc/bro-bro-check

+5-16
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
11
#!/bin/bash
22
sync
33

4-
bro_process_cnt=`ps -ef |grep "broctl/standalone broctl/auto" | grep -v grep | wc -l`
5-
if [[ $bro_process_cnt < 3 ]]; then
4+
: ${FIREWALLA_HOME:=/home/pi/firewalla}
5+
source ${FIREWALLA_HOME}/platform/platform.sh
6+
7+
bro_process_cnt=`ps -ef |grep "$(bro_proc_name)ctl/auto" | grep -v grep | wc -l`
8+
if [[ $bro_process_cnt -lt 3 ]]; then
69
logger 'FIREWALLA: bro-quick-cron: bro restart due to bro vanished'
710
sudo service brofish stop
811
sudo service brofish start
912
fi
10-
11-
redis_process_cnt=`sudo systemctl status redis-server |grep 'active (running)' | wc -l`
12-
13-
if [[ $redis_process_cnt = 0 ]]; then
14-
/usr/bin/logger "FIREWALLA PING: REDIS GOING DOWN"
15-
sleep 10
16-
redis_process_cnt=`sudo systemctl status redis-server |grep 'active (running)' | wc -l`
17-
if [[ $redis_process_cnt = 0 ]]; then
18-
sudo rm -r -f /var/log/redis/*
19-
/usr/bin/logger "REBOOT: FIREWALLA PING NO REDIS"
20-
/home/pi/firewalla/scripts/fire-reboot
21-
exit 0
22-
fi
23-
fi

etc/bro-cron2

+3-18
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,12 @@ sync
55
/usr/bin/sudo /bin/rm -r -f /bspool/tmp/*
66
#node /home/pi/firewalla/scripts/clean-redis.js &
77

8-
bro_process_cnt=`ps -ef |grep "broctl/standalone broctl/auto" | grep -v grep | wc -l`
9-
logger "detected bro process count:$bro_process_cnt"
10-
if [[ $bro_process_cnt < 3 ]]; then
11-
logger 'FIREWALLA: bro restart due to bro vanished'
12-
sudo service brofish stop
13-
sudo service brofish start
14-
fi
15-
16-
#forever_process_cnt=`forever list | grep "STOPPED" | grep -v grep | wc -l`
17-
#if [[ $forever_process_cnt > 0 ]]; then
18-
# logger 'FIREWALLA: forever process STOPPED'
19-
# forever list | logger
20-
# forever restartall
21-
#fi
22-
238
ui_process_cnt=`sudo systemctl status fireui | grep 'active (running)' | wc -l`
249
kickui_process_cnt=`sudo systemctl status firekick |grep 'active (running)' | wc -l`
2510
api_process_cnt=`sudo systemctl status fireapi |grep 'active (running)' | wc -l`
26-
if [[ $ui_process_cnt <1 ]]; then
27-
if [[ $kickui_process_cnt < 1 ]]; then
28-
if [[ $api_process_cnt < 1 ]]; then
11+
if [[ $ui_process_cnt -lt 1 ]]; then
12+
if [[ $kickui_process_cnt -lt 1 ]]; then
13+
if [[ $api_process_cnt -lt 1 ]]; then
2914
logger 'FIREWALLA: no ui process'
3015
fi
3116
fi

etc/brotab

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ SHELL=/bin/bash
22
*/15 * * * * /home/pi/firewalla/etc/bro-cron2 >/dev/null 2>&1
33
*/1 * * * * /home/pi/firewalla/etc/bro-mem-check >/dev/null 2>&1
44
*/3 * * * * /home/pi/firewalla/etc/bro-bro-check >/dev/null 2>&1
5+
*/3 * * * * /home/pi/firewalla/etc/redis-check >/dev/null 2>&1
56
0 0 */5 * * /home/pi/firewalla/scripts/scheduled_reboot.sh &>/dev/null
67
0 0 1-31/2 * * /home/pi/firewalla/scripts/clean-log >/dev/null 2>&1
78
* * * * * for x in $(seq 0 10 50); do ( sleep $x; flock -n /dev/shm/fire-ping.lock -c "timeout 30 /home/pi/scripts/fire-ping.sh &>/dev/null") & done

etc/crontab

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
SHELL=/bin/bash
2+
*/3 * * * * /home/pi/firewalla/etc/redis-check >/dev/null 2>&1
3+
0 0 */5 * * /home/pi/firewalla/scripts/scheduled_reboot.sh &>/dev/null
4+
0 0 1-31/2 * * /home/pi/firewalla/scripts/clean-log >/dev/null 2>&1
5+
* * * * * for x in $(seq 0 10 50); do ( sleep $x; flock -n /dev/shm/fire-ping.lock -c "timeout 30 /home/pi/scripts/fire-ping.sh &>/dev/null") & done
6+
*/5 * * * * ( /home/pi/firewalla/scripts/bitbridge-ping.sh >/dev/null 2>&1 )
7+
*/2 * * * * ( /home/pi/firewalla/scripts/fireapi-ping.sh >/dev/null 2>&1 )
8+
*/10 * * * * ( /home/pi/firewalla/scripts/firemain-ping.sh >/dev/null 2>&1 )
9+
*/5 * * * * ( /home/pi/firewalla/scripts/firemon-ping.sh >/dev/null 2>&1 )
10+
*/2 * * * * ( /home/pi/firewalla/scripts/brofish-ping.sh >/dev/null 2>&1 )
11+
0 2 * * * ( sleep $(( ${RANDOM} * 120 / 32768 ))m ; /home/pi/firewalla/scripts/fireupgrade_check.sh >/tmp/fireupgrade.log 2>&1 )
12+
*/5 * * * * logger "Firewalla checkpoint every 5 mins" &>/dev/null
13+
*/30 * * * * /home/pi/firewalla/scripts/free-memory &>/dev/null
14+
0 * * * * /home/pi/firewalla/scripts/health_check.sh &> /tmp/health_check.log
15+
0 0 * * * ( sleep $(( ${RANDOM} * 720 / 32768 ))m ; timeout 30 /home/pi/firewalla/scripts/diag_hello.sh &>/dev/null)

etc/node.cluster.cfg

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Example ZeekControl node configuration.
2+
#
3+
# This example has a standalone node ready to go except for possibly changing
4+
# the sniffing interface.
5+
6+
# This is a complete standalone configuration. Most likely you will
7+
# only need to change the interface.
8+
#[zeek]
9+
#type=standalone
10+
#host=localhost
11+
#interface=br0
12+
13+
## Below is an example clustered configuration. If you use this,
14+
## remove the [zeek] node above.
15+
16+
[logger]
17+
type=logger
18+
host=localhost
19+
20+
[manager]
21+
type=manager
22+
host=localhost
23+
24+
[proxy-1]
25+
type=proxy
26+
host=localhost

etc/redis-check

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
sync
3+
4+
redis_process_cnt=`sudo systemctl status redis-server |grep 'active (running)' | wc -l`
5+
if [[ $redis_process_cnt -eq 0 ]]; then
6+
/usr/bin/logger "FIREWALLA PING: REDIS GOING DOWN"
7+
sleep 10
8+
redis_process_cnt=`sudo systemctl status redis-server |grep 'active (running)' | wc -l`
9+
if [[ $redis_process_cnt -eq 0 ]]; then
10+
sudo rm -r -f /var/log/redis/*
11+
/usr/bin/logger "REBOOT: FIREWALLA PING NO REDIS"
12+
/home/pi/firewalla/scripts/fire-reboot
13+
exit 0
14+
fi
15+
fi

net2/BroControl.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/* Copyright 2019 Firewalla Inc.
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU Affero General Public License, version 3,
5+
* as published by the Free Software Foundation.
6+
*
7+
* This program is distributed in the hope that it will be useful,
8+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
* GNU Affero General Public License for more details.
11+
*
12+
* You should have received a copy of the GNU Affero General Public License
13+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
14+
*/
15+
16+
'use strict';
17+
18+
const log = require("./logger.js")(__filename);
19+
const f = require('./Firewalla.js')
20+
21+
const exec = require('child-process-promise')
22+
const util = require('util')
23+
const fs = require('fs')
24+
const appendFile = util.promisify(fs.appendFile)
25+
26+
const PATH_NODE_CFG = `/usr/local/bro/etc/node.cfg`
27+
28+
class BroControl {
29+
30+
async writeClusterConfig(monitoringInterfaces) {
31+
// rewrite cluster node.cfg
32+
await exec(`sudo cp -f ${f.getFirewallaHome}/etc/node.cluster.cfg ${PATH_NODE_CFG}`)
33+
34+
let workerCfg = []
35+
let index = 1
36+
for (const intf of monitoringInterfaces) {
37+
workerCfg.push(
38+
`\n`,
39+
`[worker-${index++}]\n`,
40+
`type=worker\n`,
41+
`host=localhost\n`,
42+
`interface=${intf}\n`,
43+
)
44+
}
45+
await appendFile(PATH_NODE_CFG, workerCfg.join(''))
46+
}
47+
48+
async addCronJobs() {
49+
await exec('sudo -u pi crontab -r; sudo -u pi crontab /home/pi/firewalla/etc/crontab')
50+
}
51+
52+
async start() {
53+
exec(`sudo systemctl start brofish`)
54+
}
55+
56+
async restart() {
57+
exec(`sudo systemctl restart brofish`)
58+
}
59+
60+
}
61+
62+
module.exports = new BroControl

0 commit comments

Comments
 (0)