MCPcopy Create free account
hub / github.com/Autoparallel/learner / install_system_daemon

Function install_system_daemon

crates/learnerd/src/daemon/linux.rs:40–80  ·  view source on GitHub ↗

Installs the daemon as a systemd service. Creates a service unit file and installs the binary: - Sets up service dependencies and metadata - Configures process management and logging - Installs binary to /usr/local/bin if running from cargo - Reloads systemd configuration # Errors Returns `LearnerdErrors` if: - Binary installation fails - Service file creation fails - Systemd reload fails

(_daemon: &Daemon)

Source from the content-addressed store, hash-verified

38/// - Service file creation fails
39/// - Systemd reload fails
40pub fn install_system_daemon(_daemon: &Daemon) -> Result<()> {
41 let service = String::from(
42 r#"[Unit]
43Description=Academic Paper Management Daemon
44After=network.target
45Documentation=https://github.com/autoparallel/learner
46
47[Service]
48Type=simple
49User=root
50Group=root
51ExecStart=/usr/local/bin/learnerd daemon start
52Restart=on-failure
53RestartSec=60
54RemainAfterExit=yes
55
56# Logging configuration
57StandardOutput=journal
58StandardError=journal
59
60[Install]
61WantedBy=multi-user.target
62"#,
63 );
64
65 // Install the binary to /usr/local/bin if it's not there
66 if let Ok(current_exe) = std::env::current_exe() {
67 if current_exe.to_str().unwrap_or("").contains(".cargo") {
68 std::process::Command::new("cp")
69 .args([current_exe.to_str().unwrap(), "/usr/local/bin/learnerd"])
70 .output()?;
71 std::process::Command::new("chmod").args(["755", "/usr/local/bin/learnerd"]).output()?;
72 }
73 }
74
75 fs::write("/etc/systemd/system/learnerd.service", service)?;
76
77 // Reload systemd
78 std::process::Command::new("systemctl").args(["daemon-reload"]).output()?;
79 Ok(())
80}
81
82/// Removes the daemon service configuration.
83///

Callers 1

installMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected