darkstat: procd init script and enabling additional parameters
This is to change the init script to a procd init script This also enable some additional parameters in the binary that were present but not enabled: The export file (option export_file) The import file (option import_file) The daylog (option daylog_file) These are disabled by default. Also, the option to run as a daemon is removed, as not compatible with procd. There is no change in the binary. Signed-off-by: Jean-Michel Lacroix <lacroix@lepine-lacroix.info>
This commit is contained in:
parent
f14c380333
commit
dd8f7348be
3 changed files with 67 additions and 63 deletions
|
@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=darkstat
|
PKG_NAME:=darkstat
|
||||||
PKG_VERSION:=3.0.719
|
PKG_VERSION:=3.0.719
|
||||||
PKG_RELEASE:=2
|
PKG_RELEASE:=3
|
||||||
|
|
||||||
PKG_MAINTAINER:=Jean-Michel Lacroix <lacroix@lepine-lacroix.info>
|
PKG_MAINTAINER:=Jean-Michel Lacroix <lacroix@lepine-lacroix.info>
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
config darkstat
|
config darkstat
|
||||||
option interface 'lan'
|
option interface 'lan'
|
||||||
option syslog false
|
option syslog false
|
||||||
option verbose true
|
option verbose false
|
||||||
option no_daemon false
|
|
||||||
option no_promisc false
|
option no_promisc false
|
||||||
option no_dns false
|
option no_dns false
|
||||||
option no_macs false
|
option no_macs false
|
||||||
option no_lastseen false
|
option no_lastseen false
|
||||||
# option httpaddr '0.0.0.0'
|
option httpaddr '0.0.0.0'
|
||||||
# option httpport '667'
|
# option httpport '667'
|
||||||
# option network_filter 'not (src net 192.168.1 and dst net 192.168.1)'
|
# option network_filter 'not (src net 192.168.1 and dst net 192.168.1)'
|
||||||
# option network_netmask '192.168.1.0/255.255.255.0'
|
# option network_netmask '192.168.1.0/255.255.255.0'
|
||||||
|
@ -17,4 +16,6 @@ config darkstat
|
||||||
# option ports_max '60'
|
# option ports_max '60'
|
||||||
# option ports_keep '30'
|
# option ports_keep '30'
|
||||||
# option highest_port '65534'
|
# option highest_port '65534'
|
||||||
|
# option export_file 'darkstat_export.log'
|
||||||
|
# option import_file 'darkstat_export.log'
|
||||||
|
# option daylog_file 'darkstat_daylog.log'
|
||||||
|
|
|
@ -1,97 +1,100 @@
|
||||||
#!/bin/sh /etc/rc.common
|
#!/bin/sh /etc/rc.common
|
||||||
# Copyright (C) 2007-2016 OpenWrt.org
|
# Copyright (C) 2018 Jean-Michel Lacroix
|
||||||
|
|
||||||
|
USE_PROCD=1
|
||||||
|
|
||||||
START=60
|
START=60
|
||||||
|
|
||||||
APP=darkstat
|
APP=darkstat
|
||||||
RUN_D=/var/empty
|
RUN_D=/var/empty
|
||||||
PID_F=$RUN_D/darkstat.pid
|
PID_F=$RUN_D/$APP.pid
|
||||||
|
CONFIGNAME=darkstat
|
||||||
|
USER=nobody
|
||||||
|
GROUP=nogroup
|
||||||
|
|
||||||
SYSLOG=""
|
CONFIGSTR=""
|
||||||
VERBOSE=""
|
FILTERSTR=""
|
||||||
NODAEMON=""
|
|
||||||
NOPROMISC=""
|
|
||||||
NODNS=""
|
|
||||||
NOMACS=""
|
|
||||||
NOLASTSEEN=""
|
|
||||||
LOCAL=""
|
|
||||||
paramstr=""
|
|
||||||
|
|
||||||
export_bool () {
|
export_bool () {
|
||||||
local option="$1"
|
local option="$1"
|
||||||
local section="$2"
|
local section="$2"
|
||||||
local _keystr="$3"
|
local _keystr="$3"
|
||||||
local _loctmp
|
local _loctmp
|
||||||
paramstr=""
|
|
||||||
config_get_bool _loctmp "$section" "$option"
|
config_get_bool _loctmp "$section" "$option"
|
||||||
if [ -n "$_loctmp" ]; then
|
if [ -n "$_loctmp" ]; then
|
||||||
if [ 1 -eq "$_loctmp" ]; then
|
if [ 1 -eq "$_loctmp" ]; then
|
||||||
paramstr="${_keystr} "
|
CONFIGSTRING="$CONFIGSTRING${_keystr} "
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
set_config_string(){
|
||||||
mkdir -p $RUN_D
|
mkdir -p $RUN_D
|
||||||
|
chown $USER:$GROUP $RUN_D
|
||||||
. /lib/functions/network.sh
|
. /lib/functions/network.sh
|
||||||
config_load darkstat
|
config_load $CONFIGNAME
|
||||||
config_foreach start_darkstat darkstat
|
config_foreach build_config_string darkstat
|
||||||
}
|
}
|
||||||
|
|
||||||
start_darkstat() {
|
build_config_string() {
|
||||||
local cfg="$1"
|
local cfg="$1"
|
||||||
config_get interface $cfg interface
|
config_get interface $cfg interface
|
||||||
|
network_get_device ifname "$interface"
|
||||||
|
CONFIGSTR=" -i $ifname "
|
||||||
export_bool syslog $cfg "--syslog"
|
export_bool syslog $cfg "--syslog"
|
||||||
SYSLOG=$paramstr
|
|
||||||
export_bool verbose $cfg "--verbose"
|
export_bool verbose $cfg "--verbose"
|
||||||
VERBOSE=$paramstr
|
# We need the --no-daemon parameter as with PROCD the process has to run in the background
|
||||||
export_bool no_daemon $cfg "--no-daemon"
|
CONFIGSTR="$CONFIGSTR--no-daemon "
|
||||||
NODAEMON=$paramstr
|
|
||||||
export_bool no_promisc $cfg "--no-promisc"
|
export_bool no_promisc $cfg "--no-promisc"
|
||||||
NOPROMISC=$paramstr
|
|
||||||
export_bool no_dns $cfg "--no-dns"
|
export_bool no_dns $cfg "--no-dns"
|
||||||
NODNS=$paramstr
|
|
||||||
export_bool no_macs $cfg "--no-macs"
|
export_bool no_macs $cfg "--no-macs"
|
||||||
NOMACS=$paramstr
|
|
||||||
export_bool no_lastseen $cfg "--no-lastseen"
|
export_bool no_lastseen $cfg "--no-lastseen"
|
||||||
NOLASTSEEN=$paramstr
|
|
||||||
config_get httpaddr $cfg httpaddr
|
config_get httpaddr $cfg httpaddr
|
||||||
|
CONFIGSTR="$CONFIGSTR${httpaddr:+-b "$httpaddr"} "
|
||||||
config_get httpport $cfg httpport
|
config_get httpport $cfg httpport
|
||||||
config_get network_filter $cfg network_filter
|
CONFIGSTR="$CONFIGSTR${httpport:+-p "$httpport"} "
|
||||||
config_get network_netmask $cfg network_netmask
|
config_get network_netmask $cfg network_netmask
|
||||||
|
CONFIGSTR="$CONFIGSTR${network_netmask:+-l "$network_netmask"} "
|
||||||
export_bool local_only $cfg "--local-only"
|
export_bool local_only $cfg "--local-only"
|
||||||
LOCAL=$paramstr
|
|
||||||
config_get hosts_max $cfg hosts_max
|
config_get hosts_max $cfg hosts_max
|
||||||
|
CONFIGSTR="$CONFIGSTR${hosts_max:+--hosts-max "$hosts_max"} "
|
||||||
config_get hosts_keep $cfg hosts_keep
|
config_get hosts_keep $cfg hosts_keep
|
||||||
config_get ports_max $cfg ports_max
|
CONFIGSTR="$CONFIGSTR${ports_keep:+--ports-keep "$ports_keep"} "
|
||||||
config_get ports_keep $cfg ports_keep
|
config_get highest_port $cfg highest_port
|
||||||
config_get highest_port $cfg highest_port
|
CONFIGSTR="$CONFIGSTR${highest_port:+--highest-port "$highest_port"} "
|
||||||
|
config_get export_file $cfg export_file
|
||||||
|
CONFIGSTR="$CONFIGSTR${export_file:+--export "$export_file"} "
|
||||||
network_get_device ifname "$interface" && {
|
config_get import_file $cfg import_file
|
||||||
/usr/sbin/$APP -i "$ifname" \
|
CONFIGSTR="$CONFIGSTR${import_file:+--import "$import_file"} "
|
||||||
${SYSLOG} \
|
config_get daylog_file $cfg daylog_file
|
||||||
${VERBOSE} \
|
CONFIGSTR="$CONFIGSTR${daylog_file:+--daylog "$daylog_file"} "
|
||||||
${NODAEMON} \
|
CONFIGSTR="$CONFIGSTR--chroot $RUN_D --pidfile $PID_F"
|
||||||
${NOPROMISC} \
|
# Now that we have the configuration string (CONFIGSTR), let us get the filter (FILTERSTR)
|
||||||
${NODNS} \
|
config_get network_filter $cfg network_filter
|
||||||
${NOMACS} \
|
FILTERSTR="${network_filter:+$network_filter}"
|
||||||
${NOLASTSEEN} \
|
|
||||||
${httpaddr:+-b "$httpaddr"} \
|
|
||||||
${httpport:+-p "$httpport"} \
|
|
||||||
${network_filter:+-f "$network_filter"} \
|
|
||||||
${network_netmask:+-l "$network_netmask"} \
|
|
||||||
${LOCAL} \
|
|
||||||
${hosts_max:+--hosts-max "$hosts_max"} \
|
|
||||||
${hosts_keep:+--hosts-keep "$hosts_keep"} \
|
|
||||||
${ports_max:+--ports-max "$ports_max"} \
|
|
||||||
${ports_keep:+--ports-keep "$ports_keep"} \
|
|
||||||
${highest_port:+--highest-port "$highest_port"} \
|
|
||||||
--chroot $RUN_D \
|
|
||||||
--pidfile $PID_F
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
service_triggers() {
|
||||||
start-stop-daemon -K -n $APP -p $PID_F -s TERM
|
procd_add_reload_trigger $CONFIGNAME
|
||||||
|
}
|
||||||
|
|
||||||
|
start_service() {
|
||||||
|
set_config_string
|
||||||
|
procd_open_instance
|
||||||
|
procd_set_param command /usr/sbin/$APP
|
||||||
|
procd_append_param command $CONFIGSTR
|
||||||
|
# Let us check if we have a filter string and apply it if we do
|
||||||
|
if [ "$FILTERSTR" != "" ]; then
|
||||||
|
procd_append_param command "-f" "$FILTERSTR"
|
||||||
|
fi
|
||||||
|
procd_close_instance
|
||||||
|
}
|
||||||
|
|
||||||
|
stop_service() {
|
||||||
rm -f $PID_F
|
rm -f $PID_F
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reload_service() {
|
||||||
|
stop
|
||||||
|
start
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue