Skip to main content

urma_node/daemon/
command.rs

1#[cfg(windows)]
2use super::scm;
3#[cfg(not(windows))]
4use super::{ServeOptions, serve};
5#[cfg(not(windows))]
6use crate::platform::ServiceSettings;
7use crate::{Error, install, platform::Paths, service::ShutdownHandle};
8use std::{io::Write, path::PathBuf};
9
10#[derive(Clone, Debug, clap::Subcommand)]
11pub enum ServiceCommand {
12    /// Serve with service.json: what every init adapter and the Windows
13    /// service manager start.
14    Run {
15        #[arg(long, hide = true, default_value_os_t = Paths::system().settings)]
16        settings: PathBuf,
17    },
18    #[command(flatten)]
19    Manage(install::Action),
20}
21
22/// `urma-node service run`. On Windows a start by the service manager is
23/// detected and served under it; otherwise this is a foreground run whose
24/// stop signal `signals` installs.
25pub fn run(
26    settings: &std::path::Path,
27    signals: impl FnOnce(ShutdownHandle) -> Result<(), Error>,
28    log: &mut impl Write,
29) -> Result<(), Error> {
30    #[cfg(windows)]
31    {
32        scm::run(settings, signals, log)
33    }
34    #[cfg(not(windows))]
35    {
36        let options = ServeOptions::from_settings(ServiceSettings::read(settings)?);
37        serve(options, signals, log)
38    }
39}