pub fn is_running() -> boolExpand description
Finds and stops the running daemon process.
This function provides a user-friendly interface for stopping the daemon process. It handles cases where no daemon is running gracefully and provides appropriate feedback to the user.
§Operation Flow
- Process Lookup: Searches for running daemon using PID file
- Termination: Attempts to terminate the found process
- Cleanup: Removes PID file and other resources
- Status Reporting: Provides feedback about the operation result
§Error Handling Strategy
This function uses a forgiving error handling approach:
- Process Not Found: Reports “not running” instead of error
- Stale PID File: Cleans up orphaned files without complaint
- Permission Issues: Reports specific error details
- Cleanup Failures: Continues operation, reports warnings
§User Experience
The function prioritizes clear user communication:
- Success messages confirm the daemon was stopped
- “Not running” messages avoid unnecessary error reports
- Specific error messages help with troubleshooting
- Consistent behavior across multiple invocations
§Returns
Returns Ok(()) in most cases, including when no daemon is running.
Only returns errors for serious system-level failures that require
user attention.
§Error Scenarios
- Permission Denied: Insufficient privileges to terminate the process
- System Errors: Platform-specific process management failures
- Resource Issues: System resource exhaustion during termination
§Usage Examples
use kasl::libs::daemon;
// Stop background monitoring
daemon::stop()?;
println!("Monitoring stopped");§Idempotent Operation
This function is safe to call multiple times and will not produce errors if called when no daemon is running. This makes it suitable for use in cleanup scripts and automated scenarios. Checks if the daemon is currently running.
This function determines whether a daemon process is currently active by checking for the existence and validity of the PID file and verifying that the corresponding process is still running.
§Returns
Returns true if the daemon is running, false otherwise.
This function does not return errors - it treats any failure to
verify the daemon as “not running”.