Merge #15367: feature: Added ability for users to add a startup command

090530cc24054d6b4658752bb88f75a3b73eab5d 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 090530cc24
  dongcarl:
    tACK 090530c

Tree-SHA512: ba514d2fc8b4fb12b781c1a9c89845a25fce0b80ba7c907761cde4abb81edd03fa643682edc895986dc20b273ac3b95769508806db7fbd99ec28623f85c41e67
This commit is contained in:
MarcoFalke 2020-09-28 20:44:25 +02:00 committed by PastaPastaPasta
parent 2099a5c2e5
commit 08349ee1da
2 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,6 @@
Configuration option changes
----------------------------
- The `startupnotify` option is used to specify a command to
execute when Dash Core has finished with its startup
sequence. (#5728)

View File

@ -539,6 +539,9 @@ void SetupServerArgs(NodeContext& node)
"(default: 0 = disable pruning blocks, 1 = allow manual pruning via RPC, >%u = automatically prune block files to stay under the specified target size in MiB)", MIN_DISK_SPACE_FOR_BLOCK_FILES / 1024 / 1024), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
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);
argsman.AddArg("-syncmempool", strprintf("Sync mempool from other nodes on start (default: %u)", DEFAULT_SYNC_MEMPOOL), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#if HAVE_SYSTEM
argsman.AddArg("-startupnotify=<cmd>", "Execute command on startup.", 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);
#else
@ -859,6 +862,17 @@ static void CleanupBlockRevFiles()
}
}
#if HAVE_SYSTEM
static void StartupNotify(const ArgsManager& args)
{
std::string cmd = args.GetArg("-startupnotify", "");
if (!cmd.empty()) {
std::thread t(runCommand, cmd);
t.detach(); // thread runs free
}
}
#endif
static void PeriodicStats(ArgsManager& args, const CTxMemPool& mempool)
{
assert(args.GetBoolArg("-statsenabled", DEFAULT_STATSD_ENABLE));
@ -2537,5 +2551,9 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
banman->DumpBanlist();
}, DUMP_BANS_INTERVAL);
#if HAVE_SYSTEM
StartupNotify(args);
#endif
return true;
}