Repair daemon service restarts
This commit is contained in:
parent
4eddcf7518
commit
7524b634d3
|
@ -38,12 +38,23 @@ pub fn ready<'a, N: Unparse<&'a Language<AnyValue>, AnyValue>>(service_name: &N)
|
|||
lifecycle(service_name, State::Ready)
|
||||
}
|
||||
|
||||
pub fn on_service_restart<'a,
|
||||
N: Unparse<&'a Language<AnyValue>, AnyValue>,
|
||||
F: 'static + Send + FnMut(&mut Activation) -> ActorResult>(
|
||||
t: &mut Activation,
|
||||
ds: &Arc<Cap>,
|
||||
service_name: &N,
|
||||
mut f: F,
|
||||
) {
|
||||
on_message!(t, ds, language(), <restart-service #(&service_name.unparse(language()))>, f);
|
||||
}
|
||||
|
||||
pub fn terminate_on_service_restart<'a, N: Unparse<&'a Language<AnyValue>, AnyValue>>(
|
||||
t: &mut Activation,
|
||||
ds: &Arc<Cap>,
|
||||
service_name: &N,
|
||||
) {
|
||||
on_message!(t, ds, language(), <restart-service #(&service_name.unparse(language()))>, |t: &mut Activation| {
|
||||
on_service_restart(t, ds, service_name, |t| {
|
||||
tracing::info!("Terminating to restart");
|
||||
t.state.shutdown();
|
||||
Ok(())
|
||||
|
|
|
@ -22,18 +22,39 @@ use syndicate_macros::during;
|
|||
|
||||
pub fn on_demand(t: &mut Activation, config_ds: Arc<Cap>, root_ds: Arc<Cap>) {
|
||||
t.spawn(syndicate::name!("daemon"), move |t| {
|
||||
Ok(during!(t, config_ds, language(), <run-service $spec: DaemonService>, |t| {
|
||||
Supervisor::start(
|
||||
t,
|
||||
syndicate::name!(parent: None, "daemon", id = ?spec.id),
|
||||
SupervisorConfiguration::on_error_only(),
|
||||
enclose!((config_ds, spec) lifecycle::updater(config_ds, spec)),
|
||||
enclose!((config_ds, root_ds) move |t|
|
||||
enclose!((config_ds, root_ds, spec) run(t, config_ds, root_ds, spec))))
|
||||
}))
|
||||
Ok(during!(t, config_ds, language(), <run-service $spec: DaemonService>,
|
||||
enclose!((config_ds, root_ds) move |t: &mut Activation| {
|
||||
supervise_daemon(t, config_ds, root_ds, spec)
|
||||
})))
|
||||
});
|
||||
}
|
||||
|
||||
fn supervise_daemon(
|
||||
t: &mut Activation,
|
||||
config_ds: Arc<Cap>,
|
||||
root_ds: Arc<Cap>,
|
||||
spec: DaemonService,
|
||||
) -> ActorResult {
|
||||
t.facet(|t| {
|
||||
lifecycle::on_service_restart(t, &config_ds, &spec, enclose!(
|
||||
(config_ds, root_ds, spec) move |t| {
|
||||
tracing::info!(id = ?spec.id, "Terminating to restart");
|
||||
t.stop_facet_and_continue(t.facet.facet_id, Some(
|
||||
enclose!((config_ds, root_ds, spec) move |t: &mut Activation| {
|
||||
supervise_daemon(t, config_ds, root_ds, spec)
|
||||
})))
|
||||
}));
|
||||
Supervisor::start(
|
||||
t,
|
||||
syndicate::name!(parent: None, "daemon", id = ?spec.id),
|
||||
SupervisorConfiguration::on_error_only(),
|
||||
enclose!((config_ds, spec) lifecycle::updater(config_ds, spec)),
|
||||
enclose!((config_ds, root_ds) move |t|
|
||||
enclose!((config_ds, root_ds, spec) run(t, config_ds, root_ds, spec))))
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
impl Process {
|
||||
fn elaborate(self) -> FullProcess {
|
||||
match self {
|
||||
|
@ -330,8 +351,6 @@ fn run(
|
|||
root_ds: Arc<Cap>,
|
||||
service: DaemonService,
|
||||
) -> ActorResult {
|
||||
lifecycle::terminate_on_service_restart(t, &config_ds, &service);
|
||||
|
||||
let spec = language().unparse(&service);
|
||||
|
||||
let total_configs = t.named_field("total_configs", 0isize);
|
||||
|
|
Loading…
Reference in New Issue