]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: signal shuts down fcgi socket
authorYehuda Sadeh <yehuda@inktank.com>
Wed, 21 Nov 2012 00:30:08 +0000 (16:30 -0800)
committerYehuda Sadeh <yehuda@inktank.com>
Wed, 21 Nov 2012 20:09:03 +0000 (12:09 -0800)
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/rgw/rgw_main.cc
src/rgw/rgw_tools.cc
src/rgw/rgw_tools.h

index bdcee9d11ac8d79db4f07a4640d9aa1550436009..c8108f1d50b4bd052c7d594f8ba40daf3755a04e 100644 (file)
@@ -61,20 +61,12 @@ static sighandler_t sighandler_usr1;
 static sighandler_t sighandler_alrm;
 static sighandler_t sighandler_term;
 
+class RGWProcess;
 
-#define SOCKET_BACKLOG 1024
+static RGWProcess *pprocess = NULL;
 
-static void godown_handler(int signum)
-{
-  FCGX_ShutdownPending();
-  signal(signum, sighandler_usr1);
-  alarm(5);
-}
 
-static void godown_alarm(int signum)
-{
-  _exit(0);
-}
+#define SOCKET_BACKLOG 1024
 
 struct RGWRequest
 {
@@ -131,6 +123,7 @@ class RGWProcess {
   ThreadPool m_tp;
   Throttle req_throttle;
   RGWREST *rest;
+  int sock_fd;
 
   struct RGWWQ : public ThreadPool::WorkQueue<RGWRequest> {
     RGWProcess *process;
@@ -188,17 +181,22 @@ public:
   RGWProcess(CephContext *cct, RGWRados *rgwstore, int num_threads, RGWREST *_rest)
     : store(rgwstore), m_tp(cct, "RGWProcess::m_tp", num_threads),
       req_throttle(cct, "rgw_ops", num_threads * 2),
-      rest(_rest),
+      rest(_rest), sock_fd(-1),
       req_wq(this, g_conf->rgw_op_thread_timeout,
             g_conf->rgw_op_thread_suicide_timeout, &m_tp),
       max_req_id(0) {}
   void run();
   void handle_request(RGWRequest *req);
+
+  void close_fd() {
+    if (sock_fd >= 0)
+      close(sock_fd);
+  }
 };
 
 void RGWProcess::run()
 {
-  int s = 0;
+  sock_fd = 0;
   if (!g_conf->rgw_socket_path.empty()) {
     string path_str = g_conf->rgw_socket_path;
 
@@ -216,9 +214,9 @@ void RGWProcess::run()
     }
 
     const char *path = path_str.c_str();
-    s = FCGX_OpenSocket(path, SOCKET_BACKLOG);
-    if (s < 0) {
-      dout(0) << "ERROR: FCGX_OpenSocket (" << path << ") returned " << s << dendl;
+    sock_fd = FCGX_OpenSocket(path, SOCKET_BACKLOG);
+    if (sock_fd < 0) {
+      dout(0) << "ERROR: FCGX_OpenSocket (" << path << ") returned " << sock_fd << dendl;
       return;
     }
     if (chmod(path, 0777) < 0) {
@@ -232,7 +230,7 @@ void RGWProcess::run()
     RGWRequest *req = new RGWRequest;
     req->id = ++max_req_id;
     dout(10) << "allocated request req=" << hex << req << dec << dendl;
-    FCGX_InitRequest(&req->fcgx, s, 0);
+    FCGX_InitRequest(&req->fcgx, sock_fd, 0);
     req_throttle.get(1);
     int ret = FCGX_Accept_r(&req->fcgx);
     if (ret < 0) {
@@ -248,6 +246,19 @@ void RGWProcess::run()
   m_tp.stop();
 }
 
+static void godown_handler(int signum)
+{
+  FCGX_ShutdownPending();
+  pprocess->close_fd();
+  signal(signum, sighandler_usr1);
+  alarm(5);
+}
+
+static void godown_alarm(int signum)
+{
+  _exit(0);
+}
+
 static int call_log_intent(RGWRados *store, void *ctx, rgw_obj& obj, RGWIntentEvent intent)
 {
   struct req_state *s = (struct req_state *)ctx;
@@ -486,6 +497,9 @@ int main(int argc, const char **argv)
   }
 
   RGWProcess process(g_ceph_context, store, g_conf->rgw_thread_pool_size, &rest);
+
+  pprocess = &process;
+
   process.run();
 
   if (do_swift) {
@@ -500,6 +514,7 @@ int main(int argc, const char **argv)
 
   RGWStoreManager::close_storage(store);
 
+  rgw_tools_cleanup();
   curl_global_cleanup();
   g_ceph_context->put();
 
index 4201bd42d06e9bfe999ea44599b5b75c847a26c7..b6d9f28477194dad246aaee16136c709986102b4 100644 (file)
@@ -161,3 +161,8 @@ int rgw_tools_init(CephContext *cct)
 
   return 0;
 }
+
+void rgw_tools_cleanup()
+{
+  ext_mime_map.clear();
+}
index 7860ea3819e210fd4069eb1b17deeeebdaa6b80b..6553d9d146540312ba1da0857f765779a1c184f0 100644 (file)
@@ -12,6 +12,7 @@ int rgw_put_system_obj(RGWRados *rgwstore, rgw_bucket& bucket, string& oid, cons
 int rgw_get_obj(RGWRados *rgwstore, void *ctx, rgw_bucket& bucket, string& key, bufferlist& bl, map<string, bufferlist> *pattrs = NULL);
 
 int rgw_tools_init(CephContext *cct);
+void rgw_tools_cleanup();
 const char *rgw_find_mime_by_ext(string& ext);
 
 #endif