systemd-ts 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +59 -0
  2. package/dist/index.d.mts +849 -429
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -2,3 +2,62 @@
2
2
 
3
3
  `systemd-ts` is a library for declaring, rendering, and managing `systemd`
4
4
  services and timers from TypeScript.
5
+
6
+ ## Usage
7
+
8
+ The example below installs a user-scoped service and timer for a small
9
+ nightly backup job. The service does the work, the timer schedules it, and
10
+ `Systemd` writes both unit files before enabling and starting the timer.
11
+
12
+ ```ts
13
+ import { homedir } from "node:os";
14
+ import { join } from "node:path";
15
+
16
+ import { Systemd, SystemdService, SystemdTimer } from "systemd-ts";
17
+
18
+ const userUnitDir = join(homedir(), ".config/systemd/user");
19
+
20
+ const service = new SystemdService({
21
+ name: "backup-db",
22
+ unit: {
23
+ Description: "Write a nightly database backup",
24
+ },
25
+ service: {
26
+ Type: "oneshot",
27
+ ExecStart: "/usr/bin/bash -lc '/srv/app/bin/backup-db >> /srv/app/log/backup-db.log 2>&1'",
28
+ },
29
+ });
30
+
31
+ const timer = new SystemdTimer({
32
+ name: "backup-db",
33
+ unit: {
34
+ Description: "Run the database backup every night",
35
+ },
36
+ timer: {
37
+ OnCalendar: "03:15",
38
+ Persistent: true,
39
+ Unit: service.filename,
40
+ },
41
+ install: {
42
+ WantedBy: "timers.target",
43
+ },
44
+ });
45
+
46
+ const systemd = new Systemd({
47
+ scope: "user",
48
+ unitDir: userUnitDir,
49
+ linkUnits: true,
50
+ });
51
+
52
+ const installed = await systemd.install(service, timer);
53
+
54
+ console.log(installed.pathFor(service));
55
+ console.log(installed.pathFor(timer));
56
+
57
+ await systemd.enable(timer);
58
+ await systemd.start(timer);
59
+ ```
60
+
61
+ That will write `backup-db.service` and `backup-db.timer` into the user's unit
62
+ directory, enable the timer under `timers.target`, and ask `systemd --user` to
63
+ start waiting for the first scheduled run.