Skip to content

Commit

Permalink
util: Add -shutdownnotify option. (#1345)
Browse files Browse the repository at this point in the history
Co-authored-by: klementtan <[email protected]>
Co-authored-by: Prasanna Loganathar <[email protected]>
  • Loading branch information
3 people authored and Bushstar committed Jul 5, 2022
1 parent 92d5d82 commit fb890f4
Showing 1 changed file with 21 additions and 2 deletions.
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 @@ -1241,7 +1260,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

0 comments on commit fb890f4

Please sign in to comment.