mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Support HTTP-API for fetching reload result. v5.0.176 v6.0.71 (#3779)
## Reload Error Ignore During a Reload, several stages will be passed through: 1. Parsing new configurations: Parse. 2. Transforming configurations: Transform. 3. Applying configurations: Apply. Previously, any error at any stage would result in a direct exit, making the system completely dependent on configuration checks: ```bash ./objs/srs -c conf/srs.conf -t echo $? #0 ``` Optimized to: If an error occurs before applying the configuration, it can be ignored. If an error occurs during the application of the configuration, some of the configuration may have already taken effect, leading to unpredictable behavior, so SRS will exit directly. ## Reload Fetch API Added a new HTTP API to query the result of the reload. ```nginx http_api { enabled on; raw_api { enabled on; allow_reload on; } } ``` ```bash curl http://localhost:1985/api/v1/raw?rpc=reload-fetch ``` ```json { "code": 0, "data": { "err": 0, "msg": "Success", "state": 0, "rid": "0s6y0n9" } } { "code": 0, "data": { "err": 1023, "msg": "code=1023(ConfigInvalid) : parse file : parse buffer containers/conf/srs.release-local.conf : root parse : parse dir : parse include buffer containers/data/config/srs.vhost.conf : read token, line=0, state=0 : line 3: unexpected end of file, expecting ; or \"}\"", "state": 1, "rid": "0g4z471" } } ``` This way, you can know if the last reload of the system was successful. --------- Co-authored-by: Haibo Chen <495810242@qq.com>
This commit is contained in:
parent
bb9331186b
commit
aa5ec87fcb
10 changed files with 84 additions and 20 deletions
|
@ -870,7 +870,9 @@ srs_error_t SrsServer::cycle()
|
|||
}
|
||||
|
||||
// Do server main cycle.
|
||||
err = do_cycle();
|
||||
if ((err = do_cycle()) != srs_success) {
|
||||
srs_error("server err %s", srs_error_desc(err).c_str());
|
||||
}
|
||||
|
||||
// OK, SRS server is done.
|
||||
wg_->done();
|
||||
|
@ -942,6 +944,10 @@ void SrsServer::on_signal(int signo)
|
|||
}
|
||||
}
|
||||
|
||||
srs_error_t _srs_reload_err;
|
||||
SrsReloadState _srs_reload_state;
|
||||
std::string _srs_reload_id;
|
||||
|
||||
srs_error_t SrsServer::do_cycle()
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
@ -991,12 +997,27 @@ srs_error_t SrsServer::do_cycle()
|
|||
// do reload the config.
|
||||
if (signal_reload) {
|
||||
signal_reload = false;
|
||||
srs_info("get signal to reload the config.");
|
||||
srs_trace("starting reload config.");
|
||||
|
||||
if ((err = _srs_config->reload()) != srs_success) {
|
||||
return srs_error_wrap(err, "config reload");
|
||||
SrsReloadState state = SrsReloadStateInit;
|
||||
_srs_reload_state = SrsReloadStateInit; srs_freep(_srs_reload_err); _srs_reload_id = srs_random_str(7);
|
||||
err = _srs_config->reload(&state);
|
||||
_srs_reload_state = state; _srs_reload_err = srs_error_copy(err);
|
||||
if (err != srs_success) {
|
||||
// If the parsing and transformation of the configuration fail, we can tolerate it by simply
|
||||
// ignoring the new configuration and continuing to use the current one. However, if the
|
||||
// application of the new configuration fails, some configurations may be applied while
|
||||
// others may not. For instance, the listening port may be closed when the configuration
|
||||
// is set to listen on an unavailable port. In such cases, we should terminate the service.
|
||||
if (state == SrsReloadStateApplying) {
|
||||
return srs_error_wrap(err, "reload fatal error state=%d", state);
|
||||
}
|
||||
|
||||
srs_warn("reload failed, state=%d, err %s", state, srs_error_desc(err).c_str());
|
||||
srs_freep(err);
|
||||
} else {
|
||||
srs_trace("reload config success, state=%d.", state);
|
||||
}
|
||||
srs_trace("reload config success.");
|
||||
}
|
||||
|
||||
srs_usleep(1 * SRS_UTIME_SECONDS);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue