pub struct DaemonState {
pub pid_file: PathBuf,
pub socket_path: PathBuf,
pub log_file: PathBuf,
}Expand description
Manages daemon state including paths for PID file, socket, and logs.
The daemon uses files in ~/.lore/ to coordinate between the running
daemon process and CLI commands that interact with it.
Fields§
§pid_file: PathBufPath to the PID file (~/.lore/daemon.pid).
socket_path: PathBufPath to the Unix socket (~/.lore/daemon.sock).
log_file: PathBufPath to the log file (~/.lore/daemon.log).
Implementations§
Source§impl DaemonState
impl DaemonState
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Creates a new DaemonState with default paths in ~/.lore/.
Creates the ~/.lore/ directory if it does not exist.
§Errors
Returns an error if the home directory cannot be determined or
if the .lore directory cannot be created.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Checks if the daemon is currently running.
Returns true if a PID file exists and the process with that PID is still alive. Returns false if no PID file exists, the PID file cannot be read, or the process is no longer running.
Sourcepub fn get_pid(&self) -> Option<u32>
pub fn get_pid(&self) -> Option<u32>
Gets the PID of the running daemon, if available.
Returns None if the PID file does not exist or cannot be parsed.
Sourcepub fn write_pid(&self, pid: u32) -> Result<()>
pub fn write_pid(&self, pid: u32) -> Result<()>
Writes the current process ID to the PID file.
§Errors
Returns an error if the PID file cannot be created or written to.
Sourcepub fn remove_pid(&self) -> Result<()>
pub fn remove_pid(&self) -> Result<()>
Removes the PID file.
Does not return an error if the file does not exist.
§Errors
Returns an error if the file exists but cannot be removed.
Sourcepub fn remove_socket(&self) -> Result<()>
pub fn remove_socket(&self) -> Result<()>
Removes the Unix socket file.
Does not return an error if the file does not exist.
§Errors
Returns an error if the file exists but cannot be removed.