Commit 1f2a404f authored by Adam Wujek's avatar Adam Wujek 💬

Merge branch 'adam-log'

parents 23781a79 b64d15f1
...@@ -97,6 +97,29 @@ config WRS_LOG_PTP ...@@ -97,6 +97,29 @@ config WRS_LOG_PTP
to represent no logging (like /dev/null). Please note that to represent no logging (like /dev/null). Please note that
unknown facility names will generate a runtime error on the switch. unknown facility names will generate a runtime error on the switch.
config WRS_LOG_SNMPD
string "Logging directions for the SNMP daemon"
default "sd"
help
The string can be a pathname (e.g. /dev/kmsg) or a valid snmpd log
option (without -L). "sd" or "s daemon" will forward messages to
syslog with daemon as facility. To set level (i.e. 5) use
"S 5 daemon". For details please check "man snmpcmd". An empty
strings is used to represent no logging (like /dev/null). Please
note that unknown facility names will generate a runtime error on the
switch.
config WRS_LOG_MONIT
string "Logging directions for the monit"
default "syslog"
help
The string can be a pathname (e.g. /dev/kmsg) or a "syslog" string.
An empty strings is used to represent no logging. If it is needed to
select facility and level please leave here empty string and change
/etc/monitrc file directly.
Please note that unknown facility names will generate a runtime error
on the switch.
config KEEP_ROOTFS config KEEP_ROOTFS
bool "Keep generated filesystem and related script" bool "Keep generated filesystem and related script"
help help
......
...@@ -472,7 +472,7 @@ value is changed by the web interface, proper action is taken. ...@@ -472,7 +472,7 @@ value is changed by the web interface, proper action is taken.
Supply Right (PSR) temperature sensors. When any temperature exceeds Supply Right (PSR) temperature sensors. When any temperature exceeds
threshold level SNMP object @t{WR-SWITCH-MIB::tempWarning} will change threshold level SNMP object @t{WR-SWITCH-MIB::tempWarning} will change
accordingly. accordingly.
@item CONFIG_WRS_LOG_HAL @item CONFIG_WRS_LOG_HAL
@itemx CONFIG_WRS_LOG_RTU @itemx CONFIG_WRS_LOG_RTU
@itemx CONFIG_WRS_LOG_PTP @itemx CONFIG_WRS_LOG_PTP
...@@ -485,6 +485,28 @@ value is changed by the web interface, proper action is taken. ...@@ -485,6 +485,28 @@ value is changed by the web interface, proper action is taken.
unknown facility names will generate a runtime error on the switch. unknown facility names will generate a runtime error on the switch.
All three strings default to ``@t{daemon.info}''. All three strings default to ``@t{daemon.info}''.
@item CONFIG_WRS_LOG_SNMPD
Value can be a pathname, to select logging to file (and
@t{/dev/kmsg} is a possible ``file'' target) or a valid snmpd log
option (without -L).
Allowed strings are in format ``@t{s} @i{facility}'' (e.g.
``@t{s daemon}'') and ``@t{s} @i{level} @i{facility}'' (e.g.
``@t{s 2 daemon}''). For example, ``@t{sd}'' or ``@t{s daemon}'' will forward
messages to syslog with daemon as facility. To set level (i.e. 5) use
``@t{S 5 daemon}''. For details please check ``man snmpcmd''. An empty
strings selects no logging at all. Please note that unknown facility
names will generate a runtime error on the switch.
@item CONFIG_WRS_LOG_MONIT
The string can be a pathname (e.g. @t{/dev/kmsg}) or a @t{syslog}
string.
An empty string is used to represent no logging. If it is needed to
select facility and level please leave here empty string and change
@t{/etc/monitrc} file directly.
Please note that unknown facility names will generate a runtime error
on the switch.
@item CONFIG_PORT00_PARAMS @item CONFIG_PORT00_PARAMS
@itemx CONFIG_PORT01_PARAMS @itemx CONFIG_PORT01_PARAMS
@itemx ... @itemx ...
......
...@@ -52,9 +52,21 @@ init() { ...@@ -52,9 +52,21 @@ init() {
fi fi
if [ -z "$CONFIG_MONIT_DISABLE" ]; then if [ -z "$CONFIG_MONIT_DISABLE" ]; then
if [ -z $CONFIG_WRS_LOG_MONIT ]; then
LOG="";
elif echo "$CONFIG_WRS_LOG_MONIT" | grep / > /dev/null; then
# if a pathname, use it
LOG="-l $CONFIG_WRS_LOG_MONIT";
else
# not a pathname, monit cannot take facility nor level from command
# line, only possible from configuration file
LOG="-l syslog"
fi
echo "Start monit" echo "Start monit"
# start monit # start monit
/usr/bin/monit /usr/bin/monit $LOG
else else
echo "Monit disabled in dot-config" echo "Monit disabled in dot-config"
loop_forever loop_forever
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
SNMP_PID=/var/run/snmpd.pid SNMP_PID=/var/run/snmpd.pid
SNMP_CONF=/wr/etc/snmpd.conf SNMP_CONF=/wr/etc/snmpd.conf
dotconfig=/wr/etc/dot-config
start_counter() { start_counter() {
# increase boot counter # increase boot counter
...@@ -17,9 +18,29 @@ start_counter() { ...@@ -17,9 +18,29 @@ start_counter() {
start() { start() {
echo -n "Starting snmpd daemon: " echo -n "Starting snmpd daemon: "
# Log to syslog at daemon level. And log source address (-a)
if [ -f "$dotconfig" ]; then
. "$dotconfig"
else
echo "$0 unable to source dot-config ($dotconfig)!"
fi
WRS_LOG=$CONFIG_WRS_LOG_SNMPD
if [ -z "$WRS_LOG" ]; then
LOG="";
elif echo "$WRS_LOG" | grep / > /dev/null; then
# if a pathname, use it
LOG="-Lf $WRS_LOG";
else
# not a pathname: use verbatim
LOG="-L$WRS_LOG"
fi
# Log source address (-a)
start-stop-daemon -q -p $SNMP_PID -S \ start-stop-daemon -q -p $SNMP_PID -S \
--exec /usr/sbin/snmpd -- -Lsd -p $SNMP_PID -a -c $SNMP_CONF --exec /usr/sbin/snmpd -- $LOG -p $SNMP_PID -a -c $SNMP_CONF
ret=$? ret=$?
if [ $ret -eq 0 ]; then if [ $ret -eq 0 ]; then
start_counter start_counter
...@@ -43,6 +64,8 @@ stop() { ...@@ -43,6 +64,8 @@ stop() {
restart() { restart() {
stop stop
# give time to snmpd to stop
sleep 1
start start
} }
......
#!/bin/ash #!/bin/ash
export WR_HOME="/wr" export WR_HOME="/wr"
echo "Killing deamon" echo "Killing daemon"
killall wrsw_hal killall wrsw_hal
killall wrsw_rtud killall wrsw_rtud
killall ptpd killall ptpd
......
...@@ -696,9 +696,9 @@ wrsBootUserspaceDaemonsMissing OBJECT-TYPE ...@@ -696,9 +696,9 @@ wrsBootUserspaceDaemonsMissing OBJECT-TYPE
MAX-ACCESS read-only MAX-ACCESS read-only
STATUS current STATUS current
DESCRIPTION DESCRIPTION
"Checking if all desired deamons are running. "Checking if all desired daemons are running.
allDeamonsPresent - all deamons running allDeamonsPresent - all daemons running
other numbers represent number of deamons not running other numbers represent number of daemons not running
other errors (can be: unable to run ps command or problem with multiple process instances) other errors (can be: unable to run ps command or problem with multiple process instances)
are reported as maximum number of missing modules" are reported as maximum number of missing modules"
::= { wrsBootStatusGroup 14 } ::= { wrsBootStatusGroup 14 }
...@@ -925,7 +925,7 @@ wrsStartCntHAL OBJECT-TYPE ...@@ -925,7 +925,7 @@ wrsStartCntHAL OBJECT-TYPE
MAX-ACCESS read-only MAX-ACCESS read-only
STATUS current STATUS current
DESCRIPTION DESCRIPTION
"Number of HAL deamon starts" "Number of HAL daemon starts"
::= { wrsStartCntGroup 1 } ::= { wrsStartCntGroup 1 }
wrsStartCntPPSI OBJECT-TYPE wrsStartCntPPSI OBJECT-TYPE
...@@ -933,7 +933,7 @@ wrsStartCntPPSI OBJECT-TYPE ...@@ -933,7 +933,7 @@ wrsStartCntPPSI OBJECT-TYPE
MAX-ACCESS read-only MAX-ACCESS read-only
STATUS current STATUS current
DESCRIPTION DESCRIPTION
"Number of PPSI deamon starts" "Number of PPSI daemon starts"
::= { wrsStartCntGroup 2 } ::= { wrsStartCntGroup 2 }
wrsStartCntRTUd OBJECT-TYPE wrsStartCntRTUd OBJECT-TYPE
...@@ -941,7 +941,7 @@ wrsStartCntRTUd OBJECT-TYPE ...@@ -941,7 +941,7 @@ wrsStartCntRTUd OBJECT-TYPE
MAX-ACCESS read-only MAX-ACCESS read-only
STATUS current STATUS current
DESCRIPTION DESCRIPTION
"Number of RTU deamon starts" "Number of RTU daemon starts"
::= { wrsStartCntGroup 3 } ::= { wrsStartCntGroup 3 }
wrsStartCntSshd OBJECT-TYPE wrsStartCntSshd OBJECT-TYPE
...@@ -949,7 +949,7 @@ wrsStartCntSshd OBJECT-TYPE ...@@ -949,7 +949,7 @@ wrsStartCntSshd OBJECT-TYPE
MAX-ACCESS read-only MAX-ACCESS read-only
STATUS current STATUS current
DESCRIPTION DESCRIPTION
"Nmber of SSH deamon starts" "Nmber of SSH daemon starts"
::= { wrsStartCntGroup 4 } ::= { wrsStartCntGroup 4 }
wrsStartCntHttpd OBJECT-TYPE wrsStartCntHttpd OBJECT-TYPE
...@@ -957,7 +957,7 @@ wrsStartCntHttpd OBJECT-TYPE ...@@ -957,7 +957,7 @@ wrsStartCntHttpd OBJECT-TYPE
MAX-ACCESS read-only MAX-ACCESS read-only
STATUS current STATUS current
DESCRIPTION DESCRIPTION
"Nmber of HTTP deamon starts" "Nmber of HTTP daemon starts"
::= { wrsStartCntGroup 5 } ::= { wrsStartCntGroup 5 }
wrsStartCntSnmpd OBJECT-TYPE wrsStartCntSnmpd OBJECT-TYPE
...@@ -965,7 +965,7 @@ wrsStartCntSnmpd OBJECT-TYPE ...@@ -965,7 +965,7 @@ wrsStartCntSnmpd OBJECT-TYPE
MAX-ACCESS read-only MAX-ACCESS read-only
STATUS current STATUS current
DESCRIPTION DESCRIPTION
"Nmber of SNMP deamon starts" "Nmber of SNMP daemon starts"
::= { wrsStartCntGroup 6 } ::= { wrsStartCntGroup 6 }
wrsStartCntSyslogd OBJECT-TYPE wrsStartCntSyslogd OBJECT-TYPE
...@@ -973,7 +973,7 @@ wrsStartCntSyslogd OBJECT-TYPE ...@@ -973,7 +973,7 @@ wrsStartCntSyslogd OBJECT-TYPE
MAX-ACCESS read-only MAX-ACCESS read-only
STATUS current STATUS current
DESCRIPTION DESCRIPTION
"Nmber of SYSLOG deamon starts" "Nmber of SYSLOG daemon starts"
::= { wrsStartCntGroup 7 } ::= { wrsStartCntGroup 7 }
-- wrsSpllState (.7.3) -- wrsSpllState (.7.3)
......
...@@ -61,21 +61,21 @@ static struct wrs_km_item kernel_modules[] = { ...@@ -61,21 +61,21 @@ static struct wrs_km_item kernel_modules[] = {
[6] = {"g_serial"}, [6] = {"g_serial"},
}; };
/* user space deamon list item */ /* user space daemon list item */
struct wrs_usd_item { struct wrs_usd_item {
char *key; /* process name */ char *key; /* process name */
int32_t exp; /* expected number of processes */ int32_t exp; /* expected number of processes */
uint32_t cnt; /* number of processes found */ uint32_t cnt; /* number of processes found */
}; };
/* user space deamon list */ /* user space daemon list */
/* - key contain process name reported by ps command /* - key contain process name reported by ps command
* - positive exp describe exact number of expected processes * - positive exp describe exact number of expected processes
* - negative exp describe minimum number of expected processes. Usefull for * - negative exp describe minimum number of expected processes. Usefull for
* processes that is hard to predict number of their instances. For example * processes that is hard to predict number of their instances. For example
* new dropbear process is spawned at ssh login. * new dropbear process is spawned at ssh login.
*/ */
static struct wrs_usd_item userspace_deamons[] = { static struct wrs_usd_item userspace_daemons[] = {
[0] = {.key = "/usr/sbin/dropbear", .exp = -1}, /* expect at least one [0] = {.key = "/usr/sbin/dropbear", .exp = -1}, /* expect at least one
* dropbear process */ * dropbear process */
[1] = {"/wr/bin/wrsw_hal", 2}, /* two wrsw_hal instances */ [1] = {"/wr/bin/wrsw_hal", 2}, /* two wrsw_hal instances */
...@@ -381,8 +381,8 @@ static void get_loaded_kernel_modules_status(void) ...@@ -381,8 +381,8 @@ static void get_loaded_kernel_modules_status(void)
fclose(f); fclose(f);
} }
/* check if deamons from userspace_deamons array are running */ /* check if daemons from userspace_daemons array are running */
static void get_deamons_status(void) static void get_daemons_status(void)
{ {
FILE *f; FILE *f;
char key[41]; /* 1 for null char */ char key[41]; /* 1 for null char */
...@@ -391,9 +391,9 @@ static void get_deamons_status(void) ...@@ -391,9 +391,9 @@ static void get_deamons_status(void)
int processes_wrong = 0; /* number of too many or too few processes */ int processes_wrong = 0; /* number of too many or too few processes */
/* clear user space deamon counters */ /* clear user space daemon counters */
for (i = 0; i < ARRAY_SIZE(userspace_deamons); i++) { for (i = 0; i < ARRAY_SIZE(userspace_daemons); i++) {
userspace_deamons[i].cnt = 0; userspace_daemons[i].cnt = 0;
} }
/* Use ps command to get process list, more portable, less error prone /* Use ps command to get process list, more portable, less error prone
...@@ -405,11 +405,11 @@ static void get_deamons_status(void) ...@@ -405,11 +405,11 @@ static void get_deamons_status(void)
wrsBootStatus_s.wrsBootUserspaceDaemonsMissing = 0; wrsBootStatus_s.wrsBootUserspaceDaemonsMissing = 0;
/* Notify snmp about error in processes list */ /* Notify snmp about error in processes list */
/* Count number of expected processes */ /* Count number of expected processes */
for (i = 0; i < ARRAY_SIZE(userspace_deamons); i++) { for (i = 0; i < ARRAY_SIZE(userspace_daemons); i++) {
/* when exp < 0 then expect at least number of /* when exp < 0 then expect at least number of
* -exp processes */ * -exp processes */
wrsBootStatus_s.wrsBootUserspaceDaemonsMissing += wrsBootStatus_s.wrsBootUserspaceDaemonsMissing +=
abs(userspace_deamons[i].exp); abs(userspace_daemons[i].exp);
} }
return; return;
...@@ -423,31 +423,31 @@ static void get_deamons_status(void) ...@@ -423,31 +423,31 @@ static void get_deamons_status(void)
if (ret != 1) if (ret != 1)
continue; /* error... or EOF */ continue; /* error... or EOF */
for (i = 0; i < ARRAY_SIZE(userspace_deamons); i++) { for (i = 0; i < ARRAY_SIZE(userspace_daemons); i++) {
if (strncmp(key, userspace_deamons[i].key, 40)) if (strncmp(key, userspace_daemons[i].key, 40))
continue; continue;
userspace_deamons[i].cnt++; userspace_daemons[i].cnt++;
break; break;
} }
} }
for (i = 0; i < ARRAY_SIZE(userspace_deamons); i++) { for (i = 0; i < ARRAY_SIZE(userspace_daemons); i++) {
if (userspace_deamons[i].exp < 0) { if (userspace_daemons[i].exp < 0) {
/* if exp < 0 then expect at least -exp processes, /* if exp < 0 then expect at least -exp processes,
* useful in situation when we cannot predict exact * useful in situation when we cannot predict exact
* number of processes. * number of processes.
* NOTE: exp in this case is negative number */ * NOTE: exp in this case is negative number */
/* saturate cnt */ /* saturate cnt */
if (userspace_deamons[i].cnt > (-userspace_deamons[i].exp)) { if (userspace_daemons[i].cnt > (-userspace_daemons[i].exp)) {
userspace_deamons[i].cnt = userspace_daemons[i].cnt =
(-userspace_deamons[i].exp); (-userspace_daemons[i].exp);
} }
} }
/* Calculate delta between expected and counted number /* Calculate delta between expected and counted number
* of processes. Neither too much or too few are ok. * of processes. Neither too much or too few are ok.
* NOTE: abs "exp" too */ * NOTE: abs "exp" too */
processes_wrong += abs(abs(userspace_deamons[i].exp) processes_wrong += abs(abs(userspace_daemons[i].exp)
- userspace_deamons[i].cnt); - userspace_daemons[i].cnt);
} }
/* save number of processes missing */ /* save number of processes missing */
...@@ -480,8 +480,8 @@ time_t wrsBootStatus_data_fill(void) ...@@ -480,8 +480,8 @@ time_t wrsBootStatus_data_fill(void)
/* get loaded kernel modules */ /* get loaded kernel modules */
get_loaded_kernel_modules_status(); get_loaded_kernel_modules_status();
/* get info about running deamons */ /* get info about running daemons */
get_deamons_status(); get_daemons_status();
/* there was an update, return current time */ /* there was an update, return current time */
return time_update; return time_update;
......
...@@ -80,7 +80,7 @@ time_t wrsOSStatus_data_fill(void) ...@@ -80,7 +80,7 @@ time_t wrsOSStatus_data_fill(void)
|| b->wrsBootLoadLM32 == WRS_BOOT_LOAD_LM32_ERROR || b->wrsBootLoadLM32 == WRS_BOOT_LOAD_LM32_ERROR
|| b->wrsBootLoadLM32 == WRS_BOOT_LOAD_LM32_FILE_NOT_FOUND || b->wrsBootLoadLM32 == WRS_BOOT_LOAD_LM32_FILE_NOT_FOUND
|| b->wrsBootKernelModulesMissing > 0 /* contain number of missing modules */ || b->wrsBootKernelModulesMissing > 0 /* contain number of missing modules */
|| b->wrsBootUserspaceDaemonsMissing > 0 /* contain number of missing deamons */ || b->wrsBootUserspaceDaemonsMissing > 0 /* contain number of missing daemons */
) { ) {
wrsOSStatus_s.wrsBootSuccessful = WRS_BOOT_SUCCESSFUL_ERROR; wrsOSStatus_s.wrsBootSuccessful = WRS_BOOT_SUCCESSFUL_ERROR;
......
...@@ -69,7 +69,7 @@ static int hal_shutdown() ...@@ -69,7 +69,7 @@ static int hal_shutdown()
return 0; return 0;
} }
static void hal_deamonize(); static void hal_daemonize();
/* Main initialization function */ /* Main initialization function */
static int hal_init() static int hal_init()
...@@ -105,13 +105,13 @@ static int hal_init() ...@@ -105,13 +105,13 @@ static int hal_init()
shw_io_write(shw_io_led_state_g, 1); shw_io_write(shw_io_led_state_g, 1);
if (daemon_mode) if (daemon_mode)
hal_deamonize(); hal_daemonize();
return 0; return 0;
} }
/* Turns a nice and well-behaving HAL into an evil servant of satan. */ /* Turns a nice and well-behaving HAL into an evil servant of satan. */
static void hal_deamonize() static void hal_daemonize()
{ {
pid_t pid, sid; pid_t pid, sid;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment