diff --git a/include/fluent-bit/flb_reload.h b/include/fluent-bit/flb_reload.h index 7066505a21c..d2da3575df1 100644 --- a/include/fluent-bit/flb_reload.h +++ b/include/fluent-bit/flb_reload.h @@ -27,6 +27,7 @@ #define FLB_RELOAD_IDLE 0 #define FLB_RELOAD_IN_PROGRESS 1 +#define FLB_RELOAD_ABORTED 2 int flb_reload_property_check_all(struct flb_config *config); int flb_reload_reconstruct_cf(struct flb_cf *src_cf, struct flb_cf *dest_cf); diff --git a/src/flb_reload.c b/src/flb_reload.c index ea43a3554d4..796ed3e06c9 100644 --- a/src/flb_reload.c +++ b/src/flb_reload.c @@ -512,12 +512,19 @@ int flb_reload(flb_ctx_t *ctx, struct flb_cf *cf_opts) ret = flb_start(new_ctx); - /* Store the new value of hot reloading times into the new context */ - if (ret == 0) { - new_config->hot_reloaded_count = reloaded_count; - flb_debug("[reload] hot reloaded %d time(s)", reloaded_count); - new_config->hot_reloading = FLB_FALSE; + if (ret != 0) { + flb_stop(new_ctx); + flb_destroy(new_ctx); + + flb_error("[reload] loaded configuration contains error(s). Reloading is aborted"); + + return -1; } + /* Store the new value of hot reloading times into the new context */ + new_config->hot_reloaded_count = reloaded_count; + flb_debug("[reload] hot reloaded %d time(s)", reloaded_count); + new_config->hot_reloading = FLB_FALSE; + return 0; } diff --git a/src/fluent-bit.c b/src/fluent-bit.c index 8ecd517f859..b48d35c3241 100644 --- a/src/fluent-bit.c +++ b/src/fluent-bit.c @@ -1394,16 +1394,23 @@ int flb_main(int argc, char **argv) #endif if (flb_bin_restarting == FLB_RELOAD_IN_PROGRESS) { /* reload by using same config files/path */ - flb_reload(ctx, cf_opts); - ctx = flb_context_get(); - flb_bin_restarting = FLB_RELOAD_IDLE; + ret = flb_reload(ctx, cf_opts); + if (ret == 0) { + ctx = flb_context_get(); + flb_bin_restarting = FLB_RELOAD_IDLE; + } + else { + flb_bin_restarting = FLB_RELOAD_ABORTED; + } } } if (exit_signal) { flb_signal_exit(exit_signal); } - ret = ctx->config->exit_status_code; + if (flb_bin_restarting != FLB_RELOAD_ABORTED) { + ret = ctx->config->exit_status_code; + } cf_opts = flb_cf_context_get(); @@ -1425,8 +1432,12 @@ int flb_main(int argc, char **argv) } #endif - flb_stop(ctx); - flb_destroy(ctx); + if (flb_bin_restarting == FLB_RELOAD_ABORTED) { + fprintf(stderr, "reloading is aborted and exit\n"); + } else { + flb_stop(ctx); + flb_destroy(ctx); + } return ret; }