winlin

support reload pid.

@@ -505,6 +505,21 @@ int SrsConfig::reload() @@ -505,6 +505,21 @@ int SrsConfig::reload()
505 srs_trace("reload listen success."); 505 srs_trace("reload listen success.");
506 } 506 }
507 507
  508 + // merge config: pid
  509 + if (!srs_directive_equals(root->get("pid"), old_root->get("pid"))) {
  510 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  511 + ISrsReloadHandler* subscribe = *it;
  512 + if ((ret = subscribe->on_reload_pid()) != ERROR_SUCCESS) {
  513 + srs_error("notify subscribes reload pid failed. ret=%d", ret);
  514 + return ret;
  515 + }
  516 + }
  517 + srs_trace("reload pid success.");
  518 + }
  519 +
  520 + // directly supported for reload:
  521 + // chunk_size, ff_log_dir
  522 +
508 // merge config: pithy_print 523 // merge config: pithy_print
509 if (!srs_directive_equals(root->get("pithy_print"), old_root->get("pithy_print"))) { 524 if (!srs_directive_equals(root->get("pithy_print"), old_root->get("pithy_print"))) {
510 for (it = subscribes.begin(); it != subscribes.end(); ++it) { 525 for (it = subscribes.begin(); it != subscribes.end(); ++it) {
@@ -40,6 +40,11 @@ int ISrsReloadHandler::on_reload_listen() @@ -40,6 +40,11 @@ int ISrsReloadHandler::on_reload_listen()
40 return ERROR_SUCCESS; 40 return ERROR_SUCCESS;
41 } 41 }
42 42
  43 +int ISrsReloadHandler::on_reload_pid()
  44 +{
  45 + return ERROR_SUCCESS;
  46 +}
  47 +
43 int ISrsReloadHandler::on_reload_pithy_print() 48 int ISrsReloadHandler::on_reload_pithy_print()
44 { 49 {
45 return ERROR_SUCCESS; 50 return ERROR_SUCCESS;
@@ -42,6 +42,7 @@ public: @@ -42,6 +42,7 @@ public:
42 virtual ~ISrsReloadHandler(); 42 virtual ~ISrsReloadHandler();
43 public: 43 public:
44 virtual int on_reload_listen(); 44 virtual int on_reload_listen();
  45 + virtual int on_reload_pid();
45 virtual int on_reload_pithy_print(); 46 virtual int on_reload_pithy_print();
46 virtual int on_reload_vhost_added(std::string vhost); 47 virtual int on_reload_vhost_added(std::string vhost);
47 virtual int on_reload_vhost_removed(std::string vhost); 48 virtual int on_reload_vhost_removed(std::string vhost);
@@ -159,6 +159,7 @@ SrsServer::SrsServer() @@ -159,6 +159,7 @@ SrsServer::SrsServer()
159 { 159 {
160 signal_reload = false; 160 signal_reload = false;
161 signal_gmc_stop = false; 161 signal_gmc_stop = false;
  162 + pid_fd = -1;
162 163
163 // donot new object in constructor, 164 // donot new object in constructor,
164 // for some global instance is not ready now, 165 // for some global instance is not ready now,
@@ -189,6 +190,11 @@ SrsServer::~SrsServer() @@ -189,6 +190,11 @@ SrsServer::~SrsServer()
189 190
190 close_listeners(); 191 close_listeners();
191 192
  193 + if (pid_fd > 0) {
  194 + ::close(pid_fd);
  195 + pid_fd = -1;
  196 + }
  197 +
192 #ifdef SRS_HTTP_API 198 #ifdef SRS_HTTP_API
193 srs_freep(http_api_handler); 199 srs_freep(http_api_handler);
194 #endif 200 #endif
@@ -310,6 +316,7 @@ int SrsServer::acquire_pid_file() @@ -310,6 +316,7 @@ int SrsServer::acquire_pid_file()
310 } 316 }
311 317
312 srs_trace("write pid=%d to %s success!", pid, pid_file.c_str()); 318 srs_trace("write pid=%d to %s success!", pid, pid_file.c_str());
  319 + pid_fd = fd;
313 320
314 return ret; 321 return ret;
315 } 322 }
@@ -554,3 +561,13 @@ int SrsServer::on_reload_listen() @@ -554,3 +561,13 @@ int SrsServer::on_reload_listen()
554 { 561 {
555 return listen(); 562 return listen();
556 } 563 }
  564 +
  565 +int SrsServer::on_reload_pid()
  566 +{
  567 + if (pid_fd > 0) {
  568 + ::close(pid_fd);
  569 + pid_fd = -1;
  570 + }
  571 +
  572 + return acquire_pid_file();
  573 +}
@@ -88,6 +88,7 @@ private: @@ -88,6 +88,7 @@ private:
88 SrsIngester* ingester; 88 SrsIngester* ingester;
89 #endif 89 #endif
90 private: 90 private:
  91 + int pid_fd;
91 std::vector<SrsConnection*> conns; 92 std::vector<SrsConnection*> conns;
92 std::vector<SrsListener*> listeners; 93 std::vector<SrsListener*> listeners;
93 bool signal_reload; 94 bool signal_reload;
@@ -107,8 +108,10 @@ public: @@ -107,8 +108,10 @@ public:
107 private: 108 private:
108 virtual void close_listeners(); 109 virtual void close_listeners();
109 virtual int accept_client(SrsListenerType type, st_netfd_t client_stfd); 110 virtual int accept_client(SrsListenerType type, st_netfd_t client_stfd);
  111 +// interface ISrsThreadHandler.
110 public: 112 public:
111 virtual int on_reload_listen(); 113 virtual int on_reload_listen();
  114 + virtual int on_reload_pid();
112 }; 115 };
113 116
114 #endif 117 #endif