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