Changeset 8885
- Timestamp:
- 07/15/12 18:25:24 (10 months ago)
- Location:
- luci/trunk/contrib/package/freifunk-watchdog
- Files:
-
- 1 added
- 3 modified
-
files/freifunk-watchdog.config (added)
-
Makefile (modified) (3 diffs)
-
src/watchdog.c (modified) (9 diffs)
-
src/watchdog.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
luci/trunk/contrib/package/freifunk-watchdog/Makefile
r7771 r8885 1 1 # 2 # Copyright (C) 2009 Jo-Philipp Wich <xm@subsignal.org>2 # Copyright (C) 2009-2012 Jo-Philipp Wich <xm@subsignal.org> 3 3 # 4 4 # This is free software, licensed under the GNU General Public License v2. … … 9 9 10 10 PKG_NAME:=freifunk-watchdog 11 PKG_RELEASE:= 711 PKG_RELEASE:=8 12 12 13 13 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) … … 47 47 $(INSTALL_DIR) $(1)/etc/init.d 48 48 $(INSTALL_BIN) ./files/freifunk-watchdog.init $(1)/etc/init.d/freifunk-watchdog 49 $(INSTALL_DIR) $(1)/etc/config 50 $(INSTALL_CONF) ./files/freifunk-watchdog.config $(1)/etc/config/freifunk-watchdog 49 51 $(INSTALL_DIR) $(1)/usr/sbin 50 52 $(INSTALL_BIN) $(PKG_BUILD_DIR)/ffwatchd $(1)/usr/sbin/ -
luci/trunk/contrib/package/freifunk-watchdog/src/watchdog.c
r5359 r8885 198 198 199 199 /* Add tuple */ 200 static void load_wifi_uci_add_iface(const char *section, struct uci_ itr_ctx *itr)200 static void load_wifi_uci_add_iface(const char *section, struct uci_wifi_iface_itr_ctx *itr) 201 201 { 202 202 wifi_tuple_t *t; … … 254 254 { 255 255 struct uci_context *ctx; 256 struct uci_ itr_ctx itr;256 struct uci_wifi_iface_itr_ctx itr; 257 257 wifi_tuple_t *cur, *next; 258 258 259 259 if( check_uci_update("wireless", modtime) ) 260 260 { 261 syslog(LOG_INFO, " Config changed, reloading");261 syslog(LOG_INFO, "Wireless config changed, reloading"); 262 262 263 263 if( (ctx = ucix_init("wireless")) != NULL ) … … 285 285 } 286 286 287 /* Add tuple */ 288 static void load_watchdog_uci_add_process(const char *section, struct uci_process_itr_ctx *itr) 289 { 290 process_tuple_t *t; 291 const char *ucitmp; 292 int val = 0; 293 294 if( (t = (process_tuple_t *)malloc(sizeof(process_tuple_t))) != NULL ) 295 { 296 t->restart = 0; 297 298 ucitmp = ucix_get_option(itr->ctx, "freifunk-watchdog", section, "process"); 299 if(ucitmp) 300 { 301 strncpy(t->process, ucitmp, sizeof(t->process)); 302 val++; 303 } 304 305 ucitmp = ucix_get_option(itr->ctx, "freifunk-watchdog", section, "initscript"); 306 if(ucitmp) 307 { 308 strncpy(t->initscript, ucitmp, sizeof(t->initscript)); 309 val++; 310 } 311 312 if( val == 2 ) 313 { 314 syslog(LOG_INFO, "Monitoring %s: initscript=%s", 315 t->process, t->initscript); 316 317 t->next = itr->list; 318 itr->list = t; 319 } 320 else 321 { 322 free(t); 323 } 324 } 325 } 326 327 /* Load config */ 328 static process_tuple_t * load_watchdog_uci(process_tuple_t *procs) 329 { 330 struct uci_context *ctx; 331 struct uci_process_itr_ctx itr; 332 process_tuple_t *cur, *next; 333 334 syslog(LOG_INFO, "Loading watchdog config"); 335 336 if( (ctx = ucix_init("freifunk-watchdog")) != NULL ) 337 { 338 if( procs != NULL ) 339 { 340 for(cur = procs; cur; cur = next) 341 { 342 next = cur->next; 343 free(cur); 344 } 345 } 346 347 itr.list = NULL; 348 itr.ctx = ctx; 349 350 ucix_for_each_section_type(ctx, "freifunk-watchdog", "process", 351 (void *)load_watchdog_uci_add_process, &itr); 352 353 return itr.list; 354 } 355 356 return procs; 357 } 358 287 359 /* Daemon implementation */ 288 360 static int do_daemon(void) … … 297 369 struct sigaction sa; 298 370 299 wifi_tuple_t *ifs = NULL, *curif; 300 time_t modtime = 0; 371 wifi_tuple_t *ifs = NULL, *curr_if; 372 process_tuple_t *procs = NULL, *curr_proc; 373 time_t wireless_modtime = 0; 301 374 302 375 int action_intv = 0; 303 376 int restart_wifi = 0; 304 int restart_cron = 0;305 int restart_sshd = 0;306 377 int loadavg_panic = 0; 307 378 … … 341 412 sigaction(SIGCHLD, &sa, NULL); 342 413 414 /* Load watchdog configuration only once */ 415 procs = load_watchdog_uci(procs); 416 343 417 while( 1 ) 344 418 { … … 355 429 loadavg_panic = 0; 356 430 357 /* Check crond */358 if( find_process("crond") < 0 )359 restart_cron++;360 else361 restart_cron = 0;362 363 /* Check SSHd */364 if( find_process("dropbear") < 0 )365 restart_sshd++;366 else367 restart_sshd = 0;368 369 431 /* Check wireless interfaces */ 370 ifs = load_wifi_uci(ifs, & modtime);371 for( cur if = ifs; curif; curif = curif->next )432 ifs = load_wifi_uci(ifs, &wireless_modtime); 433 for( curr_if = ifs; curr_if; curr_if = curr_if->next ) 372 434 { 373 435 /* Get current channel and bssid */ 374 if( (iw_get_bssid(iwfd, cur if->ifname, bssid) == 0) &&375 (iw_get_channel(iwfd, cur if->ifname, &channel) == 0) )436 if( (iw_get_bssid(iwfd, curr_if->ifname, bssid) == 0) && 437 (iw_get_channel(iwfd, curr_if->ifname, &channel) == 0) ) 376 438 { 377 439 /* Check BSSID */ 378 if( strcasecmp(bssid, cur if->bssid) != 0 )440 if( strcasecmp(bssid, curr_if->bssid) != 0 ) 379 441 { 380 442 syslog(LOG_WARNING, "BSSID mismatch on %s: current=%s wanted=%s", 381 cur if->ifname, bssid, curif->bssid);443 curr_if->ifname, bssid, curr_if->bssid); 382 444 383 445 restart_wifi++; … … 385 447 386 448 /* Check channel */ 387 else if( channel != cur if->channel )449 else if( channel != curr_if->channel ) 388 450 { 389 451 syslog(LOG_WARNING, "Channel mismatch on %s: current=%d wanted=%d", 390 cur if->ifname, channel, curif->channel);452 curr_if->ifname, channel, curr_if->channel); 391 453 392 454 restart_wifi++; … … 395 457 else 396 458 { 397 syslog(LOG_WARNING, "Requested interface %s not present", curif->ifname); 459 syslog(LOG_WARNING, "Requested interface %s not present", curr_if->ifname); 460 } 461 } 462 463 /* Check processes */ 464 for( curr_proc = procs; curr_proc; curr_proc = curr_proc->next ) 465 { 466 if( find_process(curr_proc->process) < 0 ) 467 curr_proc->restart++; 468 else 469 curr_proc->restart = 0; 470 471 /* Process restart required? */ 472 if( curr_proc->restart >= HYSTERESIS ) 473 { 474 curr_proc->restart = 0; 475 syslog(LOG_WARNING, "The %s process died, restarting", curr_proc->process); 476 EXEC(PROC_ACTION); 398 477 } 399 478 } … … 406 485 syslog(LOG_WARNING, "Channel or BSSID mismatch on wireless interface, restarting"); 407 486 EXEC(WIFI_ACTION); 408 }409 410 /* Cron restart required? */411 if( restart_cron >= HYSTERESIS )412 {413 restart_cron = 0;414 syslog(LOG_WARNING, "The cron process died, restarting");415 EXEC(CRON_ACTION);416 }417 418 /* SSHd restart required? */419 if( restart_sshd >= HYSTERESIS )420 {421 restart_sshd = 0;422 syslog(LOG_WARNING, "The ssh process died, restarting");423 EXEC(SSHD_ACTION);424 487 } 425 488 -
luci/trunk/contrib/package/freifunk-watchdog/src/watchdog.h
r5359 r8885 53 53 #define SYSLOG_IDENT "Freifunk Watchdog" 54 54 55 /* Process error action */ 56 #define PROC_ACTION curr_proc->initscript, curr_proc->initscript, "restart" 57 55 58 /* Wifi error action */ 56 59 #define WIFI_ACTION "/sbin/wifi", "/sbin/wifi" 57 58 /* Crond error action */59 #define CRON_ACTION "/etc/init.d/cron", "/etc/init.d/cron", "restart"60 61 /* SSHd error action */62 #define SSHD_ACTION "/etc/init.d/dropbear", "/etc/init.d/dropbear", "restart"63 60 64 61 /* Watchdog device */ … … 86 83 87 84 /* structure to hold tuple-list and uci context during iteration */ 88 struct uci_ itr_ctx {85 struct uci_wifi_iface_itr_ctx { 89 86 struct wifi_tuple *list; 90 87 struct uci_context *ctx; … … 92 89 93 90 typedef struct wifi_tuple wifi_tuple_t; 91 92 93 /* process name/exec tuples */ 94 struct process_tuple { 95 char process[PATH_MAX + 1]; 96 char initscript[PATH_MAX + 1]; 97 int restart; 98 struct process_tuple *next; 99 }; 100 101 /* structure to hold tuple-list and uci context during iteration */ 102 struct uci_process_itr_ctx { 103 struct process_tuple *list; 104 struct uci_context *ctx; 105 }; 106 107 typedef struct process_tuple process_tuple_t; 94 108 95 109
