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

util: Add -shutdownnotify option. #1345

Merged
merged 2 commits into from
Jun 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,24 @@ static std::unique_ptr<ECCVerifyHandle> globalVerifyHandle;
static boost::thread_group threadGroup;
static CScheduler scheduler;

#if HAVE_SYSTEM
static void ShutdownNotify()
{
std::vector<std::thread> threads;
for (const auto& cmd : gArgs.GetArgs("-shutdownnotify")) {
threads.emplace_back(runCommand, cmd);
}
for (auto& t : threads) {
t.join();
}
}
#endif

void Interrupt()
{
#if HAVE_SYSTEM
ShutdownNotify();
#endif
InterruptHTTPServer();
InterruptHTTPRPC();
InterruptRPC();
Expand Down Expand Up @@ -376,7 +392,7 @@ void SetupServerArgs()

// Hidden Options
std::vector<std::string> hidden_args = {
"-dbcrashratio", "-forcecompactdb",
"-dbcrashratio", "-forcecompactdb",
"-interrupt-block=<hash|height>", "-stop-block=<hash|height>",
"-mocknet", "-mocknet-blocktime=<secs>", "-mocknet-key=<pubkey>"
// GUI args. These will be overwritten by SetupUIArgs for the GUI
Expand Down Expand Up @@ -416,6 +432,9 @@ void SetupServerArgs()
"(default: 0 = disable pruning blocks, 1 = allow manual pruning via RPC, >=%u = automatically prune block files to stay under the specified target size in MiB)", MIN_DISK_SPACE_FOR_BLOCK_FILES / 1024 / 1024), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
gArgs.AddArg("-reindex", "Rebuild chain state and block index from the blk*.dat files on disk", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
gArgs.AddArg("-reindex-chainstate", "Rebuild chain state from the currently indexed blocks. When in pruning mode or if blocks on disk might be corrupted, use full -reindex instead.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#if HAVE_SYSTEM
gArgs.AddArg("-shutdownnotify=<cmd>", "Execute command immediately before beginning shutdown. The need for shutdown may be urgent, so be careful not to delay it long (if the command doesn't require interaction with the server, consider having it fork into the background).", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#endif
#ifndef WIN32
gArgs.AddArg("-sysperms", "Create new files with system default permissions, instead of umask 077 (only effective with disabled wallet functionality)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#else
Expand Down Expand Up @@ -1240,7 +1259,7 @@ bool AppInitParameterInteraction()
nMaxTipAge = gArgs.GetArg("-maxtipage", DEFAULT_MAX_TIP_AGE);
fIsFakeNet = Params().NetworkIDString() == "regtest" && gArgs.GetArg("-dummypos", false);
CTxOut::SERIALIZE_FORCED_TO_OLD_IN_TESTS = Params().NetworkIDString() == "regtest" && gArgs.GetArg("-txnotokens", false);

return true;
}

Expand Down