mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-10-11 03:53:22 +02:00
Merge bitcoin/bitcoin#23395: util: Add -shutdownnotify option
d96d97ad30
doc: Add release note for shutdownnotify. (klementtan)0bd73e2c45
util: 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: ACKd96d97ad30
1440000bytes: ACKd96d97ad30
theStack: re-ACKd96d97ad30
Tree-SHA512: 16f7406fd232e8b97aea5e58854c84755b0c35c88cb3ef9ee123b29a1475a376122b1e100da860cc336d4d657e6046a70e915fdb9b70c9fd097c6eef1b028161
This commit is contained in:
@@ -31,7 +31,7 @@ class NotificationsTest(BitcoinTestFramework):
|
||||
self.num_nodes = 2
|
||||
self.setup_clean_chain = True
|
||||
# The experimental syscall sandbox feature (-sandbox) is not compatible with -alertnotify,
|
||||
# -blocknotify or -walletnotify (which all invoke execve).
|
||||
# -blocknotify, -walletnotify or -shutdownnotify (which all invoke execve).
|
||||
self.disable_syscall_sandbox = True
|
||||
|
||||
def setup_network(self):
|
||||
@@ -39,14 +39,18 @@ class NotificationsTest(BitcoinTestFramework):
|
||||
self.alertnotify_dir = os.path.join(self.options.tmpdir, "alertnotify")
|
||||
self.blocknotify_dir = os.path.join(self.options.tmpdir, "blocknotify")
|
||||
self.walletnotify_dir = os.path.join(self.options.tmpdir, "walletnotify")
|
||||
self.shutdownnotify_dir = os.path.join(self.options.tmpdir, "shutdownnotify")
|
||||
self.shutdownnotify_file = os.path.join(self.shutdownnotify_dir, "shutdownnotify.txt")
|
||||
os.mkdir(self.alertnotify_dir)
|
||||
os.mkdir(self.blocknotify_dir)
|
||||
os.mkdir(self.walletnotify_dir)
|
||||
os.mkdir(self.shutdownnotify_dir)
|
||||
|
||||
# -alertnotify and -blocknotify on node0, walletnotify on node1
|
||||
self.extra_args = [[
|
||||
f"-alertnotify=echo > {os.path.join(self.alertnotify_dir, '%s')}",
|
||||
f"-blocknotify=echo > {os.path.join(self.blocknotify_dir, '%s')}",
|
||||
f"-shutdownnotify=echo > {self.shutdownnotify_file}",
|
||||
], [
|
||||
f"-walletnotify=echo %h_%b > {os.path.join(self.walletnotify_dir, notify_outputname('%w', '%s'))}",
|
||||
]]
|
||||
@@ -162,6 +166,10 @@ class NotificationsTest(BitcoinTestFramework):
|
||||
|
||||
# TODO: add test for `-alertnotify` large fork notifications
|
||||
|
||||
self.log.info("test -shutdownnotify")
|
||||
self.stop_nodes()
|
||||
self.wait_until(lambda: os.path.isfile(self.shutdownnotify_file), timeout=10)
|
||||
|
||||
def expect_wallet_notify(self, tx_details):
|
||||
self.wait_until(lambda: len(os.listdir(self.walletnotify_dir)) >= len(tx_details), timeout=10)
|
||||
# Should have no more and no less files than expected
|
||||
|
Reference in New Issue
Block a user