Skip to content

Commit 090530c

Browse files
committed
feature: Added ability for users to add a startup command
1 parent 30568d3 commit 090530c

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
@@ -670,6 +673,17 @@ static void CleanupBlockRevFiles()
670673
}
671674
}
672675

676+
#if HAVE_SYSTEM
677+
static void StartupNotify(const ArgsManager& args)
678+
{
679+
std::string cmd = args.GetArg("-startupnotify", "");
680+
if (!cmd.empty()) {
681+
std::thread t(runCommand, cmd);
682+
t.detach(); // thread runs free
683+
}
684+
}
685+
#endif
686+
673687
static void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles, const ArgsManager& args)
674688
{
675689
const CChainParams& chainparams = Params();
@@ -1969,5 +1983,9 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
19691983
banman->DumpBanlist();
19701984
}, DUMP_BANS_INTERVAL);
19711985

1986+
#if HAVE_SYSTEM
1987+
StartupNotify(args);
1988+
#endif
1989+
19721990
return true;
19731991
}

0 commit comments

Comments
 (0)