Skip to content

Commit

Permalink
check pid before init glog (#2278)
Browse files Browse the repository at this point in the history
* check pid before init glog

* compile error
  • Loading branch information
liuyu85cn committed Aug 7, 2020
1 parent 24a7142 commit a5275b1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
20 changes: 11 additions & 9 deletions src/daemons/GraphDaemon.cpp
Expand Up @@ -33,6 +33,16 @@ static void printHelp(const char *prog);
DECLARE_string(flagfile);

int main(int argc, char *argv[]) {
// Detect if the server has already been started
// Check pid before glog init, in case of user may start daemon twice
// the 2nd will make the 1st failed to output log anymore
auto pidPath = FLAGS_pid_file;
auto status = ProcessUtils::isPidAvailable(pidPath);
if (!status.ok()) {
LOG(ERROR) << status;
return EXIT_FAILURE;
}

google::SetVersionString(nebula::versionString());
if (argc == 1) {
printHelp(argv[0]);
Expand All @@ -53,15 +63,7 @@ int main(int argc, char *argv[]) {
}

// Setup logging
auto status = setupLogging();
if (!status.ok()) {
LOG(ERROR) << status;
return EXIT_FAILURE;
}

// Detect if the server has already been started
auto pidPath = FLAGS_pid_file;
status = ProcessUtils::isPidAvailable(pidPath);
status = setupLogging();
if (!status.ok()) {
LOG(ERROR) << status;
return EXIT_FAILURE;
Expand Down
18 changes: 10 additions & 8 deletions src/daemons/MetaDaemon.cpp
Expand Up @@ -159,6 +159,16 @@ Status initWebService(nebula::WebService* svc,
}

int main(int argc, char *argv[]) {
// Detect if the server has already been started
// Check pid before glog init, in case of user may start daemon twice
// the 2nd will make the 1st failed to output log anymore
auto pidPath = FLAGS_pid_file;
auto status = ProcessUtils::isPidAvailable(pidPath);
if (!status.ok()) {
LOG(ERROR) << status;
return EXIT_FAILURE;
}

google::SetVersionString(nebula::versionString());
folly::init(&argc, &argv, true);
if (FLAGS_data_path.empty()) {
Expand All @@ -172,14 +182,6 @@ int main(int argc, char *argv[]) {
google::SetStderrLogging(google::INFO);
}

// Detect if the server has already been started
auto pidPath = FLAGS_pid_file;
auto status = ProcessUtils::isPidAvailable(pidPath);
if (!status.ok()) {
LOG(ERROR) << status;
return EXIT_FAILURE;
}

if (FLAGS_daemonize) {
status = ProcessUtils::daemonize(pidPath);
if (!status.ok()) {
Expand Down
18 changes: 10 additions & 8 deletions src/daemons/StorageDaemon.cpp
Expand Up @@ -33,22 +33,24 @@ static Status setupSignalHandler();
std::unique_ptr<nebula::storage::StorageServer> gStorageServer;

int main(int argc, char *argv[]) {
google::SetVersionString(nebula::versionString());
folly::init(&argc, &argv, true);
if (FLAGS_daemonize) {
google::SetStderrLogging(google::FATAL);
} else {
google::SetStderrLogging(google::INFO);
}

// Detect if the server has already been started
// Check pid before glog init, in case of user may start daemon twice
// the 2nd will make the 1st failed to output log anymore
auto pidPath = FLAGS_pid_file;
auto status = ProcessUtils::isPidAvailable(pidPath);
if (!status.ok()) {
LOG(ERROR) << status;
return EXIT_FAILURE;
}

google::SetVersionString(nebula::versionString());
folly::init(&argc, &argv, true);
if (FLAGS_daemonize) {
google::SetStderrLogging(google::FATAL);
} else {
google::SetStderrLogging(google::INFO);
}

if (FLAGS_daemonize) {
status = ProcessUtils::daemonize(pidPath);
if (!status.ok()) {
Expand Down

0 comments on commit a5275b1

Please sign in to comment.