Skip to content

Commit

Permalink
Merge pull request #8 from cloudflare/cbranch/signal-config
Browse files Browse the repository at this point in the history
Make the restart signal kind configurable
  • Loading branch information
cbranch authored Nov 21, 2024
2 parents 4892ea1 + 19b3eca commit 9d74d45
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const REBIND_SYSTEMD_PID: &str = "auto";

/// Settings for graceful restarts
pub struct RestartConfig {
/// Enables the restart coordination socket for graceful restarts as an alternative to the SIGUSR1 signal.
/// Enables the restart coordination socket for graceful restarts as an alternative to a Unix signal.
pub enabled: bool,
/// Socket path
pub coordination_socket_path: PathBuf,
Expand All @@ -97,6 +97,8 @@ pub struct RestartConfig {
pub lifecycle_handler: Box<dyn LifecycleHandler>,
/// Exits early when child process fail to start
pub exit_on_error: bool,
/// Sets the signal to listen to on restart. This defaults to SIGUSR1.
pub restart_signal: SignalKind,
}

impl RestartConfig {
Expand Down Expand Up @@ -139,6 +141,7 @@ impl Default for RestartConfig {
environment: vec![],
lifecycle_handler: Box::new(lifecycle::NullLifecycleHandler),
exit_on_error: true,
restart_signal: SignalKind::user_defined1(),
}
}
}
Expand Down Expand Up @@ -211,7 +214,7 @@ pub fn spawn_restart_task(
false => None,
};

let mut signal_stream = signal(SignalKind::user_defined1())?;
let mut signal_stream = signal(settings.restart_signal)?;
let (restart_fd, mut socket_stream) = new_restart_coordination_socket_stream(socket)?;
let mut child_spawner =
ChildSpawner::new(restart_fd, settings.environment, settings.lifecycle_handler);
Expand Down

0 comments on commit 9d74d45

Please sign in to comment.