00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00021
00022
00528 #include <sync/common.h>
00529 #include <jnx/pmon.h>
00530 #include <jnx/patricia.h>
00531 #include "monitube2-mgmt_main.h"
00532 #include "monitube2-mgmt_config.h"
00533 #include "monitube2-mgmt_conn.h"
00534 #include "monitube2-mgmt_kcom.h"
00535 #include "monitube2-mgmt_logging.h"
00536
00537 #include MONITUBE2_OUT_H
00538 #include MONITUBE2_SEQUENCE_H
00539
00540
00541
00545 #define DNAME_MONITUBE_MGMT "monitube2-mgmt"
00546
00547
00551 #define PMON_HB_INTERVAL 30
00552
00553
00554
00555
00560 extern const parse_menu_t master_menu[];
00561
00562 static junos_pmon_context_t pmon;
00563
00564
00565
00566
00573 static void
00574 monitube_sigterm(int signal_ign __unused)
00575 {
00576 monitube_shutdown(TRUE);
00577 }
00578
00588 static int
00589 monitube_init (evContext ctx)
00590 {
00591 struct timespec interval;
00592
00593 pmon = NULL;
00594
00595 junos_sig_register(SIGTERM, monitube_sigterm);
00596
00597 if(kcom_init(ctx) != KCOM_OK) {
00598 goto init_fail;
00599 }
00600
00601 init_config(ctx);
00602
00603 if((pmon = junos_pmon_create_context()) == PMON_CONTEXT_INVALID) {
00604 LOG(LOG_ERR, "%s: health monitoring: initialization failed", __func__);
00605 goto init_fail;
00606 }
00607
00608 if(junos_pmon_set_event_context(pmon, ctx)) {
00609 LOG(LOG_ERR, "%s: health monitoring: setup failed", __func__);
00610 goto init_fail;
00611 } else {
00612 if(junos_pmon_select_backend(pmon, PMON_BACKEND_LOCAL, NULL)) {
00613 LOG(LOG_ERR, "%s: health monitoring: select backend failed",
00614 __func__);
00615 } else {
00616 interval.tv_sec = PMON_HB_INTERVAL;
00617 interval.tv_nsec = 0;
00618
00619 if(junos_pmon_heartbeat(pmon, &interval, 0)) {
00620 LOG(LOG_ERR, "%s: health monitoring: setup heartbeat failed",
00621 __func__);
00622 }
00623 }
00624 }
00625
00626 if(init_server(ctx)) {
00627 goto init_fail;
00628 }
00629
00630 return SUCCESS;
00631
00632 init_fail:
00633
00634 LOG(LOG_CRIT, "initialization failed");
00635 kcom_shutdown();
00636 clear_config();
00637 clear_stats();
00638
00639 if(pmon) {
00640 junos_pmon_destroy_context(&pmon);
00641 }
00642
00643 return EFAIL;
00644 }
00645
00646
00647
00648
00655 void
00656 monitube_shutdown(boolean do_exit)
00657 {
00658
00659 clear_config();
00660 clear_stats();
00661
00662
00663 if(pmon)
00664 junos_pmon_destroy_context(&pmon);
00665
00666 if(do_exit) {
00667 LOG(TRACE_LOG_INFO, "monitube2-mgmt shutting down");
00668 exit(0);
00669 }
00670 }
00671
00672
00685 int
00686 main (int argc, char **argv)
00687 {
00688 const char * monitube_trace_config[] =
00689 {DDLNAME_SERVICES, DDLNAME_SYNC, DDLNAME_MONITUBE, NULL};
00690
00691 int ret = 0;
00692 junos_sdk_app_ctx_t ctx;
00693
00694
00695 ctx = junos_create_app_ctx(argc, argv, DNAME_MONITUBE_MGMT,
00696 master_menu, PACKAGE_NAME, SEQUENCE_NUMBER);
00697 if (ctx == NULL) {
00698 return -1;
00699 }
00700
00701
00702 ret = junos_set_app_cb_config_read(ctx, monitube_config_read);
00703 if (ret < 0) {
00704 junos_destroy_app_ctx(ctx);
00705 return ret;
00706 }
00707
00708 ret = junos_set_app_cfg_trace_path(ctx, monitube_trace_config);
00709 if (ret < 0) {
00710 junos_destroy_app_ctx(ctx);
00711 return ret;
00712 }
00713
00714
00715 ret = junos_set_app_cb_init(ctx, monitube_init);
00716 if (ret < 0) {
00717 junos_destroy_app_ctx(ctx);
00718 return ret;
00719 }
00720
00721
00722 ret = junos_app_init(ctx);
00723
00724
00725
00726 junos_destroy_app_ctx(ctx);
00727 return ret;
00728 }