Skip to content

Commit

Permalink
construct: Handle SIGUSR2 to refresh slave.
Browse files Browse the repository at this point in the history
  • Loading branch information
jevolk committed Mar 20, 2023
1 parent fc495f0 commit 8248227
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions construct/signals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace construct
namespace ph = std::placeholders;

static void handle_cont();
static void handle_usr2();
static void handle_usr1();
static void handle_quit();
static void handle_interrupt();
Expand All @@ -42,6 +43,7 @@ construct::signals::signals(boost::asio::io_context &ios)
signal_set->add(SIGQUIT);
signal_set->add(SIGTERM);
signal_set->add(SIGUSR1);
signal_set->add(SIGUSR2);
signal_set->add(SIGCONT);
set_handle();
}
Expand Down Expand Up @@ -133,6 +135,7 @@ construct::handle_signal(const int &signum)
case SIGQUIT: return handle_quit();
case SIGTERM: return handle_quit();
case SIGUSR1: return handle_usr1();
case SIGUSR2: return handle_usr2();
case SIGCONT: return handle_cont();
default: break;
}
Expand Down Expand Up @@ -252,6 +255,50 @@ catch(const std::exception &e)
};
}

void
construct::handle_usr2()
try
{
if(ircd::run::level != ircd::run::level::RUN)
{
ircd::log::warning
{
"Not synchronizing database from SIGUSR2 in runlevel %s",
reflect(ircd::run::level)
};

return;
}

if(!ircd::slave)
return;

if(!homeserver::primary || !homeserver::primary->module[0])
return;

ircd::context{[]
{
static ircd::mods::import<bool (ircd::m::homeserver *)> refresh
{
homeserver::primary->module[0], "ircd::m::homeserver::refresh"
};

assert(homeserver::primary->hs);
const bool refreshed
{
refresh(homeserver::primary->hs.get())
};
}};
}
catch(const std::exception &e)
{
ircd::log::error
{
"SIGUSR2 handler :%s",
e.what()
};
}

void
construct::handle_cont()
try
Expand Down

0 comments on commit 8248227

Please sign in to comment.