diff options
author | Ulrich Germann <Ulrich.Germann@gmail.com> | 2015-12-07 19:01:12 +0300 |
---|---|---|
committer | Ulrich Germann <Ulrich.Germann@gmail.com> | 2015-12-07 19:01:12 +0300 |
commit | 2be2481feb2d68d6e4ba366d06fcfa51f7ff664e (patch) | |
tree | b3f1c0806f3c6126d1d1376cbdf5bd16114fc01d /moses/server | |
parent | 3eccbeaf2b36997ed527603115bf95cd8072479f (diff) |
Added switch --daemon: fork and run moses server in background. The parent won't exit until the child is ready to serve.
Diffstat (limited to 'moses/server')
-rw-r--r-- | moses/server/Server.cpp | 15 | ||||
-rw-r--r-- | moses/server/Server.h | 4 |
2 files changed, 17 insertions, 2 deletions
diff --git a/moses/server/Server.cpp b/moses/server/Server.cpp index 8a78dd7bc..19073873f 100644 --- a/moses/server/Server.cpp +++ b/moses/server/Server.cpp @@ -1,5 +1,7 @@ // -*- mode: c++; indent-tabs-mode: nil; tab-width: 2 -*- #include "Server.h" +#include <sstream> + namespace MosesServer { Server:: @@ -16,6 +18,12 @@ namespace MosesServer m_registry.addMethod("close_session", m_close_session); } + Server:: + ~Server() + { + unlink(m_pidfile.c_str()); + } + int Server:: run() @@ -32,7 +40,12 @@ namespace MosesServer .keepaliveMaxConn(m_server_options.keepaliveMaxConn) .timeout(m_server_options.timeout) ); - + std::ostringstream pidfilename; + pidfilename << "/tmp/moses-server." << m_server_options.port << ".pid"; + m_pidfile = pidfilename.str(); + std::ofstream pidfile(m_pidfile.c_str()); + pidfile << getpid() << std::endl; + pidfile.close(); XVERBOSE(1,"Listening on port " << m_server_options.port << std::endl); if (m_server_options.is_serial) { diff --git a/moses/server/Server.h b/moses/server/Server.h index 4afbf5d91..802eaef3e 100644 --- a/moses/server/Server.h +++ b/moses/server/Server.h @@ -16,6 +16,7 @@ #include "CloseSession.h" #include "Session.h" #include "moses/parameters/ServerOptions.h" +#include <string> namespace MosesServer { @@ -28,9 +29,10 @@ namespace MosesServer xmlrpc_c::methodPtr const m_optimizer; xmlrpc_c::methodPtr const m_translator; xmlrpc_c::methodPtr const m_close_session; + std::string m_pidfile; public: Server(Moses::Parameter& params); - + ~Server(); int run(); void delete_session(uint64_t const session_id); |