Skip to content

Commit 2552702

Browse files
author
MarcoFalke
committed
Merge #15367: feature: Added ability for users to add a startup command
090530c feature: Added ability for users to add a startup command (Ben Carman) Pull request description: Thoughts for adding the feature is for users to be able to add things like electrum-personal-server or lnd to run whenever Bitcoin Core is running. Open to feedback about the feature. ACKs for top commit: MarcoFalke: re-ACK 090530c dongcarl: tACK 090530c Tree-SHA512: ba514d2fc8b4fb12b781c1a9c89845a25fce0b80ba7c907761cde4abb81edd03fa643682edc895986dc20b273ac3b95769508806db7fbd99ec28623f85c41e67
2 parents c95784e + 090530c commit 2552702

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

doc/release-notes-15367.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Configuration option changes
2+
----------------------------
3+
4+
- The `startupnotify` option is used to specify a command to
5+
execute when Bitcoin Core has finished with its startup
6+
sequence. (#15367)

src/init.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,9 @@ void SetupServerArgs(NodeContext& node)
422422
argsman.AddArg("-reindex", "Rebuild chain state and block index from the blk*.dat files on disk", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
423423
argsman.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);
424424
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);
425+
#if HAVE_SYSTEM
426+
argsman.AddArg("-startupnotify=<cmd>", "Execute command on startup.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
427+
#endif
425428
#ifndef WIN32
426429
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);
427430
#else
@@ -674,6 +677,17 @@ static void CleanupBlockRevFiles()
674677
}
675678
}
676679

680+
#if HAVE_SYSTEM
681+
static void StartupNotify(const ArgsManager& args)
682+
{
683+
std::string cmd = args.GetArg("-startupnotify", "");
684+
if (!cmd.empty()) {
685+
std::thread t(runCommand, cmd);
686+
t.detach(); // thread runs free
687+
}
688+
}
689+
#endif
690+
677691
static void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles, const ArgsManager& args)
678692
{
679693
const CChainParams& chainparams = Params();
@@ -1973,5 +1987,9 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
19731987
banman->DumpBanlist();
19741988
}, DUMP_BANS_INTERVAL);
19751989

1990+
#if HAVE_SYSTEM
1991+
StartupNotify(args);
1992+
#endif
1993+
19761994
return true;
19771995
}

0 commit comments

Comments
 (0)