feat(installer): implement Phase 2 — uo-link install and service #5
@@ -31,7 +31,9 @@ use std::path::{Path, PathBuf};
|
|||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
|
|
||||||
use crate::util::{command_line, run, run_ok};
|
// `command_line` is used only by the Windows registration path, so it is qualified at its call
|
||||||
|
// site rather than imported here — an unconditional import is an unused-import error on Linux.
|
||||||
|
use crate::util::{run, run_ok};
|
||||||
|
|
||||||
/// The unit file name, and the systemd service name with its suffix.
|
/// The unit file name, and the systemd service name with its suffix.
|
||||||
pub const SYSTEMD_UNIT: &str = "runicgateway-link.service";
|
pub const SYSTEMD_UNIT: &str = "runicgateway-link.service";
|
||||||
@@ -149,7 +151,7 @@ fn prepare_platform() -> Prepared {
|
|||||||
/// Creates the dedicated system user if it is not already there. Returns whether it created it.
|
/// Creates the dedicated system user if it is not already there. Returns whether it created it.
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn ensure_user(user: &str) -> Result<bool> {
|
fn ensure_user(user: &str) -> Result<bool> {
|
||||||
if run("id", &["-u", user]).map(|o| o.status.success()) == Ok(true) {
|
if run("id", &["-u", user]).is_ok_and(|o| o.status.success()) {
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
// `useradd` is the near-universal spelling; `adduser` is the fallback for Debian's wrapper and
|
// `useradd` is the near-universal spelling; `adduser` is the fallback for Debian's wrapper and
|
||||||
@@ -373,7 +375,7 @@ fn register_windows(binary: &Path, config: &Path, restart: bool) -> Result<Outco
|
|||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
"`{}` failed with exit code {}. Check the Windows event log; a service that exits \
|
"`{}` failed with exit code {}. Check the Windows event log; a service that exits \
|
||||||
immediately usually cannot read its config: {}",
|
immediately usually cannot read its config: {}",
|
||||||
command_line("sc.exe", &["start", WINDOWS_SERVICE]),
|
crate::util::command_line("sc.exe", &["start", WINDOWS_SERVICE]),
|
||||||
start.status.code().unwrap_or(-1),
|
start.status.code().unwrap_or(-1),
|
||||||
config.display()
|
config.display()
|
||||||
);
|
);
|
||||||
@@ -798,6 +800,16 @@ mod tests {
|
|||||||
// The write grant belongs to the database directory, which is not always the config's.
|
// The write grant belongs to the database directory, which is not always the config's.
|
||||||
assert!(steps.contains("/var/lib/runicgateway'"), "{steps}");
|
assert!(steps.contains("/var/lib/runicgateway'"), "{steps}");
|
||||||
}
|
}
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
{
|
||||||
|
assert!(steps.contains("systemctl enable --now"), "{steps}");
|
||||||
|
assert!(
|
||||||
|
steps.contains("ExecStart=/usr/bin/runicgateway-link"),
|
||||||
|
"{steps}"
|
||||||
|
);
|
||||||
|
// Non-systemd hosts get the requirements, not just a unit they cannot use.
|
||||||
|
assert!(steps.contains("without systemd"), "{steps}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -826,16 +838,6 @@ mod tests {
|
|||||||
assert_eq!(protected, unprotected);
|
assert_eq!(protected, unprotected);
|
||||||
assert!(protected.contains("chown runicgateway"), "{protected}");
|
assert!(protected.contains("chown runicgateway"), "{protected}");
|
||||||
}
|
}
|
||||||
#[cfg(not(windows))]
|
|
||||||
{
|
|
||||||
assert!(steps.contains("systemctl enable --now"), "{steps}");
|
|
||||||
assert!(
|
|
||||||
steps.contains("ExecStart=/usr/bin/runicgateway-link"),
|
|
||||||
"{steps}"
|
|
||||||
);
|
|
||||||
// Non-systemd hosts get the requirements, not just a unit they cannot use.
|
|
||||||
assert!(steps.contains("without systemd"), "{steps}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user