(options: SystemdUnitOptions)
| 442 | |
| 443 | /** Render a systemd --user unit. Pure (snapshot-tested). */ |
| 444 | export const generateSystemdUnit = (options: SystemdUnitOptions): string => { |
| 445 | const execStart = options.execStart.map(systemdQuote).join(" "); |
| 446 | const env = Object.entries(options.environment) |
| 447 | .map(([key, value]) => `Environment=${systemdQuote(`${key}=${value}`)}`) |
| 448 | .join("\n"); |
| 449 | return `[Unit] |
| 450 | Description=Executor supervised daemon |
| 451 | After=default.target |
| 452 | |
| 453 | [Service] |
| 454 | Type=simple |
| 455 | ExecStart=${execStart} |
| 456 | ${env} |
| 457 | WorkingDirectory=${systemdQuote(options.workingDirectory)} |
| 458 | StandardOutput=${systemdQuote(`append:${options.stdoutPath}`)} |
| 459 | StandardError=${systemdQuote(`append:${options.stderrPath}`)} |
| 460 | Restart=on-failure |
| 461 | RestartSec=5s |
| 462 | |
| 463 | [Install] |
| 464 | WantedBy=default.target |
| 465 | `; |
| 466 | }; |
| 467 | |
| 468 | const makeSystemdBackend = (): ServiceBackend => { |
| 469 | const unitName = `${SERVICE_LABEL}.service`; |
no test coverage detected