Skip to content

Commit

Permalink
For #1635, inotify watch ConfigMap for reload. 3.0.133
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Mar 12, 2020
1 parent 88368ed commit bb509d2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
31 changes: 17 additions & 14 deletions trunk/src/app/srs_app_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ SrsInotifyWorker::SrsInotifyWorker(SrsServer* s)
server = s;
trd = new SrsSTCoroutine("inotify", this);
inotify_fd = NULL;
watch_conf = watch_k8s = 0;
}

SrsInotifyWorker::~SrsInotifyWorker()
Expand Down Expand Up @@ -540,20 +541,22 @@ srs_error_t SrsInotifyWorker::start()
string config_dir = srs_path_dirname(_srs_config->config());
if (true) {
uint32_t mask = IN_ALL_EVENTS;
if (::inotify_add_watch(fd, config_dir.c_str(), mask) < 0) {
return srs_error_new(ERROR_INOTIFY_WATCH, "watch file=%s, fd=%d, mask=%#x", config_dir.c_str(), fd, mask);
if ((watch_conf = ::inotify_add_watch(fd, config_dir.c_str(), mask)) < 0) {
return srs_error_new(ERROR_INOTIFY_WATCH, "watch file=%s, fd=%d, watch=%d, mask=%#x",
config_dir.c_str(), fd, watch_conf, mask);
}
srs_trace("auto reload watching fd=%d, file=%s", fd, config_dir.c_str());
srs_trace("auto reload watching fd=%d, watch=%d, file=%s", fd, watch_conf, config_dir.c_str());
}

// Watch k8s sub directory.
string k8s_file = config_dir + "/..data";
if (srs_path_exists(k8s_file)) {
uint32_t mask = IN_ALL_EVENTS;
if (::inotify_add_watch(fd, k8s_file.c_str(), mask) < 0) {
return srs_error_new(ERROR_INOTIFY_WATCH, "watch file=%s, fd=%d, mask=%#x", k8s_file.c_str(), fd, mask);
if ((watch_k8s = ::inotify_add_watch(fd, k8s_file.c_str(), mask)) < 0) {
return srs_error_new(ERROR_INOTIFY_WATCH, "watch file=%s, fd=%d, watch=%d, mask=%#x",
k8s_file.c_str(), fd, watch_k8s, mask);
}
srs_trace("auto reload watching fd=%d, file=%s", fd, k8s_file.c_str());
srs_trace("auto reload watching fd=%d, watch=%d, file=%s", fd, watch_k8s, k8s_file.c_str());
}

if ((err = trd->start()) != srs_success) {
Expand Down Expand Up @@ -587,14 +590,14 @@ srs_error_t SrsInotifyWorker::cycle()
for (char* ptr = buf; ptr < buf + nn; ptr += sizeof(inotify_event) + ie->len) {
ie = (inotify_event*)ptr;

if (!ie->len || !ie->name) {
continue;
}

string name = ie->name;
if ((name == k8s_file || name == config_file) && ie->mask & (IN_MODIFY|IN_CREATE)) {
do_reload = true;
}
//if (!ie->len || !ie->name) {
// continue;
//}
//
//string name = ie->name;
//if ((name == k8s_file || name == config_file) && ie->mask & (IN_MODIFY|IN_CREATE)) {
// do_reload = true;
//}

srs_trace("inotify event wd=%d, mask=%#x, len=%d, name=%s, reload=%d", ie->wd, ie->mask, ie->len, ie->name, do_reload);
}
Expand Down
2 changes: 2 additions & 0 deletions trunk/src/app/srs_app_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ class SrsInotifyWorker : public ISrsCoroutineHandler
SrsServer* server;
SrsCoroutine* trd;
srs_netfd_t inotify_fd;
int watch_conf;
int watch_k8s;
public:
SrsInotifyWorker(SrsServer* s);
virtual ~SrsInotifyWorker();
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core_version3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
#ifndef SRS_CORE_VERSION3_HPP
#define SRS_CORE_VERSION3_HPP

#define SRS_VERSION3_REVISION 132
#define SRS_VERSION3_REVISION 133

#endif

0 comments on commit bb509d2

Please sign in to comment.