00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00022
00023
00103 #include <stdlib.h>
00104 #include <string.h>
00105 #include <signal.h>
00106 #include <stdio.h>
00107 #include <sys/types.h>
00108 #include <unistd.h>
00109 #include <isc/eventlib.h>
00110 #include <jnx/aux_types.h>
00111 #include <jnx/bits.h>
00112 #include <jnx/mgmt_sock_pub.h>
00113 #include <jnx/junos_init.h>
00114 #include <jnx/junos_trace.h>
00115 #include "hellopics-mgmt_logging.h"
00116 #include "hellopics-mgmt_config.h"
00117 #include "hellopics-mgmt_conn.h"
00118 #include "hellopics-mgmt_ha.h"
00119
00120 #include HELLOPICS_OUT_H
00121 #include HELLOPICS_SEQUENCE_H
00122
00123
00124 extern volatile boolean is_master;
00125
00129 #define DNAME_HELLOPICS_MGMT "hellopics-mgmt"
00130
00131
00132
00137 extern const parse_menu_t master_menu[];
00138
00139
00140
00141 static void hellopics_mastership_switch(bool master);
00142 evContext present_ctx;
00143
00153 static int
00154 hellopics_init (evContext ctx)
00155 {
00156 init_connection_stats();
00157 present_ctx = ctx;
00158 init_config();
00159 return init_server(ctx);
00160 }
00161
00162
00163
00164
00165
00166
00179 int
00180 main (int argc, char ** argv)
00181 {
00182 const char * hp_config[] = {DDLNAME_SYNC, DDLNAME_SYNC_HELLOPICS, NULL};
00183 int ret = 0;
00184 junos_sdk_app_ctx_t ctx;
00185
00186
00187 ctx = junos_create_app_ctx(argc, argv, DNAME_HELLOPICS_MGMT,
00188 master_menu, PACKAGE_NAME, SEQUENCE_NUMBER);
00189 if (ctx == NULL) {
00190 return -1;
00191 }
00192
00193
00194 if ((ret = junos_set_app_cb_config_read(ctx, hellopics_config_read))) {
00195 goto cleanup;
00196 }
00197
00198
00199 if ((ret = junos_set_app_cb_init(ctx, hellopics_init))) {
00200 goto cleanup;
00201 }
00202
00203
00204 ret = junos_set_app_cfg_trace_path(ctx, hp_config);
00205 if (ret < 0) {
00206 goto cleanup;
00207 }
00208
00209 if ((ret = junos_set_app_cb_mastership_switch(ctx,
00210 hellopics_mastership_switch))) {
00211 goto cleanup;
00212 }
00213
00214 ret = junos_app_init(ctx);
00215
00216 cleanup:
00217 if (ret != 0)
00218 LOG(LOG_ERR, "%s: Clean up before the exit ", __func__);
00219
00220
00221 junos_destroy_app_ctx(ctx);
00222 return ret;
00223 }
00233 static void
00234 hellopics_mastership_switch(bool master __unused)
00235 {
00236 LOG(LOG_INFO, "%s: Switching the daemon mastership", __func__);
00237 kill(getpid(),SIGTERM);
00238 }