diff --git a/BedrockServer.cpp b/BedrockServer.cpp index 5a1de2175..e20853cae 100644 --- a/BedrockServer.cpp +++ b/BedrockServer.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -621,6 +622,15 @@ void BedrockServer::sync() // until they return. atomic_store(&_syncNode, shared_ptr(nullptr)); + // If we're not detaching, save that we're shutting down. + if (!_detach) { + ofstream file("/var/log/bedrock_shutdown", std::ios::app); + if (file) { + file << "shutdown " << getpid() << " " << SComposeTime("%Y-%m-%dT%H:%M:%S", STimeNow()) << endl; + file.close(); + } + } + // Release the current DB pool, and zero out our pointer. If any socket threads hold a handle to `_syncNode`, they will keep this in existence // until they release it. _dbPool = nullptr; diff --git a/main.cpp b/main.cpp index ff6ef35b4..56989a865 100644 --- a/main.cpp +++ b/main.cpp @@ -4,7 +4,6 @@ /// #include #include -#include #include #include #include @@ -401,12 +400,6 @@ int main(int argc, char* argv[]) { // All done SINFO("Graceful process shutdown complete"); - // Save that we're shutting down. - ofstream file("/var/log/bedrock_shutdown", std::ios::app); - if (file) { - file << "shutdown " << getpid() << " " << SComposeTime("%Y-%m-%dT%H:%M:%S", STimeNow()) << endl; - file.close(); - } return 0; }