contrib/package/freifunk-watchdog:
- lower watchdog poll interval to 10 seconds (fixes reboot porblems on rb532) - prevent unneeded config reloads (happens when no wireless device is active) - remove not working watchdog stop workaround (no driver can cope with 3600) - bump pkg revision
This commit is contained in:
parent
216937af29
commit
c6a29c1a08
3 changed files with 93 additions and 91 deletions
|
@ -8,7 +8,7 @@
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=freifunk-watchdog
|
PKG_NAME:=freifunk-watchdog
|
||||||
PKG_RELEASE:=4
|
PKG_RELEASE:=5
|
||||||
|
|
||||||
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
|
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
|
||||||
PKG_BUILD_DEPENDS := uci
|
PKG_BUILD_DEPENDS := uci
|
||||||
|
|
|
@ -31,14 +31,6 @@ static void shutdown_watchdog(int sig)
|
||||||
{
|
{
|
||||||
syslog(LOG_INFO, "Stopping watchdog timer");
|
syslog(LOG_INFO, "Stopping watchdog timer");
|
||||||
write(wdfd, &wshutdown, 1);
|
write(wdfd, &wshutdown, 1);
|
||||||
|
|
||||||
/* Older Kamikaze versions are compiled with
|
|
||||||
* CONFIG_WATCHDOG_NOWAYOUT=y, this can be
|
|
||||||
* harmful if we're in the middle of an upgrade.
|
|
||||||
* Increase the watchdog timeout to 3600 seconds
|
|
||||||
* here to avoid unplanned reboots. */
|
|
||||||
ioctl(wdfd, WDIOC_SETTIMEOUT, &wdelay);
|
|
||||||
|
|
||||||
close(wdfd);
|
close(wdfd);
|
||||||
wdfd = -1;
|
wdfd = -1;
|
||||||
}
|
}
|
||||||
|
@ -191,11 +183,9 @@ static int check_uci_update(const char *config, time_t *mtime)
|
||||||
*mtime = s.st_mtime;
|
*mtime = s.st_mtime;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add tuple */
|
/* Add tuple */
|
||||||
|
@ -290,7 +280,7 @@ static wifi_tuple_t * load_wifi_uci(wifi_tuple_t *ifs, time_t *modtime)
|
||||||
static int do_daemon(void)
|
static int do_daemon(void)
|
||||||
{
|
{
|
||||||
static int wdtrigger = 1;
|
static int wdtrigger = 1;
|
||||||
static int wdtimeout = INTERVAL * 2;
|
static int wdtimeout = BASE_INTERVAL * 2;
|
||||||
static const char wdkeepalive = WATCH_KEEPALIVE;
|
static const char wdkeepalive = WATCH_KEEPALIVE;
|
||||||
|
|
||||||
int iwfd;
|
int iwfd;
|
||||||
|
@ -301,6 +291,7 @@ static int do_daemon(void)
|
||||||
wifi_tuple_t *ifs = NULL, *curif;
|
wifi_tuple_t *ifs = NULL, *curif;
|
||||||
time_t modtime = 0;
|
time_t modtime = 0;
|
||||||
|
|
||||||
|
int action_intv = 0;
|
||||||
int restart_wifi = 0;
|
int restart_wifi = 0;
|
||||||
int restart_cron = 0;
|
int restart_cron = 0;
|
||||||
int restart_sshd = 0;
|
int restart_sshd = 0;
|
||||||
|
@ -320,7 +311,7 @@ static int do_daemon(void)
|
||||||
if( (wdfd = open(WATCH_DEVICE, O_WRONLY)) > -1 )
|
if( (wdfd = open(WATCH_DEVICE, O_WRONLY)) > -1 )
|
||||||
{
|
{
|
||||||
syslog(LOG_INFO, "Opened %s - polling every %i seconds",
|
syslog(LOG_INFO, "Opened %s - polling every %i seconds",
|
||||||
WATCH_DEVICE, INTERVAL);
|
WATCH_DEVICE, BASE_INTERVAL);
|
||||||
|
|
||||||
/* Install signal handler to halt watchdog on shutdown */
|
/* Install signal handler to halt watchdog on shutdown */
|
||||||
sa.sa_handler = shutdown_watchdog;
|
sa.sa_handler = shutdown_watchdog;
|
||||||
|
@ -338,98 +329,106 @@ static int do_daemon(void)
|
||||||
|
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
/* Check average load */
|
/* Check/increment action interval */
|
||||||
if( find_loadavg() >= LOAD_TRESHOLD )
|
if( ++action_intv >= ACTION_INTERVAL )
|
||||||
loadavg_panic++;
|
|
||||||
else
|
|
||||||
loadavg_panic = 0;
|
|
||||||
|
|
||||||
/* Check crond */
|
|
||||||
if( find_process("crond") < 0 )
|
|
||||||
restart_cron++;
|
|
||||||
else
|
|
||||||
restart_cron = 0;
|
|
||||||
|
|
||||||
/* Check SSHd */
|
|
||||||
if( find_process("dropbear") < 0 )
|
|
||||||
restart_sshd++;
|
|
||||||
else
|
|
||||||
restart_sshd = 0;
|
|
||||||
|
|
||||||
/* Check wireless interfaces */
|
|
||||||
ifs = load_wifi_uci(ifs, &modtime);
|
|
||||||
for( curif = ifs; curif; curif = curif->next )
|
|
||||||
{
|
{
|
||||||
/* Get current channel and bssid */
|
/* Reset action interval */
|
||||||
if( (iw_get_bssid(iwfd, curif->ifname, bssid) == 0) &&
|
action_intv = 0;
|
||||||
|
|
||||||
|
/* Check average load */
|
||||||
|
if( find_loadavg() >= LOAD_TRESHOLD )
|
||||||
|
loadavg_panic++;
|
||||||
|
else
|
||||||
|
loadavg_panic = 0;
|
||||||
|
|
||||||
|
/* Check crond */
|
||||||
|
if( find_process("crond") < 0 )
|
||||||
|
restart_cron++;
|
||||||
|
else
|
||||||
|
restart_cron = 0;
|
||||||
|
|
||||||
|
/* Check SSHd */
|
||||||
|
if( find_process("dropbear") < 0 )
|
||||||
|
restart_sshd++;
|
||||||
|
else
|
||||||
|
restart_sshd = 0;
|
||||||
|
|
||||||
|
/* Check wireless interfaces */
|
||||||
|
ifs = load_wifi_uci(ifs, &modtime);
|
||||||
|
for( curif = ifs; curif; curif = curif->next )
|
||||||
|
{
|
||||||
|
/* Get current channel and bssid */
|
||||||
|
if( (iw_get_bssid(iwfd, curif->ifname, bssid) == 0) &&
|
||||||
(iw_get_channel(iwfd, curif->ifname, &channel) == 0) )
|
(iw_get_channel(iwfd, curif->ifname, &channel) == 0) )
|
||||||
{
|
|
||||||
/* Check BSSID */
|
|
||||||
if( strcasecmp(bssid, curif->bssid) != 0 )
|
|
||||||
{
|
{
|
||||||
syslog(LOG_WARNING, "BSSID mismatch on %s: current=%s wanted=%s",
|
/* Check BSSID */
|
||||||
curif->ifname, bssid, curif->bssid);
|
if( strcasecmp(bssid, curif->bssid) != 0 )
|
||||||
|
{
|
||||||
|
syslog(LOG_WARNING, "BSSID mismatch on %s: current=%s wanted=%s",
|
||||||
|
curif->ifname, bssid, curif->bssid);
|
||||||
|
|
||||||
restart_wifi++;
|
restart_wifi++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check channel */
|
||||||
|
else if( channel != curif->channel )
|
||||||
|
{
|
||||||
|
syslog(LOG_WARNING, "Channel mismatch on %s: current=%d wanted=%d",
|
||||||
|
curif->ifname, channel, curif->channel);
|
||||||
|
|
||||||
|
restart_wifi++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
/* Check channel */
|
|
||||||
else if( channel != curif->channel )
|
|
||||||
{
|
{
|
||||||
syslog(LOG_WARNING, "Channel mismatch on %s: current=%d wanted=%d",
|
syslog(LOG_WARNING, "Requested interface %s not present", curif->ifname);
|
||||||
curif->ifname, channel, curif->channel);
|
|
||||||
|
|
||||||
restart_wifi++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
|
||||||
|
/* Wifi restart required? */
|
||||||
|
if( restart_wifi >= HYSTERESIS )
|
||||||
{
|
{
|
||||||
syslog(LOG_WARNING, "Requested interface %s not present", curif->ifname);
|
restart_wifi = 0;
|
||||||
|
syslog(LOG_WARNING, "Channel or BSSID mismatch on wireless interface, restarting");
|
||||||
|
EXEC(WIFI_ACTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Cron restart required? */
|
||||||
|
if( restart_cron >= HYSTERESIS )
|
||||||
|
{
|
||||||
|
restart_cron = 0;
|
||||||
|
syslog(LOG_WARNING, "The cron process died, restarting");
|
||||||
|
EXEC(CRON_ACTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* SSHd restart required? */
|
||||||
|
if( restart_sshd >= HYSTERESIS )
|
||||||
|
{
|
||||||
|
restart_sshd = 0;
|
||||||
|
syslog(LOG_WARNING, "The ssh process died, restarting");
|
||||||
|
EXEC(SSHD_ACTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Is there a load problem? */
|
||||||
|
if( loadavg_panic >= HYSTERESIS )
|
||||||
|
{
|
||||||
|
syslog(LOG_EMERG, "Critical system load level, triggering reset!");
|
||||||
|
|
||||||
|
/* Try watchdog, fall back to reboot */
|
||||||
|
if( wdfd > -1 )
|
||||||
|
ioctl(wdfd, WDIOC_SETTIMEOUT, &wdtrigger);
|
||||||
|
else
|
||||||
|
EXEC(LOAD_ACTION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Wifi restart required? */
|
|
||||||
if( restart_wifi >= HYSTERESIS )
|
|
||||||
{
|
|
||||||
restart_wifi = 0;
|
|
||||||
syslog(LOG_WARNING, "Channel or BSSID mismatch on wireless interface, restarting");
|
|
||||||
EXEC(WIFI_ACTION);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Cron restart required? */
|
|
||||||
if( restart_cron >= HYSTERESIS )
|
|
||||||
{
|
|
||||||
restart_cron = 0;
|
|
||||||
syslog(LOG_WARNING, "The cron process died, restarting");
|
|
||||||
EXEC(CRON_ACTION);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* SSHd restart required? */
|
|
||||||
if( restart_sshd >= HYSTERESIS )
|
|
||||||
{
|
|
||||||
restart_sshd = 0;
|
|
||||||
syslog(LOG_WARNING, "The ssh process died, restarting");
|
|
||||||
EXEC(SSHD_ACTION);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Is there a load problem? */
|
|
||||||
if( loadavg_panic >= HYSTERESIS )
|
|
||||||
{
|
|
||||||
syslog(LOG_EMERG, "Critical system load level, triggering reset!");
|
|
||||||
|
|
||||||
/* Try watchdog, fall back to reboot */
|
|
||||||
if( wdfd > -1 )
|
|
||||||
ioctl(wdfd, WDIOC_SETTIMEOUT, &wdtrigger);
|
|
||||||
else
|
|
||||||
EXEC(LOAD_ACTION);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Reset watchdog timer */
|
/* Reset watchdog timer */
|
||||||
if( wdfd > -1 )
|
if( wdfd > -1 )
|
||||||
write(wdfd, &wdkeepalive, 1);
|
write(wdfd, &wdkeepalive, 1);
|
||||||
|
|
||||||
sleep(INTERVAL);
|
sleep(BASE_INTERVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
shutdown_watchdog(0);
|
shutdown_watchdog(0);
|
||||||
|
|
|
@ -39,8 +39,11 @@
|
||||||
#include "wireless.22.h"
|
#include "wireless.22.h"
|
||||||
|
|
||||||
|
|
||||||
/* Check interval */
|
/* Watchdog poll interval */
|
||||||
#define INTERVAL 30
|
#define BASE_INTERVAL 5
|
||||||
|
|
||||||
|
/* Action interval (N * BASE_INTERVAL) */
|
||||||
|
#define ACTION_INTERVAL 6
|
||||||
|
|
||||||
/* Hysteresis */
|
/* Hysteresis */
|
||||||
#define HYSTERESIS 3
|
#define HYSTERESIS 3
|
||||||
|
|
Loading…
Reference in a new issue