Skip to main content

frm/commands/
fg_node.rs

1// Copyright (c) 2025-2026 Michael S. Klishin and Contributors
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
9#[cfg(unix)]
10use std::os::unix::process::CommandExt;
11#[cfg(windows)]
12use std::process;
13use std::process::Command;
14
15use crate::Result;
16use crate::common::cli_tools::RABBITMQ_SERVER;
17use crate::common::env_vars::RABBITMQ_CONFIG_FILES;
18use crate::errors::Error;
19use crate::paths::Paths;
20use crate::version::Version;
21
22#[cfg(unix)]
23pub fn run(paths: &Paths, version: &Version) -> Result<()> {
24    if !paths.version_installed(version) {
25        return Err(Error::VersionNotInstalled(version.clone()));
26    }
27
28    let server_path = paths.version_sbin_dir(version).join(RABBITMQ_SERVER);
29    if !server_path.exists() {
30        return Err(Error::FileNotFound(server_path.display().to_string()));
31    }
32
33    let err = Command::new(&server_path)
34        .env(RABBITMQ_CONFIG_FILES, paths.version_confd_dir(version))
35        .exec();
36
37    Err(Error::CommandFailed(format!(
38        "failed to execute {}: {}",
39        server_path.display(),
40        err
41    )))
42}
43
44#[cfg(windows)]
45pub fn run(paths: &Paths, version: &Version) -> Result<()> {
46    if !paths.version_installed(version) {
47        return Err(Error::VersionNotInstalled(version.clone()));
48    }
49
50    let server_path = paths.version_sbin_dir(version).join(RABBITMQ_SERVER);
51    if !server_path.exists() {
52        return Err(Error::FileNotFound(server_path.display().to_string()));
53    }
54
55    let status = Command::new(&server_path)
56        .env(RABBITMQ_CONFIG_FILES, paths.version_confd_dir(version))
57        .status()
58        .map_err(|e| {
59            Error::CommandFailed(format!(
60                "failed to execute {}: {}",
61                server_path.display(),
62                e
63            ))
64        })?;
65
66    process::exit(status.code().unwrap_or(1));
67}