static int child_init(int rank) { if (rank==1) { if_update_stat(dlg_enable_stats, active_dlgs, active_dlgs_cnt); if_update_stat(dlg_enable_stats, early_dlgs, early_dlgs_cnt); } if ( (dlg_db_mode==DB_MODE_REALTIME && (rank>=0 || rank==PROC_TIMER || rank==PROC_MODULE)) || (dlg_db_mode==DB_MODE_SHUTDOWN && (rank==(dont_fork?1:PROC_MAIN) || rank==PROC_MODULE) ) || (dlg_db_mode==DB_MODE_DELAYED && (rank==PROC_MAIN || rank==PROC_MODULE || rank==PROC_TIMER || rank>0) )){ if ( dlg_connect_db(&db_url) ) { LM_ERR("failed to connect to database (rank=%d)\n",rank); return -1; } } if (cdb_url.s && cdb_url.len && init_cachedb() < 0) { LM_ERR("cannot init cachedb feature\n"); return -1; } return 0; }
static int child_init(int rank) { dlg_db_mode = dlg_db_mode_param; if(rank==PROC_MAIN) { if(dlg_timer_procs>0) { if(fork_sync_timer(PROC_TIMER, "Dialog Main Timer", 1 /*socks flag*/, dlg_timer_routine, NULL, 1 /*every sec*/)<0) { LM_ERR("failed to start main timer routine as process\n"); return -1; /* error */ } } if(dlg_ka_timer>0 && dlg_ka_interval>0) { if(fork_sync_timer(PROC_TIMER, "Dialog KA Timer", 1 /*socks flag*/, dlg_ka_timer_exec, NULL, dlg_ka_timer /*sec*/)<0) { LM_ERR("failed to start ka timer routine as process\n"); return -1; /* error */ } } if(fork_sync_timer(PROC_TIMER, "Dialog Clean Timer", 1 /*socks flag*/, dlg_clean_timer_exec, NULL, dlg_clean_timer /*sec*/)<0) { LM_ERR("failed to start clean timer routine as process\n"); return -1; /* error */ } } if (rank==1) { if_update_stat(dlg_enable_stats, active_dlgs, active_dlgs_cnt); if_update_stat(dlg_enable_stats, early_dlgs, early_dlgs_cnt); } if ( ((dlg_db_mode==DB_MODE_REALTIME || dlg_db_mode==DB_MODE_DELAYED) && (rank>0 || rank==PROC_TIMER)) || (dlg_db_mode==DB_MODE_SHUTDOWN && (rank==PROC_MAIN)) ) { if ( dlg_connect_db(&db_url) ) { LM_ERR("failed to connect to database (rank=%d)\n",rank); return -1; } } /* in DB_MODE_SHUTDOWN only PROC_MAIN will do a DB dump at the end, so * for the rest of the processes will be the same as DB_MODE_NONE */ if (dlg_db_mode==DB_MODE_SHUTDOWN && rank!=PROC_MAIN) dlg_db_mode = DB_MODE_NONE; /* in DB_MODE_REALTIME and DB_MODE_DELAYED the PROC_MAIN have no DB handle */ if ( (dlg_db_mode==DB_MODE_REALTIME || dlg_db_mode==DB_MODE_DELAYED) && rank==PROC_MAIN) dlg_db_mode = DB_MODE_NONE; return 0; }
int init_dlg_db(const str *db_url, int dlg_hash_size , int db_update_period) { /* Find a database module */ if (db_bind_mod(db_url, &dialog_dbf) < 0){ LM_ERR("Unable to bind to a database driver\n"); return -1; } if (dlg_connect_db(db_url)!=0){ LM_ERR("unable to connect to the database\n"); return -1; } if(db_check_table_version(&dialog_dbf, dialog_db_handle, &dialog_table_name, DLG_TABLE_VERSION) < 0) { LM_ERR("error during table version check.\n"); return -1; } if( (dlg_db_mode==DB_MODE_DELAYED) && (register_timer( dialog_update_db, 0, db_update_period)<0 )) { LM_ERR("failed to register update db\n"); return -1; } if( (load_dialog_info_from_db(dlg_hash_size) ) !=0 ){ LM_ERR("unable to load the dialog data\n"); return -1; } if (dlg_db_mode==DB_MODE_SHUTDOWN && remove_all_dialogs_from_db()!=0) { LM_WARN("failed to properly remove all the dialogs form DB\n"); } dialog_dbf.close(dialog_db_handle); dialog_db_handle = 0; return 0; }
static int child_init(int rank) { dlg_db_mode = dlg_db_mode_param; if ( ((dlg_db_mode==DB_MODE_REALTIME || dlg_db_mode==DB_MODE_DELAYED) && (rank>0 || rank==PROC_TIMER)) || (dlg_db_mode==DB_MODE_SHUTDOWN && (rank==PROC_MAIN)) ) { if ( dlg_connect_db(&db_url) ) { LM_ERR("failed to connect to database (rank=%d)\n",rank); return -1; } } /* in DB_MODE_SHUTDOWN only PROC_MAIN will do a DB dump at the end, so * for the rest of the processes will be the same as DB_MODE_NONE */ if (dlg_db_mode==DB_MODE_SHUTDOWN && rank!=PROC_MAIN) dlg_db_mode = DB_MODE_NONE; /* in DB_MODE_REALTIME and DB_MODE_DELAYED the PROC_MAIN have no DB handle */ if ( (dlg_db_mode==DB_MODE_REALTIME || dlg_db_mode==DB_MODE_DELAYED) && rank==PROC_MAIN) dlg_db_mode = DB_MODE_NONE; return 0; }