mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2026-01-21 03:50:46 -08:00
Merge pull request #7 from zerotier/2279-prometheus-after-daemonize
Stop and restart the Prometheus worker thread when daemonizing
This commit is contained in:
commit
b8e3ca6a2c
2 changed files with 15 additions and 1 deletions
|
|
@ -50,6 +50,16 @@ namespace prometheus {
|
|||
public:
|
||||
SaveToFile() = default;
|
||||
|
||||
void stop() {
|
||||
must_die = true;
|
||||
worker_thread.join();
|
||||
}
|
||||
|
||||
void restart() {
|
||||
must_die = false;
|
||||
worker_thread = std::thread(&SaveToFile::worker_function, this);
|
||||
}
|
||||
|
||||
~SaveToFile() {
|
||||
must_die = true;
|
||||
worker_thread.join();
|
||||
|
|
|
|||
6
one.cpp
6
one.cpp
|
|
@ -2330,14 +2330,18 @@ int main(int argc, char** argv)
|
|||
}
|
||||
#endif // !ZT_ONE_NO_ROOT_CHECK
|
||||
if (runAsDaemon) {
|
||||
prometheus::simpleapi::saver.stop();
|
||||
|
||||
long p = (long)fork();
|
||||
if (p < 0) {
|
||||
fprintf(stderr, "%s: could not fork" ZT_EOL_S, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
else if (p > 0)
|
||||
return 0; // forked
|
||||
_Exit(0); // forked
|
||||
// else p == 0, so we are daemonized
|
||||
|
||||
prometheus::simpleapi::saver.restart();
|
||||
}
|
||||
#endif // __UNIX_LIKE__
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue