Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check pid before init glog #2278

Merged
merged 2 commits into from Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 10 additions & 8 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;
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 @@ -59,14 +69,6 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE;
}

// Detect if the server has already been started
auto pidPath = FLAGS_pid_file;
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/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