use std::{cmp::Ordering, str::FromStr, time::Duration};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u8)]
pub enum DaemonLock {
Processes = 1,
PidFile = 2,
StateFile = 3,
RestartCounts = 4,
ManualStopFlags = 5,
RestartSuppressed = 6,
}
impl DaemonLock {
pub const fn priority(&self) -> u8 {
*self as u8
}
pub const fn name(&self) -> &'static str {
match self {
Self::Processes => "processes",
Self::PidFile => "pid_file",
Self::StateFile => "state_file",
Self::RestartCounts => "restart_counts",
Self::ManualStopFlags => "manual_stop_flags",
Self::RestartSuppressed => "restart_suppressed",
}
}
pub const fn can_acquire_after(&self, other: &Self) -> bool {
self.priority() > other.priority()
}
}
impl PartialOrd for DaemonLock {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for DaemonLock {
fn cmp(&self, other: &Self) -> Ordering {
self.priority().cmp(&other.priority())
}
}
pub const PID_FILE_NAME: &str = "pid.xml";
pub const PID_LOCK_SUFFIX: &str = ".lock";
pub const STATE_FILE_NAME: &str = "state.xml";
pub const DEFAULT_SHELL: &str = "sh";
pub const SHELL_COMMAND_FLAG: &str = "-c";
pub const PROCESS_READY_CHECKS: usize = 10;
pub const PROCESS_CHECK_INTERVAL: Duration = Duration::from_millis(100);
pub const SERVICE_START_TIMEOUT: Duration = Duration::from_secs(5);
pub const SERVICE_POLL_INTERVAL: Duration = Duration::from_millis(50);
pub const POST_RESTART_VERIFY_ATTEMPTS: usize = 2;
pub const POST_RESTART_VERIFY_DELAY: Duration = Duration::from_millis(200);
pub const MAX_STATUS_LOG_LINES: usize = 50;
pub const LOG_BUFFER_SIZE: usize = 8192;
pub const HOOK_LABEL_FORMAT: &str = "{}.{}";
pub const ENV_FILE_MALFORMED_MSG: &str =
"Ignoring malformed line in env file for '{}': {}";
pub const ENV_FILE_READ_ERROR_MSG: &str = "Failed to read env file for '{}': {}";
pub const HOOK_TIMEOUT_PARSE_ERROR_MSG: &str =
"Invalid timeout '{}' for hook {} on '{}': {}";
pub const INSUFFICIENT_SIGNAL_PERMISSIONS_MSG: &str =
"Insufficient permissions to signal process group {} for '{}'";
pub const PROCESS_TREE_TERM_FAILURE_MSG: &str =
"Failed to terminate process tree rooted at PID {} for '{}'";
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DeploymentStrategy {
Rolling,
Immediate,
}
impl DeploymentStrategy {
pub fn as_str(&self) -> &'static str {
match self {
Self::Rolling => "rolling",
Self::Immediate => "immediate",
}
}
}
impl FromStr for DeploymentStrategy {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"rolling" => Ok(Self::Rolling),
"immediate" => Ok(Self::Immediate),
_ => Err(format!("Unknown deployment strategy: {}", s)),
}
}
}
impl Default for DeploymentStrategy {
fn default() -> Self {
Self::Immediate
}
}
pub const DEFAULT_DEPLOYMENT_STRATEGY: &str = "immediate";
pub const ROLLING_DEPLOYMENT: &str = "rolling";
pub const IMMEDIATE_DEPLOYMENT: &str = "immediate";
pub const SKIP_CRON_SERVICE_MSG: &str = "Skipping cron-managed service '{}' during bulk start; scheduled execution will launch it";
pub const SKIP_CRON_RESTART_MSG: &str = "Skipping cron-managed service '{}' during restart; scheduled execution will launch it";