1use crate::core::error::Result;
4use crate::daemon::process;
5
6pub fn start() -> Result<()> {
8 if process::is_running()? {
9 if let Some(pid) = process::get_pid()? {
10 println!("Daemon already running (PID: {})", pid);
11 return Ok(());
12 }
13 }
14
15 match process::start_daemon() {
16 Ok(pid) => {
17 println!("Daemon started (PID: {})", pid);
18 println!("File watcher active for incremental indexing.");
19 Ok(())
20 }
21 Err(e) => {
22 eprintln!("Failed to start daemon: {}", e);
23 Err(e)
24 }
25 }
26}
27
28pub fn stop() -> Result<()> {
30 if !process::is_running()? {
31 println!("Daemon is not running.");
32 return Ok(());
33 }
34
35 match process::stop_daemon() {
36 Ok(true) => {
37 println!("Daemon stopped.");
38 Ok(())
39 }
40 Ok(false) => {
41 println!("Daemon is not running.");
42 Ok(())
43 }
44 Err(e) => {
45 eprintln!("Failed to stop daemon: {}", e);
46 Err(e)
47 }
48 }
49}
50
51pub fn status() -> Result<()> {
53 if process::is_running()? {
54 if let Some(pid) = process::get_pid()? {
55 println!("Daemon is running (PID: {})", pid);
56 } else {
57 println!("Daemon is running.");
58 }
59 } else {
60 println!("Daemon is not running.");
61 }
62 Ok(())
63}