Skip to content

Commit 21b84cc

Browse files
committed
Added new status/report framework.
The purpose of this framework is to allow Modules (or parts of the core) to register identifiers in order to publish their status (readiness) and reports (logs). There statuses/reports may be checked from scripts or listed via MI. This allow the script to check the readiness status of various components of OpenSIPS, or, an external entity may monitor (check, list, get events) of the status / readiness of OpenSIPS (or parts of it). Also reports (some important logs poduced by OpenSIPS/modules) may be listed via MI, in order to have some history of what happened inside OpenSIPS/modules. Available cfg commnds (core provided): sr_check_status( group, [identifier]) Available MI commands (core providede): sr_get_status group identifier sr_list_status [group] sr_list_reports [group] [identifier] Available events (core provided): E_SR_STATUS_CHANGED ( group, identifier, new_status, new_details, old_status) The old "general" OpenSIPS status was ported to this new framework as group "core", identifier "main", publishing the core status (startup, running, terminating).
1 parent ceea5eb commit 21b84cc

File tree

12 files changed

+1241
-42
lines changed

12 files changed

+1241
-42
lines changed

core_cmds.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "flags.h"
3737
#include "serialize.h"
3838
#include "blacklists.h"
39+
#include "status_report.h"
3940
#include "cachedb/cachedb.h"
4041
#include "msg_translator.h"
4142
/* needed by tcpconn_add_alias() */
@@ -299,6 +300,11 @@ static cmd_export_t core_cmds[]={
299300
{CMD_PARAM_STR, 0, 0},
300301
{CMD_PARAM_INT|CMD_PARAM_OPT, 0, 0}, {0,0,0}},
301302
ALL_ROUTES},
303+
{"sr_check_status", (cmd_function)w_sr_check_status, {
304+
{CMD_PARAM_STR, fixup_sr_group, 0},
305+
{CMD_PARAM_STR|CMD_PARAM_OPT, 0, 0}, {0,0,0}},
306+
ALL_ROUTES},
307+
302308
{0,0,{{0,0,0}},0}
303309
};
304310

daemonize.c

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ char *startup_wdir = NULL;
6767

6868
static int status_pipe[2];
6969

70-
static enum opensips_states *osips_state = NULL;
71-
7270
/* creates the status pipe which will be used for
7371
* proper status code returning
7472
*
@@ -567,26 +565,3 @@ int set_core_dump(int enable, unsigned int size)
567565
return -1;
568566
}
569567

570-
571-
/* first setting must be done before any forking, so all processes will
572-
* inherite the same pointer to the global state variable */
573-
void set_osips_state(enum opensips_states state)
574-
{
575-
if (osips_state==NULL) {
576-
osips_state = shm_malloc( sizeof(enum opensips_states) );
577-
if (osips_state==NULL) {
578-
LM_ERR("failed to allocate opensips state variable in shm\n");
579-
return;
580-
}
581-
}
582-
583-
*osips_state = state;
584-
}
585-
586-
587-
enum opensips_states get_osips_state(void)
588-
{
589-
return osips_state ? *osips_state : STATE_NONE;
590-
}
591-
592-

daemonize.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@ int create_status_pipe(void);
4141
int wait_for_one_child(void);
4242
int wait_for_all_children(void);
4343

44-
enum opensips_states {STATE_NONE, STATE_STARTING,
45-
STATE_RUNNING, STATE_TERMINATING};
46-
47-
void set_osips_state(enum opensips_states);
48-
enum opensips_states get_osips_state(void);
49-
5044
#define report_failure_status() \
5145
do { \
5246
if (send_status_code(-1) < 0) \

main.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
#include "ut.h"
132132
#include "serialize.h"
133133
#include "statistics.h"
134+
#include "status_report.h"
134135
#include "core_stats.h"
135136
#include "pvar.h"
136137
#include "signals.h"
@@ -256,7 +257,8 @@ static int main_loop(void)
256257
shm_free(startup_done);
257258
}
258259

259-
set_osips_state( STATE_RUNNING );
260+
sr_set_core_status( STATE_RUNNING, MI_SSTR("running"));
261+
sr_add_core_report( MI_SSTR("initialization completed, ready now") );
260262

261263
/* main process left */
262264
is_main=1;
@@ -632,7 +634,13 @@ int main(int argc, char** argv)
632634
goto error;
633635
}
634636

635-
set_osips_state( STATE_STARTING );
637+
if (init_status_report() < 0) {
638+
LM_ERR("failed to initialize status-report support\n");
639+
goto error;
640+
}
641+
642+
sr_set_core_status( STATE_INITIALIZING, MI_SSTR("initializing"));
643+
sr_add_core_report( MI_SSTR("initializing") );
636644

637645
if ((!testing_framework || strcmp(testing_module, "core"))
638646
&& parse_opensips_cfg(cfg_file, preproc, NULL) < 0) {

mi/mi_core.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "../ipc.h"
5050
#include "../xlog.h"
5151
#include "../cfg_reload.h"
52+
#include "../status_report.h"
5253
#include "mi.h"
5354
#include "mi_trace.h"
5455

@@ -897,6 +898,28 @@ static mi_export_t mi_core_cmds[] = {
897898
{EMPTY_MI_RECIPE}
898899
}
899900
},
901+
{ "sr_get_status", "gets the status (only) of a 'status-report' "
902+
"group/identifier", 0, 0, {
903+
{mi_sr_get_status, {"group",0}},
904+
{mi_sr_get_status, {"group","identifier",0}},
905+
{EMPTY_MI_RECIPE}
906+
}
907+
},
908+
{ "sr_list_status", "list the status of all the identifiers in OpenSIPS"
909+
" or from a certain 'status-report' group", 0, 0, {
910+
{mi_sr_list_status, {0}},
911+
{mi_sr_list_status, {"group",0}},
912+
{EMPTY_MI_RECIPE}
913+
}
914+
},
915+
{ "sr_list_reports", "list the reports produced by some 'status-report' "
916+
"identifiers / groups" , 0, 0, {
917+
{mi_sr_list_reports, {0}},
918+
{mi_sr_list_reports, {"group",0}},
919+
{mi_sr_list_reports, {"group","identifier",0}},
920+
{EMPTY_MI_RECIPE}
921+
}
922+
},
900923
{ "help", "prints information about MI commands usage", 0, 0, {
901924
{w_mi_help, {0}},
902925
{w_mi_help_1, {"mi_cmd", 0}},

modules/dispatcher/dispatch.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
#include "../../ut.h"
3131
#include "../../trim.h"
32-
#include "../../daemonize.h"
32+
#include "../../status_report.h"
3333
#include "../../dprint.h"
3434
#include "../../action.h"
3535
#include "../../route.h"
@@ -909,7 +909,8 @@ void ds_flusher_routine(unsigned int ticks, void* param)
909909
ds_set_p list;
910910
int j;
911911

912-
if (ticks > 0 && get_osips_state() > STATE_RUNNING)
912+
/* do not run this routine if not in running mode */
913+
if (ticks > 0 && sr_get_core_status() < STATE_RUNNING)
913914
return;
914915

915916
ds_partition_t *partition;
@@ -2682,7 +2683,8 @@ void ds_update_weights(unsigned int ticks, void *param)
26822683
ds_partition_t *part;
26832684
ds_set_p sp;
26842685

2685-
if (get_osips_state() > STATE_RUNNING)
2686+
/* do not run this routine if not in running mode */
2687+
if (sr_get_core_status() < STATE_RUNNING)
26862688
return;
26872689

26882690
for (part = partitions; part; part = part->next) {

modules/mid_registrar/save.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#include "../../dset.h"
4343

4444
#include "../../parser/parse_from.h"
45-
#include "../../daemonize.h"
45+
#include "../../status_report.h"
4646
#include "../../mod_fix.h"
4747
#include "../../data_lump.h"
4848
#include "../../data_lump_rpl.h"
@@ -1865,7 +1865,7 @@ void mid_reg_tmcb_deleted(struct cell *_, int __, struct tmcb_params *params)
18651865

18661866
/* no response from downstream - clear up any lingering refs! */
18671867
if (mri->pending_replies && (reg_mode != MID_REG_THROTTLE_AOR) &&
1868-
get_osips_state() < STATE_TERMINATING) {
1868+
sr_get_core_status() == STATE_RUNNING) {
18691869
ul.lock_udomain(mri->dom, &mri->aor);
18701870
ul.get_urecord(mri->dom, &mri->aor, &r);
18711871
if (!r) {

modules/usrloc/dlist.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#include "../../ut.h"
4141
#include "../../db/db_ut.h"
4242
#include "../../mem/shm_mem.h"
43-
#include "../../daemonize.h"
43+
#include "../../status_report.h"
4444
#include "../../dprint.h"
4545
#include "../../ip_addr.h"
4646
#include "../../socket_info.h"
@@ -895,7 +895,7 @@ static inline int new_dlist(str* _n, dlist_t** _d)
895895
{
896896
dlist_t* ptr;
897897

898-
if (get_osips_state()>STATE_STARTING) {
898+
if (sr_get_core_status()!=STATE_INITIALIZING) {
899899
LM_ERR("cannot register new domain during runtime\n");
900900
return -1;
901901
}

shutdown.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "route.h"
3535
#include "script_cb.h"
3636
#include "blacklists.h"
37+
#include "status_report.h"
3738
#include "mem/shm_mem.h"
3839
#include "db/db_insertq.h"
3940
#include "net/net_udp.h"
@@ -189,7 +190,7 @@ void shutdown_opensips( int status )
189190
int i, n, p;
190191
int chld_status;
191192

192-
set_osips_state( STATE_TERMINATING );
193+
sr_set_core_status( STATE_TERMINATING, MI_SSTR("shutting down"));
193194

194195
/* terminate all processes */
195196

signals.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "dprint.h"
2828
#include "daemonize.h"
2929
#include "pt.h"
30+
#include "status_report.h"
3031
#include "shutdown.h"
3132
#include "signals.h"
3233

@@ -175,7 +176,7 @@ static void sig_usr(int signo)
175176
case SIGTERM:
176177
/* ignore any SIGTERM if not in shutdown sequance (this
177178
* is marked by the attendent process) */
178-
if (get_osips_state()!=STATE_TERMINATING)
179+
if (sr_get_core_status()!=STATE_TERMINATING)
179180
return;
180181
/* if some shutdown already in progress, ignore this one */
181182
if (sig_flag==0) sig_flag=signo;

0 commit comments

Comments
 (0)