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
|
@ -863,7 +863,7 @@ srs_error_t SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
|
|||
}
|
||||
} else {
|
||||
SrsJsonObject* data = SrsJsonAny::object();
|
||||
obj->set("client", data);;
|
||||
obj->set("client", data);
|
||||
|
||||
if ((err = client->dumps(data)) != srs_success) {
|
||||
int code = srs_error_code(err);
|
||||
|
@ -907,6 +907,10 @@ SrsGoApiRaw::~SrsGoApiRaw()
|
|||
_srs_config->unsubscribe(this);
|
||||
}
|
||||
|
||||
extern srs_error_t _srs_reload_err;
|
||||
extern SrsReloadState _srs_reload_state;
|
||||
extern std::string _srs_reload_id;
|
||||
|
||||
srs_error_t SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
@ -937,8 +941,8 @@ srs_error_t SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage*
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// the rpc is required.
|
||||
// the allowd rpc method check.
|
||||
if (rpc.empty() || rpc != "reload") {
|
||||
// the allowed rpc method check.
|
||||
if (rpc.empty() || (rpc != "reload" && rpc != "reload-fetch")) {
|
||||
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW);
|
||||
}
|
||||
|
||||
|
@ -950,6 +954,16 @@ srs_error_t SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage*
|
|||
|
||||
server->on_signal(SRS_SIGNAL_RELOAD);
|
||||
return srs_api_response_code(w, r, ERROR_SUCCESS);
|
||||
} else if (rpc == "reload-fetch") {
|
||||
SrsJsonObject* data = SrsJsonAny::object();
|
||||
obj->set("data", data);
|
||||
|
||||
data->set("err", SrsJsonAny::integer(srs_error_code(_srs_reload_err)));
|
||||
data->set("msg", SrsJsonAny::str(srs_error_summary(_srs_reload_err).c_str()));
|
||||
data->set("state", SrsJsonAny::integer(_srs_reload_state));
|
||||
data->set("rid", SrsJsonAny::str(_srs_reload_id.c_str()));
|
||||
|
||||
return srs_api_response(w, r, obj->dumps());
|
||||
}
|
||||
|
||||
return err;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue