monitube2-mgmt_main.c

Go to the documentation of this file.
00001 /*
00002  * $Id: monitube2-mgmt_main.c 347265 2009-11-19 13:55:39Z kdickman $
00003  *
00004  * This code is provided as is by Juniper Networks SDK Developer Support.
00005  * It is provided with no warranties or guarantees, and Juniper Networks
00006  * will not provide support or maintenance of this code in any fashion.
00007  * The code is provided only to help a developer better understand how
00008  * the SDK can be used.
00009  * 
00010  * Copyright (c) 2009, Juniper Networks, Inc.
00011  * All rights reserved.
00012  */
00013 
00021 /* The Application and This Daemon's Documentation: */
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 /*** Constants ***/
00541 
00545 #define DNAME_MONITUBE_MGMT    "monitube2-mgmt"
00546 
00547 
00551 #define PMON_HB_INTERVAL   30
00552 
00553 
00554 /*** Data Structures ***/
00555 
00560 extern const parse_menu_t master_menu[];
00561 
00562 static junos_pmon_context_t pmon; 
00563 
00564 /*** STATIC/INTERNAL Functions ***/
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 //    close_connections();
00639     if(pmon) {
00640         junos_pmon_destroy_context(&pmon);
00641     }
00642     
00643     return EFAIL;
00644 }
00645 
00646 
00647 /*** GLOBAL/EXTERNAL Functions ***/
00648 
00655 void
00656 monitube_shutdown(boolean do_exit)
00657 {
00658     //kcom_shutdown();
00659     clear_config();
00660     clear_stats();
00661     //close_connections();
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     // create an application context
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     // set config read call back
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     // set init call back
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     // now just call the great junos_app_init
00722     ret = junos_app_init(ctx);
00723 
00724     // should not come here unless daemon exiting or init failed,
00725     // destroy context
00726     junos_destroy_app_ctx(ctx);
00727     return ret;
00728 }

2007-2009 Juniper Networks, Inc. All rights reserved. The information contained herein is confidential information of Juniper Networks, Inc., and may not be used, disclosed, distributed, modified, or copied without the prior written consent of Juniper Networks, Inc. in an express license. This information is subject to change by Juniper Networks, Inc. Juniper Networks, the Juniper Networks logo, and JUNOS are registered trademarks of Juniper Networks, Inc. in the United States and other countries. All other trademarks, service marks, registered trademarks, or registered service marks are the property of their respective owners.
Generated on Sun May 30 20:27:04 2010 for SDK Your Net Corporation Monitube2 IPTV Monitoring Example: monitube2-mgmt 1.0 by Doxygen 1.5.1