MCPcopy Create free account
hub / github.com/ermak-dev/cloudpub / handle_service_command

Function handle_service_command

client/src/base.rs:44–118  ·  view source on GitHub ↗
(action: &ServiceAction, config: &ClientConfig)

Source from the content-addressed store, hash-verified

42}
43
44fn handle_service_command(action: &ServiceAction, config: &ClientConfig) -> Result<()> {
45 // Determine config path to use for service
46 let config_path = match action {
47 ServiceAction::Install { conf: Some(path) } => {
48 // Use provided config path
49 PathBuf::from(path)
50 }
51 _ => {
52 // Use default config path
53 config.get_config_path().to_owned()
54 }
55 };
56
57 // Check if the provided config path exists
58 let actual_config = if config.token.is_some() {
59 debug!("Service config has token: {:?}", config_path);
60 config_path.clone()
61 } else {
62 #[cfg(any(target_os = "linux", target_os = "macos"))]
63 {
64 use crate::service::ServiceConfig;
65 // On Unix, check if running under sudo and use original user's config if available
66 if let Some(sudo_config) = ServiceConfig::get_sudo_user_config_path() {
67 sudo_config.clone()
68 } else {
69 config_path.clone()
70 }
71 }
72 #[cfg(not(any(target_os = "linux", target_os = "macos")))]
73 config_path.clone()
74 };
75
76 if actual_config.as_os_str().is_empty() || !actual_config.exists() {
77 bail!(crate::t!("error-config-not-found", "path" => format!("{:?}", config_path)));
78 }
79
80 let cfg = ClientConfig::from_file(&actual_config, true)
81 .context(crate::t!("error-config-load-failed", "path" => format!("{:?}", actual_config)))?;
82
83 if cfg.token.is_none() {
84 bail!(crate::t!("error-config-token-missing"));
85 }
86 // Create the appropriate service manager for the current platform
87 let service_manager = create_service_manager(actual_config);
88
89 match action {
90 ServiceAction::Install { .. } => {
91 service_manager.install()?;
92 println!("{}", crate::t!("service-installed"));
93 }
94 ServiceAction::Uninstall => {
95 service_manager.uninstall()?;
96 println!("{}", crate::t!("service-uninstalled"));
97 }
98 ServiceAction::Start => {
99 service_manager.start()?;
100 println!("{}", crate::t!("service-started"));
101 }

Callers 1

main_loopFunction · 0.85

Calls 9

create_service_managerFunction · 0.85
get_config_pathMethod · 0.80
cloneMethod · 0.80
is_emptyMethod · 0.80
installMethod · 0.45
uninstallMethod · 0.45
startMethod · 0.45
stopMethod · 0.45
statusMethod · 0.45

Tested by

no test coverage detected