monitube-mgmt_main.c

Go to the documentation of this file.
00001 /*
00002  * $Id: monitube-mgmt_main.c 346460 2009-11-14 05:06:47Z ssiano $
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) 2008, Juniper Networks, Inc.
00011  * All rights reserved.
00012  */
00013 
00021 /* The Application and This Daemon's Documentation: */
00022 
00813 #include <sync/common.h>
00814 #include <jnx/pmon.h>
00815 #include "monitube-mgmt_main.h"
00816 #include "monitube-mgmt_config.h"
00817 #include "monitube-mgmt_conn.h"
00818 #include "monitube-mgmt_kcom.h"
00819 #include "monitube-mgmt_logging.h"
00820 
00821 #include MONITUBE_OUT_H
00822 #include MONITUBE_SEQUENCE_H
00823 
00824 /*** Constants ***/
00825 
00829 #define DNAME_MONITUBE_MGMT    "monitube-mgmt"
00830 
00831 
00835 #define PMON_HB_INTERVAL   30
00836 
00837 
00838 /*** Data Structures ***/
00839 
00844 extern const parse_menu_t master_menu[];
00845 
00846 static junos_pmon_context_t pmon; 
00847 
00848 /*** STATIC/INTERNAL Functions ***/
00849 
00850 
00857 static void
00858 monitube_sigterm(int signal_ign __unused)
00859 {
00860     monitube_shutdown(TRUE);
00861 }
00862 
00872 static int
00873 monitube_init (evContext ctx)
00874 {
00875     struct timespec interval;
00876     
00877     pmon = NULL;
00878     
00879     junos_sig_register(SIGTERM, monitube_sigterm);
00880 
00881     init_config(ctx);
00882     
00883     if(kcom_init(ctx) != KCOM_OK) {
00884         goto init_fail;
00885     }
00886     
00887     if((pmon = junos_pmon_create_context()) == PMON_CONTEXT_INVALID) {
00888         LOG(LOG_ERR, "%s: health monitoring: initialization failed", __func__);
00889         goto init_fail;
00890     }
00891 
00892     if(junos_pmon_set_event_context(pmon, ctx)) {
00893         LOG(LOG_ERR, "%s: health monitoring: setup failed", __func__);
00894         // upon failure forget about this hb monitoring... run daemon anyway
00895     } else  {
00896         if(junos_pmon_select_backend(pmon, PMON_BACKEND_LOCAL, NULL)) {
00897             LOG(LOG_ERR, "%s: health monitoring: select backend failed",
00898                     __func__);
00899         } else {
00900             interval.tv_sec = PMON_HB_INTERVAL;
00901             interval.tv_nsec = 0;
00902             
00903             if(junos_pmon_heartbeat(pmon, &interval, 0)) {
00904                 LOG(LOG_ERR, "%s: health monitoring: setup heartbeat failed",
00905                         __func__);
00906             }
00907         }
00908     }
00909     
00910     if(init_server(ctx)) {
00911         goto init_fail;
00912     }
00913     
00914     return SUCCESS;
00915     
00916 init_fail:
00917 
00918     LOG(LOG_CRIT, "initialization failed");
00919     kcom_shutdown();
00920     clear_config();
00921     close_connections();
00922     if(pmon) {
00923         junos_pmon_destroy_context(&pmon);
00924     }
00925     
00926     return EFAIL;
00927 }
00928 
00929 
00930 /*** GLOBAL/EXTERNAL Functions ***/
00931 
00938 void
00939 monitube_shutdown(boolean do_exit)
00940 {
00941     kcom_shutdown();
00942     clear_config();
00943     close_connections();
00944     
00945     if(pmon)
00946         junos_pmon_destroy_context(&pmon);
00947     
00948     if(do_exit) {
00949         LOG(TRACE_LOG_INFO, "monitube-mgmt shutting down");
00950         exit(0);
00951     }
00952 }
00953 
00954 
00967 int
00968 main (int argc, char **argv)
00969 {
00970     const char * monitube_trace_config[] = 
00971         {DDLNAME_SYNC, DDLNAME_SYNC_MONITUBE, NULL};
00972     
00973     int ret = 0;
00974     junos_sdk_app_ctx_t ctx;
00975     
00976     // create an application context
00977     ctx = junos_create_app_ctx(argc, argv, DNAME_MONITUBE_MGMT,
00978                  master_menu, PACKAGE_NAME, SEQUENCE_NUMBER);
00979     if (ctx == NULL) {
00980         return -1;
00981     }
00982 
00983     // set config read call back
00984     ret = junos_set_app_cb_config_read(ctx, monitube_config_read);
00985     if (ret < 0) {
00986         junos_destroy_app_ctx(ctx); 
00987         return ret;
00988     }
00989     
00990     ret = junos_set_app_cfg_trace_path(ctx, monitube_trace_config);
00991     if (ret < 0) {
00992         junos_destroy_app_ctx(ctx); 
00993         return ret;
00994     }
00995     
00996     // set init call back
00997     ret = junos_set_app_cb_init(ctx, monitube_init);
00998     if (ret < 0) {
00999         junos_destroy_app_ctx(ctx); 
01000         return ret;
01001     }
01002 
01003     // now just call the great junos_app_init
01004     ret = junos_app_init(ctx);
01005 
01006     // should not come here unless daemon exiting or init failed,
01007     // destroy context
01008     junos_destroy_app_ctx(ctx);
01009     return ret;
01010 }

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:03 2010 for SDK Your Net Corporation Monitube IPTV Monitoring Example: monitube-mgmt 1.0 by Doxygen 1.5.1