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)
| 38 | /// - Service file creation fails |
| 39 | /// - Systemd reload fails |
| 40 | pub fn install_system_daemon(_daemon: &Daemon) -> Result<()> { |
| 41 | let service = String::from( |
| 42 | r#"[Unit] |
| 43 | Description=Academic Paper Management Daemon |
| 44 | After=network.target |
| 45 | Documentation=https://github.com/autoparallel/learner |
| 46 | |
| 47 | [Service] |
| 48 | Type=simple |
| 49 | User=root |
| 50 | Group=root |
| 51 | ExecStart=/usr/local/bin/learnerd daemon start |
| 52 | Restart=on-failure |
| 53 | RestartSec=60 |
| 54 | RemainAfterExit=yes |
| 55 | |
| 56 | # Logging configuration |
| 57 | StandardOutput=journal |
| 58 | StandardError=journal |
| 59 | |
| 60 | [Install] |
| 61 | WantedBy=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 | /// |