mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 15:33:54 +01:00
ircd:Ⓜ️:app: Add autorun mechanism; conf items; program options.
This commit is contained in:
parent
5ed2022517
commit
813b686e97
5 changed files with 93 additions and 10 deletions
|
@ -24,6 +24,7 @@ bool single;
|
|||
bool debugmode;
|
||||
bool nolisten;
|
||||
bool nobackfill;
|
||||
bool noautoapps;
|
||||
bool noautomod;
|
||||
bool nocompact;
|
||||
bool checkdb;
|
||||
|
@ -59,6 +60,7 @@ lgetopt opts[]
|
|||
{ "execute", &execute, lgetopt::STRINGS, "Execute command lines immediately after startup" },
|
||||
{ "nolisten", &nolisten, lgetopt::BOOL, "Normal execution but without listening sockets" },
|
||||
{ "nobackfill", &nobackfill, lgetopt::BOOL, "Disable initial backfill jobs after startup." },
|
||||
{ "noautoapps", &noautoapps, lgetopt::BOOL, "Disable automatic execution of managed child applications." },
|
||||
{ "noautomod", &noautomod, lgetopt::BOOL, "Normal execution but without autoloading modules" },
|
||||
{ "nocompact", &nocompact, lgetopt::BOOL, "Disable automatic database compaction" },
|
||||
{ "checkdb", &checkdb, lgetopt::BOOL, "Perform complete checks of databases when opening" },
|
||||
|
@ -228,6 +230,7 @@ noexcept try
|
|||
opts.server_name = server_name;
|
||||
opts.bootstrap_vector_path = bootstrap;
|
||||
opts.backfill = !nobackfill;
|
||||
opts.autoapps = !noautoapps;
|
||||
const ircd::custom_ptr<ircd::m::homeserver> homeserver
|
||||
{
|
||||
// 6.1
|
||||
|
|
|
@ -18,6 +18,7 @@ struct ircd::m::app
|
|||
{
|
||||
static log::log log;
|
||||
static conf::item<bool> enable;
|
||||
static conf::item<bool> autorun;
|
||||
static conf::item<std::string> path;
|
||||
static std::set<std::string> bin;
|
||||
|
||||
|
|
|
@ -154,4 +154,7 @@ struct ircd::m::homeserver::opts
|
|||
|
||||
/// Whether to run initial backfill jobs after startup.
|
||||
bool backfill {true};
|
||||
|
||||
/// Whether to permit automatic execution of managed apps.
|
||||
bool autoapps {true};
|
||||
};
|
||||
|
|
|
@ -22,6 +22,12 @@ ircd::m::app::path
|
|||
{ "persist", false },
|
||||
};
|
||||
|
||||
decltype(ircd::m::app::autorun)
|
||||
ircd::m::app::autorun
|
||||
{
|
||||
{ "name", "ircd.m.app.autorun" },
|
||||
{ "default", true },
|
||||
};
|
||||
|
||||
decltype(ircd::m::app::enable)
|
||||
ircd::m::app::enable
|
||||
|
@ -51,23 +57,92 @@ ircd::util::instance_list<ircd::m::app>::list
|
|||
void
|
||||
ircd::m::app::init()
|
||||
{
|
||||
static const auto not_executable{[]
|
||||
(const std::string &file)
|
||||
{
|
||||
return !fs::is_exec(file);
|
||||
}};
|
||||
if(!enable || !path || ircd::read_only)
|
||||
return;
|
||||
|
||||
std::vector<std::string> files
|
||||
{
|
||||
bool(path)?
|
||||
fs::ls(string_view(path)):
|
||||
std::vector<std::string>{}
|
||||
fs::ls(string_view(path))
|
||||
};
|
||||
|
||||
bin = std::set<std::string>
|
||||
{
|
||||
begin(files), std::remove_if(begin(files), end(files), not_executable)
|
||||
begin(files), std::remove_if(begin(files), end(files), []
|
||||
(const std::string &file)
|
||||
{
|
||||
return !fs::is_exec(file);
|
||||
})
|
||||
};
|
||||
|
||||
log::debug
|
||||
{
|
||||
log, "Found %zu executable in `%s'",
|
||||
bin.size(),
|
||||
string_view{path},
|
||||
};
|
||||
|
||||
if(!autorun)
|
||||
{
|
||||
log::warning
|
||||
{
|
||||
log, "Autorun is disabled by the configuration. Apps may still be executed manually.",
|
||||
};
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
events::type::for_each_in("ircd.app.run.auto", []
|
||||
(const string_view &, const event::idx &run_event_idx)
|
||||
{
|
||||
const m::event::fetch run_event
|
||||
{
|
||||
std::nothrow, run_event_idx
|
||||
};
|
||||
|
||||
if(!run_event.valid || !my(run_event))
|
||||
return true;
|
||||
|
||||
const m::room room
|
||||
{
|
||||
at<"room_id"_>(run_event)
|
||||
};
|
||||
|
||||
const m::event::idx app_event_idx
|
||||
{
|
||||
room.get(std::nothrow, "ircd.app", at<"state_key"_>(run_event))
|
||||
};
|
||||
|
||||
if(!app_event_idx)
|
||||
return true;
|
||||
|
||||
const m::event::fetch app_event
|
||||
{
|
||||
std::nothrow, app_event_idx
|
||||
};
|
||||
|
||||
if(!app_event.valid || !my(app_event))
|
||||
return true;
|
||||
|
||||
log::debug
|
||||
{
|
||||
log, "Attempting app:%lu run.auto:%lu",
|
||||
app_event_idx,
|
||||
run_event_idx,
|
||||
};
|
||||
|
||||
auto app
|
||||
{
|
||||
std::make_unique<m::app>(app_event_idx)
|
||||
};
|
||||
|
||||
const auto pid
|
||||
{
|
||||
app->child.run()
|
||||
};
|
||||
|
||||
app.release();
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -279,7 +279,8 @@ try
|
|||
if(key && !key->verify_keys.empty())
|
||||
m::keys::cache::set(key->verify_keys);
|
||||
|
||||
m::app::init();
|
||||
if(opts->autoapps)
|
||||
m::app::init();
|
||||
|
||||
if(!ircd::maintenance)
|
||||
signon(*this);
|
||||
|
|
Loading…
Reference in a new issue