Permalink
Browse files

Write PID file before initializing globals.

Initializing globals can take a long time
(e.g. if the server has to index a large dataset
before serving requests), and it can be useful
to be able to kill the server during that time.
  • Loading branch information...
1 parent 1a88d41 commit 43d72c9af752521969e3e4d7fd3e6a9669750cb5 @avm avm committed Sep 24, 2012
Showing with 6 additions and 6 deletions.
  1. +2 −3 main/fcgi_server.cpp
  2. +2 −2 main/fcgi_server.h
  3. +2 −1 main/main.cpp
View
@@ -88,8 +88,6 @@ FCGIServer::start() {
status_ = LOADING;
- pid(globals_->config()->asString("/fastcgi/daemon/pidfile"));
-
logTimes_ = globals_->config()->asInt("/fastcgi/daemon/log-times", 0);
initMonitorThread();
@@ -372,7 +370,8 @@ FCGIServer::monitor() {
}
void
-FCGIServer::pid(const std::string &file) {
+FCGIServer::writePid(const Config& config) {
+ const std::string& file = config.asString("/fastcgi/daemon/pidfile");
try {
std::ofstream f(file.c_str());
f.exceptions(std::ios::badbit);
View
@@ -71,6 +71,8 @@ class FCGIServer : public Server {
public:
FCGIServer(boost::shared_ptr<Globals> globals);
virtual ~FCGIServer();
+
+ static void writePid(const Config& config);
void start();
void stop();
void join();
@@ -84,8 +86,6 @@ class FCGIServer : public Server {
std::string getServerInfo() const;
- void pid(const std::string &file);
-
void initMonitorThread();
void initRequestCache();
void initTimeStatistics();
View
@@ -102,7 +102,8 @@ main(int argc, char *argv[]) {
}
}
- std::auto_ptr<Config> config = Config::create(argc, argv);
+ boost::scoped_ptr<Config> config(Config::create(argc, argv));
+ FCGIServer::writePid(*config);
boost::shared_ptr<Globals> globals(new Globals(config.get()));
FCGIServer server(globals);
::server = &server;

0 comments on commit 43d72c9

Please sign in to comment.