use std::net::SocketAddr;
use std::path::PathBuf;
use std::time::Duration;
use crate::procserv::restart::{RestartMode, RestartPolicy};
#[derive(Debug, Clone, Default)]
pub struct ListenConfig {
pub tcp_port: Option<u16>,
pub tcp_bind: Option<SocketAddr>,
pub log_port: Option<u16>,
pub log_bind: Option<SocketAddr>,
pub unix_path: Option<PathBuf>,
}
#[derive(Debug, Clone, Copy, Default)]
pub struct KeyBindings {
pub kill: Option<u8>,
pub toggle_restart: Option<u8>,
pub restart: Option<u8>,
pub quit: Option<u8>,
pub logout: Option<u8>,
}
#[derive(Debug, Clone)]
pub struct ChildConfig {
pub name: String,
pub program: PathBuf,
pub args: Vec<String>,
pub cwd: Option<PathBuf>,
pub kill_signal: i32,
pub ignore_chars: Vec<u8>,
}
#[derive(Debug, Clone, Default)]
pub struct LoggingConfig {
pub log_path: Option<PathBuf>,
pub pid_path: Option<PathBuf>,
pub info_path: Option<PathBuf>,
pub stamp_log: bool,
pub time_format: String,
pub stamp_format: String,
}
#[derive(Debug, Clone)]
pub struct ProcServConfig {
pub foreground: bool,
pub listen: ListenConfig,
pub keys: KeyBindings,
pub child: ChildConfig,
pub logging: LoggingConfig,
pub restart: RestartPolicy,
pub restart_mode: RestartMode,
pub holdoff: Duration,
pub wait_for_manual_start: bool,
}
impl ProcServConfig {
pub fn validate(&self) -> Result<(), String> {
if self.listen.tcp_port.is_none() && self.listen.unix_path.is_none() {
return Err("at least one of tcp_port / unix_path must be set".into());
}
if self.child.program.as_os_str().is_empty() {
return Err("child.program is required".into());
}
Ok(())
}
}