@zukhruf/launchd 0.0.0-stage → 0.8.19
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.
- package/LICENSE +21 -0
- package/README.md +672 -2
- package/dist/errors.d.ts +27 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +46 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/job/absolute-path.d.ts +5 -0
- package/dist/job/absolute-path.d.ts.map +1 -0
- package/dist/job/absolute-path.js +6 -0
- package/dist/job/absolute-path.js.map +1 -0
- package/dist/job/agent-job.d.ts +8 -0
- package/dist/job/agent-job.d.ts.map +1 -0
- package/dist/job/agent-job.js +2 -0
- package/dist/job/agent-job.js.map +1 -0
- package/dist/job/calendar-interval.d.ts +10 -0
- package/dist/job/calendar-interval.d.ts.map +1 -0
- package/dist/job/calendar-interval.js +2 -0
- package/dist/job/calendar-interval.js.map +1 -0
- package/dist/job/daemon-job.d.ts +10 -0
- package/dist/job/daemon-job.d.ts.map +1 -0
- package/dist/job/daemon-job.js +2 -0
- package/dist/job/daemon-job.js.map +1 -0
- package/dist/job/job-file.d.ts +21 -0
- package/dist/job/job-file.d.ts.map +1 -0
- package/dist/job/job-file.js +103 -0
- package/dist/job/job-file.js.map +1 -0
- package/dist/job/job.d.ts +67 -0
- package/dist/job/job.d.ts.map +1 -0
- package/dist/job/job.js +2 -0
- package/dist/job/job.js.map +1 -0
- package/dist/job/keep-alive-conditions.d.ts +15 -0
- package/dist/job/keep-alive-conditions.d.ts.map +1 -0
- package/dist/job/keep-alive-conditions.js +2 -0
- package/dist/job/keep-alive-conditions.js.map +1 -0
- package/dist/job/launch-events.d.ts +17 -0
- package/dist/job/launch-events.d.ts.map +1 -0
- package/dist/job/launch-events.js +2 -0
- package/dist/job/launch-events.js.map +1 -0
- package/dist/job/mach-service.d.ts +5 -0
- package/dist/job/mach-service.d.ts.map +1 -0
- package/dist/job/mach-service.js +2 -0
- package/dist/job/mach-service.js.map +1 -0
- package/dist/job/property-list-value.d.ts +5 -0
- package/dist/job/property-list-value.d.ts.map +1 -0
- package/dist/job/property-list-value.js +2 -0
- package/dist/job/property-list-value.js.map +1 -0
- package/dist/job/resource-limits.d.ts +13 -0
- package/dist/job/resource-limits.d.ts.map +1 -0
- package/dist/job/resource-limits.js +2 -0
- package/dist/job/resource-limits.js.map +1 -0
- package/dist/job/socket.d.ts +37 -0
- package/dist/job/socket.d.ts.map +1 -0
- package/dist/job/socket.js +2 -0
- package/dist/job/socket.js.map +1 -0
- package/dist/launchctl/cancel-options.d.ts +5 -0
- package/dist/launchctl/cancel-options.d.ts.map +1 -0
- package/dist/launchctl/cancel-options.js +2 -0
- package/dist/launchctl/cancel-options.js.map +1 -0
- package/dist/launchctl/domain.d.ts +3 -0
- package/dist/launchctl/domain.d.ts.map +1 -0
- package/dist/launchctl/domain.js +2 -0
- package/dist/launchctl/domain.js.map +1 -0
- package/dist/launchctl/launchctl.d.ts +17 -0
- package/dist/launchctl/launchctl.d.ts.map +1 -0
- package/dist/launchctl/launchctl.js +98 -0
- package/dist/launchctl/launchctl.js.map +1 -0
- package/dist/launchd/launchd.d.ts +30 -0
- package/dist/launchd/launchd.d.ts.map +1 -0
- package/dist/launchd/launchd.js +65 -0
- package/dist/launchd/launchd.js.map +1 -0
- package/dist/service/service-state.d.ts +13 -0
- package/dist/service/service-state.d.ts.map +1 -0
- package/dist/service/service-state.js +2 -0
- package/dist/service/service-state.js.map +1 -0
- package/dist/service/service.d.ts +35 -0
- package/dist/service/service.d.ts.map +1 -0
- package/dist/service/service.js +58 -0
- package/dist/service/service.js.map +1 -0
- package/package.json +50 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cancel-options.d.ts","sourceRoot":"","sources":["../../src/launchctl/cancel-options.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,oEAAoE;IACpE,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cancel-options.js","sourceRoot":"","sources":["../../src/launchctl/cancel-options.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain.d.ts","sourceRoot":"","sources":["../../src/launchctl/domain.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,EAAE,GAAG,QAAQ,MAAM,EAAE,GAAG,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain.js","sourceRoot":"","sources":["../../src/launchctl/domain.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ServiceState } from '../service/service-state.ts';
|
|
2
|
+
import type { Domain } from './domain.ts';
|
|
3
|
+
/** `/bin/launchctl`, and what its answers mean for each subcommand that the package runs. */
|
|
4
|
+
export declare class Launchctl {
|
|
5
|
+
#private;
|
|
6
|
+
/** 113 is a service that the domain does not have. */
|
|
7
|
+
print(target: string, signal?: AbortSignal): Promise<ServiceState>;
|
|
8
|
+
/** true when launchd has forgotten the service; false while the bootout goes on. */
|
|
9
|
+
bootout(target: string, signal?: AbortSignal): Promise<boolean>;
|
|
10
|
+
bootstrap(domain: Domain, file: string, signal?: AbortSignal): Promise<void>;
|
|
11
|
+
enable(target: string, signal?: AbortSignal): Promise<void>;
|
|
12
|
+
disable(target: string, signal?: AbortSignal): Promise<void>;
|
|
13
|
+
/** The PID that `-p` prints. */
|
|
14
|
+
kickstart(target: string, kill: boolean, signal?: AbortSignal): Promise<number>;
|
|
15
|
+
kill(target: string, processSignal: NodeJS.Signals | number, signal?: AbortSignal): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=launchctl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launchctl.d.ts","sourceRoot":"","sources":["../../src/launchctl/launchctl.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAmB1C,6FAA6F;AAC7F,qBAAa,SAAS;;IACpB,sDAAsD;IAChD,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAaxE,oFAAoF;IAC9E,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAQ/D,SAAS,CACb,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,IAAI,CAAC;IAKV,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAK3D,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAKlE,gCAAgC;IAC1B,SAAS,CACb,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,MAAM,CAAC;IAOZ,IAAI,CACR,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,CAAC,OAAO,GAAG,MAAM,EACtC,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,IAAI,CAAC;CAkDjB"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { untilAborted } from '@zukhruf/async';
|
|
3
|
+
import { isErrno } from '@zukhruf/fs';
|
|
4
|
+
import { LaunchctlError, LaunchdUnavailableError, PermissionDeniedError, ServiceNotFoundError, } from "../errors.js";
|
|
5
|
+
// launchctl error <code> on macOS 27.2.
|
|
6
|
+
const NOT_PERMITTED = 1;
|
|
7
|
+
const NO_SUCH_PROCESS = 3;
|
|
8
|
+
const IN_PROGRESS = 36;
|
|
9
|
+
const SERVICE_NOT_FOUND = 113;
|
|
10
|
+
// Two top-level lines of `print`, which "is NOT API" (launchctl(1), lines
|
|
11
|
+
// 222-224): the package reads no other part of it (ADR 0006).
|
|
12
|
+
const PID = /^\tpid = (\d+)$/m;
|
|
13
|
+
const LAST_EXIT_CODE = /^\tlast exit code = (\d+)/m;
|
|
14
|
+
/** `/bin/launchctl`, and what its answers mean for each subcommand that the package runs. */
|
|
15
|
+
export class Launchctl {
|
|
16
|
+
/** 113 is a service that the domain does not have. */
|
|
17
|
+
async print(target, signal) {
|
|
18
|
+
const args = ['print', target];
|
|
19
|
+
const answer = await this.#run(args, signal);
|
|
20
|
+
if (answer.exitCode === SERVICE_NOT_FOUND)
|
|
21
|
+
return { state: 'not loaded' };
|
|
22
|
+
this.#succeeded(args, answer);
|
|
23
|
+
const pid = PID.exec(answer.stdout)?.[1];
|
|
24
|
+
const code = LAST_EXIT_CODE.exec(answer.stdout)?.[1];
|
|
25
|
+
const lastExitStatus = code === undefined ? undefined : Number(code);
|
|
26
|
+
return pid === undefined
|
|
27
|
+
? { state: 'not running', lastExitStatus }
|
|
28
|
+
: { state: 'running', pid: Number(pid), lastExitStatus };
|
|
29
|
+
}
|
|
30
|
+
/** true when launchd has forgotten the service; false while the bootout goes on. */
|
|
31
|
+
async bootout(target, signal) {
|
|
32
|
+
const args = ['bootout', target];
|
|
33
|
+
const answer = await this.#run(args, signal);
|
|
34
|
+
if (answer.exitCode === NO_SUCH_PROCESS)
|
|
35
|
+
return true;
|
|
36
|
+
if (answer.exitCode === 0 || answer.exitCode === IN_PROGRESS)
|
|
37
|
+
return false;
|
|
38
|
+
throw this.#error(args, answer);
|
|
39
|
+
}
|
|
40
|
+
async bootstrap(domain, file, signal) {
|
|
41
|
+
const args = ['bootstrap', domain, file];
|
|
42
|
+
this.#succeeded(args, await this.#run(args, signal));
|
|
43
|
+
}
|
|
44
|
+
async enable(target, signal) {
|
|
45
|
+
const args = ['enable', target];
|
|
46
|
+
this.#succeeded(args, await this.#run(args, signal));
|
|
47
|
+
}
|
|
48
|
+
async disable(target, signal) {
|
|
49
|
+
const args = ['disable', target];
|
|
50
|
+
this.#succeeded(args, await this.#run(args, signal));
|
|
51
|
+
}
|
|
52
|
+
/** The PID that `-p` prints. */
|
|
53
|
+
async kickstart(target, kill, signal) {
|
|
54
|
+
const args = ['kickstart', ...(kill ? ['-k'] : []), '-p', target];
|
|
55
|
+
const answer = await this.#run(args, signal);
|
|
56
|
+
this.#found(args, answer, target);
|
|
57
|
+
return Number(answer.stdout);
|
|
58
|
+
}
|
|
59
|
+
async kill(target, processSignal, signal) {
|
|
60
|
+
const args = ['kill', String(processSignal), target];
|
|
61
|
+
this.#found(args, await this.#run(args, signal), target);
|
|
62
|
+
}
|
|
63
|
+
#found(args, answer, target) {
|
|
64
|
+
if (answer.exitCode === SERVICE_NOT_FOUND) {
|
|
65
|
+
throw new ServiceNotFoundError(args, answer.exitCode, answer.stderr, target);
|
|
66
|
+
}
|
|
67
|
+
this.#succeeded(args, answer);
|
|
68
|
+
}
|
|
69
|
+
#succeeded(args, answer) {
|
|
70
|
+
if (answer.exitCode !== 0)
|
|
71
|
+
throw this.#error(args, answer);
|
|
72
|
+
}
|
|
73
|
+
#error(args, answer) {
|
|
74
|
+
const error = new LaunchctlError(args, answer.exitCode, answer.stderr);
|
|
75
|
+
return answer.exitCode === NOT_PERMITTED
|
|
76
|
+
? new PermissionDeniedError(error)
|
|
77
|
+
: error;
|
|
78
|
+
}
|
|
79
|
+
// A cancel stops the wait, not the subcommand, as a cancel of the bootout
|
|
80
|
+
// wait leaves launchd to finish the bootout (ADR 0004).
|
|
81
|
+
#run(args, signal) {
|
|
82
|
+
const { promise, resolve, reject } = Promise.withResolvers();
|
|
83
|
+
execFile('/bin/launchctl', args, { encoding: 'utf8' }, (error, stdout, stderr) => {
|
|
84
|
+
if (error === null)
|
|
85
|
+
resolve({ exitCode: 0, stdout, stderr });
|
|
86
|
+
else if (typeof error.code === 'number') {
|
|
87
|
+
resolve({ exitCode: error.code, stdout, stderr });
|
|
88
|
+
}
|
|
89
|
+
else if (isErrno(error, 'ENOENT')) {
|
|
90
|
+
reject(new LaunchdUnavailableError(error));
|
|
91
|
+
}
|
|
92
|
+
else
|
|
93
|
+
reject(error);
|
|
94
|
+
});
|
|
95
|
+
return untilAborted(promise, signal);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=launchctl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launchctl.js","sourceRoot":"","sources":["../../src/launchctl/launchctl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,OAAO,EACL,cAAc,EACd,uBAAuB,EACvB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,cAAc,CAAC;AAUtB,wCAAwC;AACxC,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,MAAM,eAAe,GAAG,CAAC,CAAC;AAC1B,MAAM,WAAW,GAAG,EAAE,CAAC;AACvB,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAE9B,0EAA0E;AAC1E,8DAA8D;AAC9D,MAAM,GAAG,GAAG,kBAAkB,CAAC;AAC/B,MAAM,cAAc,GAAG,4BAA4B,CAAC;AAEpD,6FAA6F;AAC7F,MAAM,OAAO,SAAS;IACpB,sDAAsD;IACtD,KAAK,CAAC,KAAK,CAAC,MAAc,EAAE,MAAoB;QAC9C,MAAM,IAAI,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;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AAE,MAAM,EAAE,EAAE;YACxB,IAAI,KAAK,KAAK,IAAI;gBAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;iBACxD,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACxC,OAAO,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;YACpD,CAAC;iBAAM,IAAI,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE,CAAC;gBACpC,MAAM,CAAC,IAAI,uBAAuB,CAAC,KAAK,CAAC,CAAC,CAAC;YAC7C,CAAC;;gBAAM,MAAM,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC,CACF,CAAC;QACF,OAAO,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACvC,CAAC;CACF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type Clock } from '@zukhruf/async';
|
|
2
|
+
import type { AgentJob } from '../job/agent-job.ts';
|
|
3
|
+
import type { DaemonJob } from '../job/daemon-job.ts';
|
|
4
|
+
import type { CancelOptions } from '../launchctl/cancel-options.ts';
|
|
5
|
+
import type { Domain } from '../launchctl/domain.ts';
|
|
6
|
+
import { Service } from '../service/service.ts';
|
|
7
|
+
export interface LaunchdOptions {
|
|
8
|
+
/** The clock of the waits: the bootout wait and the atomic write. Production gives `globalThis`. */
|
|
9
|
+
clock: Clock;
|
|
10
|
+
}
|
|
11
|
+
/** The jobs of one domain, and the folder of their job files. */
|
|
12
|
+
export declare class Launchd<J extends AgentJob | DaemonJob> {
|
|
13
|
+
#private;
|
|
14
|
+
/** The domain-target: 'gui/501', 'user/501' or 'system'. */
|
|
15
|
+
readonly domain: Domain;
|
|
16
|
+
/** The absolute path of the folder of the job files. */
|
|
17
|
+
readonly folder: string;
|
|
18
|
+
private constructor();
|
|
19
|
+
/** This user's agents: gui/<uid> when this uid owns /dev/console, else user/<uid>. The folder is Library/LaunchAgents under $HOME (ADR 0005). */
|
|
20
|
+
static agents({ clock }: LaunchdOptions): Launchd<AgentJob>;
|
|
21
|
+
/** The daemons of the system domain, in /Library/LaunchDaemons. A change needs root. */
|
|
22
|
+
static daemons({ clock }: LaunchdOptions): Launchd<DaemonJob>;
|
|
23
|
+
/** The reconcile: writes <folder>/<Label>.plist when its bytes differ, boots out the old service, enables, bootstraps. */
|
|
24
|
+
install(job: J, options?: CancelOptions): Promise<Service>;
|
|
25
|
+
/** The handle of a label in this domain. Reads nothing and runs nothing. */
|
|
26
|
+
service(label: string): Service;
|
|
27
|
+
/** A handle for each <folder>/*.plist, with the label from the file name, sorted. No folder gives []. */
|
|
28
|
+
installed({ signal }?: CancelOptions): Promise<Service[]>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=launchd.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launchd.d.ts","sourceRoot":"","sources":["../../src/launchd/launchd.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,KAAK,EAAgB,MAAM,gBAAgB,CAAC;AAE1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhD,MAAM,WAAW,cAAc;IAC7B,oGAAoG;IACpG,KAAK,EAAE,KAAK,CAAC;CACd;AAED,iEAAiE;AACjE,qBAAa,OAAO,CAAC,CAAC,SAAS,QAAQ,GAAG,SAAS;;IACjD,4DAA4D;IAC5D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,wDAAwD;IACxD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAIxB,OAAO;IAMP,iJAAiJ;IACjJ,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC;IAU3D,wFAAwF;IACxF,MAAM,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC;IAI7D,0HAA0H;IACpH,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,OAAO,CAAC;IAoBpE,4EAA4E;IAC5E,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAI/B,yGAAyG;IACnG,SAAS,CAAC,EAAE,MAAM,EAAE,GAAE,aAAkB,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CAQpE"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { statSync } from 'node:fs';
|
|
2
|
+
import { homedir, userInfo } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { untilAborted } from '@zukhruf/async';
|
|
5
|
+
import { JobFile } from "../job/job-file.js";
|
|
6
|
+
import { Launchctl } from "../launchctl/launchctl.js";
|
|
7
|
+
import { Service } from "../service/service.js";
|
|
8
|
+
/** The jobs of one domain, and the folder of their job files. */
|
|
9
|
+
export class Launchd {
|
|
10
|
+
/** The domain-target: 'gui/501', 'user/501' or 'system'. */
|
|
11
|
+
domain;
|
|
12
|
+
/** The absolute path of the folder of the job files. */
|
|
13
|
+
folder;
|
|
14
|
+
#clock;
|
|
15
|
+
#launchctl = new Launchctl();
|
|
16
|
+
constructor(domain, folder, clock) {
|
|
17
|
+
this.domain = domain;
|
|
18
|
+
this.folder = folder;
|
|
19
|
+
this.#clock = clock;
|
|
20
|
+
}
|
|
21
|
+
/** This user's agents: gui/<uid> when this uid owns /dev/console, else user/<uid>. The folder is Library/LaunchAgents under $HOME (ADR 0005). */
|
|
22
|
+
static agents({ clock }) {
|
|
23
|
+
const { uid } = userInfo();
|
|
24
|
+
const atConsole = statSync('/dev/console').uid === uid;
|
|
25
|
+
return new Launchd(atConsole ? `gui/${uid}` : `user/${uid}`, join(homedir(), 'Library', 'LaunchAgents'), clock);
|
|
26
|
+
}
|
|
27
|
+
/** The daemons of the system domain, in /Library/LaunchDaemons. A change needs root. */
|
|
28
|
+
static daemons({ clock }) {
|
|
29
|
+
return new Launchd('system', '/Library/LaunchDaemons', clock);
|
|
30
|
+
}
|
|
31
|
+
/** The reconcile: writes <folder>/<Label>.plist when its bytes differ, boots out the old service, enables, bootstraps. */
|
|
32
|
+
async install(job, options = {}) {
|
|
33
|
+
const jobFile = new JobFile(this.folder, job.Label);
|
|
34
|
+
const service = this.#service(jobFile);
|
|
35
|
+
const content = JobFile.render(job);
|
|
36
|
+
if (await jobFile.holds(content)) {
|
|
37
|
+
if ((await service.state(options)).state !== 'not loaded') {
|
|
38
|
+
return service;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
// The old bytes stay until launchd has forgotten the old service, so an
|
|
43
|
+
// install that stops here leaves other bytes, and the next one repeats
|
|
44
|
+
// the work (ADR 0003).
|
|
45
|
+
await service.bootout(options);
|
|
46
|
+
await jobFile.write(content, this.#clock);
|
|
47
|
+
}
|
|
48
|
+
await service.enable(options);
|
|
49
|
+
await service.bootstrap(options);
|
|
50
|
+
return service;
|
|
51
|
+
}
|
|
52
|
+
/** The handle of a label in this domain. Reads nothing and runs nothing. */
|
|
53
|
+
service(label) {
|
|
54
|
+
return this.#service(new JobFile(this.folder, label));
|
|
55
|
+
}
|
|
56
|
+
/** A handle for each <folder>/*.plist, with the label from the file name, sorted. No folder gives []. */
|
|
57
|
+
async installed({ signal } = {}) {
|
|
58
|
+
const labels = await untilAborted(JobFile.labels(this.folder), signal);
|
|
59
|
+
return labels.map((label) => this.service(label));
|
|
60
|
+
}
|
|
61
|
+
#service(jobFile) {
|
|
62
|
+
return new Service(jobFile, this.domain, this.#launchctl, this.#clock);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=launchd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launchd.js","sourceRoot":"","sources":["../../src/launchd/launchd.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAc,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAI1D,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAG7C,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAOhD,iEAAiE;AACjE,MAAM,OAAO,OAAO;IAClB,4DAA4D;IACnD,MAAM,CAAS;IACxB,wDAAwD;IAC/C,MAAM,CAAS;IACf,MAAM,CAAQ;IACd,UAAU,GAAG,IAAI,SAAS,EAAE,CAAC;IAEtC,YAAoB,MAAc,EAAE,MAAc,EAAE,KAAY;QAC9D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,iJAAiJ;IACjJ,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAkB;QACrC,MAAM,EAAE,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;QAC3B,MAAM,SAAS,GAAG,QAAQ,CAAC,cAAc,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC;QACvD,OAAO,IAAI,OAAO,CAChB,SAAS,CAAC,CAAC,CAAC,OAAO,GAAG,EAAE,CAAC,CAAC,CAAC,QAAQ,GAAG,EA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,KAAK,CAAC,CAAC,CAAC;IACxD,CAAC;IAED,yGAAyG;IACzG,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,KAAoB,EAAE;QAC5C,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;QACvE,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;IACpD,CAAC;IAED,QAAQ,CAAC,OAAgB;QACvB,OAAO,IAAI,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACzE,CAAC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** What `launchctl print` shows of one service. */
|
|
2
|
+
export type ServiceState = {
|
|
3
|
+
readonly state: 'not loaded';
|
|
4
|
+
} | {
|
|
5
|
+
readonly state: 'running';
|
|
6
|
+
readonly pid: number;
|
|
7
|
+
/** undefined: no number in a `last exit code` line, or no such line. */
|
|
8
|
+
readonly lastExitStatus: number | undefined;
|
|
9
|
+
} | {
|
|
10
|
+
readonly state: 'not running';
|
|
11
|
+
readonly lastExitStatus: number | undefined;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=service-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-state.d.ts","sourceRoot":"","sources":["../../src/service/service-state.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,MAAM,MAAM,YAAY,GACpB;IAAE,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAA;CAAE,GAChC;IACE,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,wEAAwE;IACxE,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7C,GACD;IACE,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-state.js","sourceRoot":"","sources":["../../src/service/service-state.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type Clock } from '@zukhruf/async';
|
|
2
|
+
import type { JobFile } from '../job/job-file.ts';
|
|
3
|
+
import type { CancelOptions } from '../launchctl/cancel-options.ts';
|
|
4
|
+
import type { Domain } from '../launchctl/domain.ts';
|
|
5
|
+
import type { Launchctl } from '../launchctl/launchctl.ts';
|
|
6
|
+
import type { ServiceState } from './service-state.ts';
|
|
7
|
+
/** One label in one domain. A handle: it holds no state, and it exists also when launchd has no such service. */
|
|
8
|
+
export declare class Service {
|
|
9
|
+
#private;
|
|
10
|
+
readonly label: string;
|
|
11
|
+
/** The job file: <folder>/<label>.plist. */
|
|
12
|
+
readonly file: string;
|
|
13
|
+
/** The service-target: <domain>/<label>, such as 'gui/501/com.example.sync'. */
|
|
14
|
+
readonly target: string;
|
|
15
|
+
constructor(jobFile: JobFile, domain: Domain, launchctl: Launchctl, clock: Clock);
|
|
16
|
+
/** One `launchctl print <target>`: exit code 113 and the lines `pid =` and `last exit code =`. */
|
|
17
|
+
state({ signal }?: CancelOptions): Promise<ServiceState>;
|
|
18
|
+
/** Runs the service now (`kickstart -p`). With `kill`, kills the process that runs first (`-k`). Gives the PID of the new process, or of the process that runs. */
|
|
19
|
+
kickstart({ kill, signal, }?: CancelOptions & {
|
|
20
|
+
kill?: boolean;
|
|
21
|
+
}): Promise<number>;
|
|
22
|
+
/** Sends a process signal, by name or number, to the process of the service. */
|
|
23
|
+
kill(processSignal: NodeJS.Signals | number, { signal }?: CancelOptions): Promise<void>;
|
|
24
|
+
/** Enables the service: launchd may load it again. */
|
|
25
|
+
enable({ signal }?: CancelOptions): Promise<void>;
|
|
26
|
+
/** Disables the service: launchd does not load it until enable(), also after a restart. */
|
|
27
|
+
disable({ signal }?: CancelOptions): Promise<void>;
|
|
28
|
+
/** Loads the job file into the domain. */
|
|
29
|
+
bootstrap({ signal }?: CancelOptions): Promise<void>;
|
|
30
|
+
/** Removes the service from the domain, and waits until launchd forgets it. The job file stays. */
|
|
31
|
+
bootout({ signal }?: CancelOptions): Promise<void>;
|
|
32
|
+
/** bootout(), then removes the job file. Resolves when neither is there. */
|
|
33
|
+
uninstall(options?: CancelOptions): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/service/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAQ,MAAM,gBAAgB,CAAC;AAElD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,iHAAiH;AACjH,qBAAa,OAAO;;IAClB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,4CAA4C;IAC5C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,gFAAgF;IAChF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAOtB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,KAAK;IAWd,kGAAkG;IAClG,KAAK,CAAC,EAAE,MAAM,EAAE,GAAE,aAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;IAI5D,mKAAmK;IACnK,SAAS,CAAC,EACR,IAAY,EACZ,MAAM,GACP,GAAE,aAAa,GAAG;QAAE,IAAI,CAAC,EAAE,OAAO,CAAA;KAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAI5D,gFAAgF;IAChF,IAAI,CACF,aAAa,EAAE,MAAM,CAAC,OAAO,GAAG,MAAM,EACtC,EAAE,MAAM,EAAE,GAAE,aAAkB,GAC7B,OAAO,CAAC,IAAI,CAAC;IAIhB,sDAAsD;IACtD,MAAM,CAAC,EAAE,MAAM,EAAE,GAAE,aAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrD,2FAA2F;IAC3F,OAAO,CAAC,EAAE,MAAM,EAAE,GAAE,aAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAItD,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,EAAE,GAAE,aAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxD,mGAAmG;IAC7F,OAAO,CAAC,EAAE,MAAM,EAAE,GAAE,aAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAU5D,4EAA4E;IACtE,SAAS,CAAC,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;CAI5D"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { poll } from '@zukhruf/async';
|
|
2
|
+
/** One label in one domain. A handle: it holds no state, and it exists also when launchd has no such service. */
|
|
3
|
+
export class Service {
|
|
4
|
+
label;
|
|
5
|
+
/** The job file: <folder>/<label>.plist. */
|
|
6
|
+
file;
|
|
7
|
+
/** The service-target: <domain>/<label>, such as 'gui/501/com.example.sync'. */
|
|
8
|
+
target;
|
|
9
|
+
#domain;
|
|
10
|
+
#jobFile;
|
|
11
|
+
#launchctl;
|
|
12
|
+
#clock;
|
|
13
|
+
constructor(jobFile, domain, launchctl, clock) {
|
|
14
|
+
this.label = jobFile.label;
|
|
15
|
+
this.file = jobFile.path;
|
|
16
|
+
this.target = `${domain}/${jobFile.label}`;
|
|
17
|
+
this.#domain = domain;
|
|
18
|
+
this.#jobFile = jobFile;
|
|
19
|
+
this.#launchctl = launchctl;
|
|
20
|
+
this.#clock = clock;
|
|
21
|
+
}
|
|
22
|
+
/** One `launchctl print <target>`: exit code 113 and the lines `pid =` and `last exit code =`. */
|
|
23
|
+
state({ signal } = {}) {
|
|
24
|
+
return this.#launchctl.print(this.target, signal);
|
|
25
|
+
}
|
|
26
|
+
/** Runs the service now (`kickstart -p`). With `kill`, kills the process that runs first (`-k`). Gives the PID of the new process, or of the process that runs. */
|
|
27
|
+
kickstart({ kill = false, signal, } = {}) {
|
|
28
|
+
return this.#launchctl.kickstart(this.target, kill, signal);
|
|
29
|
+
}
|
|
30
|
+
/** Sends a process signal, by name or number, to the process of the service. */
|
|
31
|
+
kill(processSignal, { signal } = {}) {
|
|
32
|
+
return this.#launchctl.kill(this.target, processSignal, signal);
|
|
33
|
+
}
|
|
34
|
+
/** Enables the service: launchd may load it again. */
|
|
35
|
+
enable({ signal } = {}) {
|
|
36
|
+
return this.#launchctl.enable(this.target, signal);
|
|
37
|
+
}
|
|
38
|
+
/** Disables the service: launchd does not load it until enable(), also after a restart. */
|
|
39
|
+
disable({ signal } = {}) {
|
|
40
|
+
return this.#launchctl.disable(this.target, signal);
|
|
41
|
+
}
|
|
42
|
+
/** Loads the job file into the domain. */
|
|
43
|
+
bootstrap({ signal } = {}) {
|
|
44
|
+
return this.#launchctl.bootstrap(this.#domain, this.file, signal);
|
|
45
|
+
}
|
|
46
|
+
/** Removes the service from the domain, and waits until launchd forgets it. The job file stays. */
|
|
47
|
+
async bootout({ signal } = {}) {
|
|
48
|
+
// launchd answers before the process is gone, and refuses a bootstrap of
|
|
49
|
+
// the label until then; it gives no event when it forgets the service.
|
|
50
|
+
await poll(async () => (await this.#launchctl.bootout(this.target, signal)) ? true : undefined, { interval: 1000, signal, clock: this.#clock });
|
|
51
|
+
}
|
|
52
|
+
/** bootout(), then removes the job file. Resolves when neither is there. */
|
|
53
|
+
async uninstall(options = {}) {
|
|
54
|
+
await this.bootout(options);
|
|
55
|
+
await this.#jobFile.remove();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/service/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAQlD,iHAAiH;AACjH,MAAM,OAAO,OAAO;IACT,KAAK,CAAS;IACvB,4CAA4C;IACnC,IAAI,CAAS;IACtB,gFAAgF;IACvE,MAAM,CAAS;IACf,OAAO,CAAS;IAChB,QAAQ,CAAU;IAClB,UAAU,CAAY;IACtB,MAAM,CAAQ;IAEvB,YACE,OAAgB,EAChB,MAAc,EACd,SAAoB,EACpB,KAAY;QAEZ,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,GAAG,MAAM,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QAC3C,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,kGAAkG;IAClG,KAAK,CAAC,EAAE,MAAM,KAAoB,EAAE;QAClC,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpD,CAAC;IAED,mKAAmK;IACnK,SAAS,CAAC,EACR,IAAI,GAAG,KAAK,EACZ,MAAM,MACgC,EAAE;QACxC,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CA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,OAAO,CAAC,CAAC;QAC5B,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC/B,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zukhruf/launchd",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.8.19",
|
|
4
|
+
"description": "Install the jobs of launchd, the service manager of macOS, from a job typed with the key names of launchd.plist(5), and drive their services with the current subcommands of launchctl. After Homebrew services and nix-darwin, on /bin/launchctl.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/JanuaryLabs/zukhruf",
|
|
9
|
+
"directory": "packages/launchd"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/JanuaryLabs/zukhruf/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/JanuaryLabs/zukhruf/tree/main/packages/launchd#readme",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"launchd",
|
|
17
|
+
"launchctl",
|
|
18
|
+
"launch-agent",
|
|
19
|
+
"launch-daemon",
|
|
20
|
+
"plist",
|
|
21
|
+
"service",
|
|
22
|
+
"daemon",
|
|
23
|
+
"macos"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"exports": {
|
|
27
|
+
"./package.json": "./package.json",
|
|
28
|
+
".": {
|
|
29
|
+
"@zukhruf/source": "./src/index.ts",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/index.js",
|
|
32
|
+
"default": "./dist/index.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"!dist/spec/**",
|
|
38
|
+
"!**/*.tsbuildinfo",
|
|
39
|
+
"!**/*.test.*"
|
|
40
|
+
],
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@zukhruf/async": "^0.8.19",
|
|
46
|
+
"@zukhruf/fs": "^0.8.19",
|
|
47
|
+
"plist": "^5.1.1"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@zukhruf/testing": "^0.8.19"
|
|
51
|
+
}
|
|
52
|
+
}
|