Skip to content

Commit 51a9f24

Browse files
committed
merge bitcoin#23395: Add -shutdownnotify option
1 parent af0e14d commit 51a9f24

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

doc/release-notes-6901.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Notable changes
2+
===============
3+
4+
New settings
5+
------------
6+
7+
- The `shutdownnotify` option is used to specify a command to execute synchronously
8+
before Dash Core has begun its shutdown sequence.

src/init.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,24 @@ static fs::path GetPidFile(const ArgsManager& args)
224224
// shutdown thing.
225225
//
226226

227+
#if HAVE_SYSTEM
228+
static void ShutdownNotify(const ArgsManager& args)
229+
{
230+
std::vector<std::thread> threads;
231+
for (const auto& cmd : args.GetArgs("-shutdownnotify")) {
232+
threads.emplace_back(runCommand, cmd);
233+
}
234+
for (auto& t : threads) {
235+
t.join();
236+
}
237+
}
238+
#endif
239+
227240
void Interrupt(NodeContext& node)
228241
{
242+
#if HAVE_SYSTEM
243+
ShutdownNotify(*node.args);
244+
#endif
229245
InterruptHTTPServer();
230246
InterruptHTTPRPC();
231247
InterruptRPC();
@@ -552,6 +568,7 @@ void SetupServerArgs(ArgsManager& argsman)
552568
argsman.AddArg("-syncmempool", strprintf("Sync mempool from other nodes on start (default: %u)", DEFAULT_SYNC_MEMPOOL), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
553569
#if HAVE_SYSTEM
554570
argsman.AddArg("-startupnotify=<cmd>", "Execute command on startup.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
571+
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);
555572
#endif
556573
#ifndef WIN32
557574
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);

test/functional/feature_notifications.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ def setup_network(self):
3434
self.alertnotify_dir = os.path.join(self.options.tmpdir, "alertnotify")
3535
self.blocknotify_dir = os.path.join(self.options.tmpdir, "blocknotify")
3636
self.walletnotify_dir = os.path.join(self.options.tmpdir, "walletnotify")
37+
self.shutdownnotify_dir = os.path.join(self.options.tmpdir, "shutdownnotify")
38+
self.shutdownnotify_file = os.path.join(self.shutdownnotify_dir, "shutdownnotify.txt")
3739
self.chainlocknotify_dir = os.path.join(self.options.tmpdir, "chainlocknotify")
3840
self.instantsendnotify_dir = os.path.join(self.options.tmpdir, "instantsendnotify")
3941
os.mkdir(self.alertnotify_dir)
4042
os.mkdir(self.blocknotify_dir)
4143
os.mkdir(self.walletnotify_dir)
44+
os.mkdir(self.shutdownnotify_dir)
4245
os.mkdir(self.chainlocknotify_dir)
4346
os.mkdir(self.instantsendnotify_dir)
4447

@@ -47,6 +50,7 @@ def setup_network(self):
4750
self.extra_args = [[
4851
f"-alertnotify=echo > {os.path.join(self.alertnotify_dir, '%s')}",
4952
f"-blocknotify=echo > {os.path.join(self.blocknotify_dir, '%s')}",
53+
f"-shutdownnotify=echo > {self.shutdownnotify_file}",
5054
f"-chainlocknotify=echo > {os.path.join(self.chainlocknotify_dir, '%s')}",
5155
], [
5256
"-rescan",
@@ -145,6 +149,10 @@ def run_test(self):
145149

146150
# TODO: add test for `-alertnotify` large fork notifications
147151

152+
self.log.info("test -shutdownnotify")
153+
self.stop_nodes()
154+
self.wait_until(lambda: os.path.isfile(self.shutdownnotify_file), timeout=10)
155+
148156
def expect_wallet_notify(self, tx_details):
149157
self.wait_until(lambda: len(os.listdir(self.walletnotify_dir)) >= len(tx_details), timeout=10)
150158
# Should have no more and no less files than expected

0 commit comments

Comments
 (0)