Skip to content

Commit

Permalink
Move shutdown logging to just before deleting the SQLitePool, which i…
Browse files Browse the repository at this point in the history
…s where unmapping happens
  • Loading branch information
tylerkaraszewski committed Jun 10, 2024
1 parent b2adefe commit 5211c7a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
10 changes: 10 additions & 0 deletions BedrockServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <arpa/inet.h>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <sys/resource.h>
#include <sys/time.h>
Expand Down Expand Up @@ -621,6 +622,15 @@ void BedrockServer::sync()
// until they return.
atomic_store(&_syncNode, shared_ptr<SQLiteNode>(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;
Expand Down
7 changes: 0 additions & 7 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
///
#include <dlfcn.h>
#include <iostream>
#include <fstream>
#include <signal.h>
#include <sys/resource.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -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;
}

0 comments on commit 5211c7a

Please sign in to comment.