From a21e03df2716be98a60cd47f328e10c8d03f7e9d Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 2 Mar 2019 12:25:51 -0800 Subject: [PATCH] ircd: Add restart support w/ console cmd. --- construct/construct.cc | 9 ++++++++- include/ircd/ircd.h | 5 +++-- include/ircd/run.h | 5 ++--- ircd/ircd.cc | 8 ++++++++ modules/console.cc | 8 ++++++++ 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/construct/construct.cc b/construct/construct.cc index 50af20d79..736056c6d 100644 --- a/construct/construct.cc +++ b/construct/construct.cc @@ -70,12 +70,14 @@ const char *const usererrstr %s )"}; -int main(int argc, char *const *argv, const char *const *const envp) +int main(int _argc, char *const *_argv, char *const *const _envp) try { umask(077); // better safe than sorry --SRB // '-' switched arguments come first; this function incs argv and decs argc + auto argc(_argc); + auto argv(_argv), envp(_envp); parseargs(&argc, &argv, opts); applyargs(); @@ -149,6 +151,11 @@ try // Execution. // Blocks until a clean exit from a quit() or an exception comes out of it. ios.run(); + + // The restart flag can be set by the console command "restart" which + // calls ircd::quit() to clean break from the run() loop. + if(ircd::restart) + ircd::syscall(::execve, _argv[0], _argv, _envp); } catch(const ircd::user_error &e) { diff --git a/include/ircd/ircd.h b/include/ircd/ircd.h index df92a7c83..2147afe34 100644 --- a/include/ircd/ircd.h +++ b/include/ircd/ircd.h @@ -65,9 +65,10 @@ namespace ircd { struct init; - extern conf::item debugmode; - seconds uptime(); void init(boost::asio::io_context &ios, const string_view &origin, const string_view &hostname); bool quit() noexcept; + + extern conf::item restart; + extern conf::item debugmode; } diff --git a/include/ircd/run.h b/include/ircd/run.h index be28bb5fd..4b8376660 100644 --- a/include/ircd/run.h +++ b/include/ircd/run.h @@ -21,11 +21,10 @@ namespace ircd::run enum class level :int; struct changed; - extern const enum level &level; - string_view reflect(const enum level &); - bool set(const enum level &); + + extern const enum level &level; } /// An instance of this class registers itself to be called back when diff --git a/ircd/ircd.cc b/ircd/ircd.cc index 077880971..5d7bbf2bb 100644 --- a/ircd/ircd.cc +++ b/ircd/ircd.cc @@ -25,6 +25,14 @@ ircd::debugmode { "persist", false }, }; +decltype(ircd::restart) +ircd::restart +{ + { "name", "ircd.restart" }, + { "default", false }, + { "persist", false }, +}; + /// Sets up the IRCd and its main context, then returns without blocking. // /// Pass your io_context instance, it will share it with the rest of your program. diff --git a/modules/console.cc b/modules/console.cc index 4f9f463bf..965b2eb82 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -449,6 +449,14 @@ console_cmd__debug(opt &out, const string_view &line) // main // +bool +console_cmd__restart(opt &out, const string_view &line) +{ + ircd::restart.set("true"); + ircd::quit(); + return false; +} + bool console_cmd__die(opt &out, const string_view &line) {