mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
Merge bitcoin/bitcoin#23395: util: Add -shutdownnotify option
d96d97ad30doc: Add release note for shutdownnotify. (klementtan)0bd73e2c45util: Add -shutdownnotify option. (klementtan) Pull request description: **Description**: Similar to `-startupnotify`, this PR adds a new option to allow users to specify a command to be executed when Bitcoin Core shuts down. **Note**: The `shutdownnotify` commands will not be executed if bitcoind shut down due to *unexpected* reasons (ie `killall -9 bitcoind`). ### Testing: **Normal shutdown commands** ``` # start bitcoind with shutdownnotify optioin ./src/bitcoind -signet -shutdownnotify="touch foo.txt" # shutdown bitcoind ./src/bitcoin-cli -signet stop # check that foo.txt has been created ``` **Final RPC call** Commands: ``` $ ./src/bitcoind -signet -nolisten -noconnect -shutdownnotify="./src/bitcoin-cli -signet getblockchaininfo > tmp.txt" $ ./src/bitcoin-cli stop $ cat tmp.txt ``` <details> <summary>Screen Shot</summary>  </details> ACKs for top commit: achow101: ACKd96d97ad301440000bytes: ACKd96d97ad30theStack: re-ACKd96d97ad30Tree-SHA512: 16f7406fd232e8b97aea5e58854c84755b0c35c88cb3ef9ee123b29a1475a376122b1e100da860cc336d4d657e6046a70e915fdb9b70c9fd097c6eef1b028161
This commit is contained in:
17
src/init.cpp
17
src/init.cpp
@@ -191,8 +191,24 @@ static fs::path GetPidFile(const ArgsManager& args)
|
||||
// shutdown thing.
|
||||
//
|
||||
|
||||
#if HAVE_SYSTEM
|
||||
static void ShutdownNotify(const ArgsManager& args)
|
||||
{
|
||||
std::vector<std::thread> threads;
|
||||
for (const auto& cmd : args.GetArgs("-shutdownnotify")) {
|
||||
threads.emplace_back(runCommand, cmd);
|
||||
}
|
||||
for (auto& t : threads) {
|
||||
t.join();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void Interrupt(NodeContext& node)
|
||||
{
|
||||
#if HAVE_SYSTEM
|
||||
ShutdownNotify(*node.args);
|
||||
#endif
|
||||
InterruptHTTPServer();
|
||||
InterruptHTTPRPC();
|
||||
InterruptRPC();
|
||||
@@ -441,6 +457,7 @@ void SetupServerArgs(ArgsManager& argsman)
|
||||
argsman.AddArg("-settings=<file>", strprintf("Specify path to dynamic settings data file. Can be disabled with -nosettings. File is written at runtime and not meant to be edited by users (use %s instead for custom settings). Relative paths will be prefixed by datadir location. (default: %s)", BITCOIN_CONF_FILENAME, BITCOIN_SETTINGS_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||
#if HAVE_SYSTEM
|
||||
argsman.AddArg("-startupnotify=<cmd>", "Execute command on startup.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||
argsman.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
|
||||
argsman.AddArg("-sysperms", "Create new files with system default permissions, instead of umask 077 (only effective with disabled wallet functionality)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||
|
||||
Reference in New Issue
Block a user