equilibrium-mgmt_main.c

Go to the documentation of this file.
00001 /*
00002  * $Id: equilibrium-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 
00014  
00022 /* The Application and This Daemon's Documentation: */
00023 
00633 #include <sync/common.h>
00634 #include <jnx/pmon.h>
00635 #include "equilibrium-mgmt_main.h"
00636 #include "equilibrium-mgmt_config.h"
00637 #include "equilibrium-mgmt_conn.h"
00638 #include "equilibrium-mgmt_kcom.h"
00639 #include "equilibrium-mgmt_logging.h"
00640 
00641 #include EQUILIBRIUM_OUT_H
00642 #include EQUILIBRIUM_SEQUENCE_H
00643 
00644 /*** Constants ***/
00645 
00649 #define DNAME_EQUILIBRIUM_MGMT    "equilibrium-mgmt"
00650 
00651 
00655 #define PMON_HB_INTERVAL   30
00656 
00657 
00658 /*** Data Structures ***/
00659 
00664 extern const parse_menu_t master_menu[];
00665 
00666 static junos_pmon_context_t pmon; 
00667 
00668 /*** STATIC/INTERNAL Functions ***/
00669 
00670 
00677 static void
00678 equilibrium_sigterm(int signal_ign __unused)
00679 {
00680     equilibrium_shutdown(TRUE);
00681 }
00682 
00692 static int
00693 equilibrium_init (evContext ctx)
00694 {
00695     pmon = NULL;
00696     struct timespec interval;
00697     
00698     junos_sig_register(SIGTERM, equilibrium_sigterm);
00699 
00700     init_config();
00701     
00702     if(kcom_init(ctx) != KCOM_OK) {
00703         goto init_fail;
00704     }
00705     
00706     if((pmon = junos_pmon_create_context()) == PMON_CONTEXT_INVALID) {
00707         LOG(LOG_ERR, "%s: health monitoring: initialization failed", __func__);
00708         goto init_fail;
00709     }
00710 
00711     if(junos_pmon_set_event_context(pmon, ctx)) {
00712         LOG(LOG_ERR, "%s: health monitoring: setup failed", __func__);
00713         goto init_fail;
00714     }
00715     
00716     if(junos_pmon_select_backend(pmon, PMON_BACKEND_LOCAL, NULL)) {
00717         LOG(LOG_ERR, "%s: health monitoring: select backend failed", __func__);
00718         goto init_fail;
00719     }
00720     
00721     interval.tv_sec = PMON_HB_INTERVAL;
00722     interval.tv_nsec = 0;
00723     
00724     if(junos_pmon_heartbeat(pmon, &interval, 0)) {
00725         LOG(LOG_ERR, "health monitoring: setup heartbeat failed");
00726         goto init_fail;
00727     }
00728     
00729     if(init_server(ctx)) {
00730         goto init_fail;
00731     }
00732     
00733     return SUCCESS;
00734     
00735 init_fail:
00736 
00737     LOG(LOG_CRIT, "initialization failed");
00738 
00739     kcom_shutdown();
00740     clear_config();
00741     close_connections();
00742     if(pmon) {
00743         junos_pmon_destroy_context(&pmon);
00744     }
00745     
00746     return EFAIL;
00747 }
00748 
00749 
00750 /*** GLOBAL/EXTERNAL Functions ***/
00751 
00758 void
00759 equilibrium_shutdown(boolean do_exit)
00760 {
00761     kcom_shutdown();
00762     clear_config();
00763     clear_ssrb_config();
00764     close_connections();
00765     junos_pmon_destroy_context(&pmon);
00766     
00767     if(do_exit) {
00768         LOG(TRACE_LOG_INFO, "equilibrium-mgmt shutting down");
00769         exit(0);
00770     }
00771 }
00772 
00773 
00786 int
00787 main (int argc, char **argv)
00788 {
00789     const char * eq_trace_config[] = {
00790             DDLNAME_SYNC, DDLNAME_SYNC_EQUILIBRIUM, NULL};
00791     int ret = 0;
00792     junos_sdk_app_ctx_t ctx;
00793     
00794     // create an application context
00795     ctx = junos_create_app_ctx(argc, argv, DNAME_EQUILIBRIUM_MGMT,
00796                  master_menu, PACKAGE_NAME, SEQUENCE_NUMBER);
00797     if (ctx == NULL) {
00798         return -1;
00799     }
00800 
00801     // set config read call back
00802     ret = junos_set_app_cb_config_read(ctx, equilibrium_config_read);
00803     if (ret < 0) {
00804         junos_destroy_app_ctx(ctx); 
00805         return ret;
00806     }
00807 
00808     // set init call back
00809     ret = junos_set_app_cb_init(ctx, equilibrium_init);
00810     if (ret < 0) {
00811         junos_destroy_app_ctx(ctx); 
00812         return ret;
00813     }
00814     
00815     // set trace options DDL path
00816     ret = junos_set_app_cfg_trace_path(ctx, eq_trace_config);
00817     if (ret < 0) {
00818         junos_destroy_app_ctx(ctx);
00819         return ret;
00820     }
00821 
00822     // now just call the great junos_app_init
00823     ret = junos_app_init(ctx);
00824 
00825     // should not come here unless daemon exiting or init failed,
00826     // destroy context
00827     junos_destroy_app_ctx(ctx);
00828     return ret;
00829 }

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:26:57 2010 for SDK Your Net Corporation Equilibrium Load Balancer Example: equilibrium-mgmt 1.0 by Doxygen 1.5.1