@julianpoemp/node-service 1.1.0 → 1.2.0

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.
@@ -1,6 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LinuxServiceManager = void 0;
4
+ exports.parseSystemctlState = parseSystemctlState;
5
+ exports.escapeSystemdSpecifiers = escapeSystemdSpecifiers;
6
+ exports.quoteSystemdExecArg = quoteSystemdExecArg;
7
+ exports.buildSystemdExecStart = buildSystemdExecStart;
8
+ exports.buildSystemdEnvironment = buildSystemdEnvironment;
4
9
  const tslib_1 = require("tslib");
5
10
  const os_service_manager_1 = require("./os-service-manager");
6
11
  const functions_1 = require("./functions");
@@ -8,6 +13,52 @@ const path_1 = require("path");
8
13
  const os_1 = require("os");
9
14
  const Path = require("node:path");
10
15
  const promises_1 = require("fs/promises");
16
+ /**
17
+ * Maps the output of `systemctl status <name>.service` to a service status.
18
+ * @returns undefined if the output contains no known state
19
+ */
20
+ function parseSystemctlState(output) {
21
+ var _a;
22
+ const state = (_a = / *Active: *([^ (]+) \(([^(]+)\)/.exec(output)) === null || _a === void 0 ? void 0 : _a[1];
23
+ switch (state) {
24
+ case 'active':
25
+ return os_service_manager_1.OSServiceStatus.running;
26
+ case 'inactive':
27
+ return os_service_manager_1.OSServiceStatus.stopped;
28
+ case 'activating':
29
+ case 'deactivating':
30
+ case 'reloading':
31
+ return os_service_manager_1.OSServiceStatus.waiting;
32
+ case 'failed':
33
+ return os_service_manager_1.OSServiceStatus.failed;
34
+ default:
35
+ return undefined;
36
+ }
37
+ }
38
+ /**
39
+ * Escapes systemd specifiers (`%n`, `%h`, …) in a unit file value.
40
+ */
41
+ function escapeSystemdSpecifiers(value) {
42
+ return `${value}`.replace(/%/g, '%%');
43
+ }
44
+ /**
45
+ * Quotes one word of ExecStart: paths and arguments with spaces, quotes, backslashes, `%` or `$` stay one argument
46
+ * and arrive unchanged (systemd would otherwise expand specifiers and environment variables).
47
+ */
48
+ function quoteSystemdExecArg(value) {
49
+ const escaped = escapeSystemdSpecifiers(`${value}`.replace(/\\/g, '\\\\').replace(/"/g, '\\"')).replace(/\$/g, '$$$$');
50
+ return `"${escaped}"`;
51
+ }
52
+ function buildSystemdExecStart(command, args) {
53
+ return [command, ...args].map(quoteSystemdExecArg).join(' ');
54
+ }
55
+ /**
56
+ * `Environment="KEY=value"` with quotes, backslashes and specifiers escaped. Environment= doesn't expand `$`.
57
+ */
58
+ function buildSystemdEnvironment(key, value) {
59
+ const escaped = escapeSystemdSpecifiers(`${key}=${value}`.replace(/\\/g, '\\\\').replace(/"/g, '\\"'));
60
+ return `Environment="${escaped}"`;
61
+ }
11
62
  class LinuxServiceManager extends os_service_manager_1.OSServiceManager {
12
63
  constructor() {
13
64
  super(...arguments);
@@ -36,7 +87,7 @@ class LinuxServiceManager extends os_service_manager_1.OSServiceManager {
36
87
  this._installationOptions = options;
37
88
  yield this.prepareLogging();
38
89
  if (yield this.isInstalled()) {
39
- throw new Error(`Node-Service Error: Can't install service. Service already exists. Unload it via launchctl unload or call manager.stop();`);
90
+ throw new Error(`Node-Service Error: Can't install service. Service already exists. Remove it via systemctl disable or call manager.uninstall();`);
40
91
  }
41
92
  const configString = this.buildServiceFile(options);
42
93
  if (!(yield (0, functions_1.exists)(this.paths.root))) {
@@ -45,33 +96,32 @@ class LinuxServiceManager extends os_service_manager_1.OSServiceManager {
45
96
  });
46
97
  }
47
98
  const userCommand = this.options.level === 'system' ? '' : ' --user';
48
- const logFolderCreation = ((_a = options.logging) === null || _a === void 0 ? void 0 : _a.enabled)
49
- ? `&& mkdir -p ${this.paths.logRoot} 2>/dev/null && chmod 745 ${this.paths.logRoot} && touch ${this.paths.log} 2>/dev/null && chmod 745 ${this.paths.log} && touch ${this.paths.errorLog} 2>/dev/null && chmod 745 ${this.paths.errorLog} `
50
- : '';
51
- let script = `printf '${configString
52
- .replace(/'/g, '"')
53
- .replace(/\n/g, '\\n')}' > "/tmp/${this.options.slug}.service" `;
54
- script += `${logFolderCreation}`;
55
- script += `&& mv -f "/tmp/${this.options.slug}.service" "${this.paths.config}" `;
56
- script += `&& systemctl${userCommand} daemon-reload && `;
57
- script += `systemctl${userCommand} enable ${this.options.slug}.service`;
58
- if (this.options.level === 'system') {
59
- if (this.options.debugging) {
60
- console.log(`NODE-SERVICE DEBUG: RUN AS ADMIN`);
61
- console.log(`NODE-SERVICE DEBUG: ${script}`);
99
+ // the unit file is written as is and copied by the script - no shell escaping of its content
100
+ const unitFile = yield (0, functions_1.writeTempFile)(`${this.options.slug}.service`, configString);
101
+ try {
102
+ const commands = [];
103
+ if ((_a = options.logging) === null || _a === void 0 ? void 0 : _a.enabled) {
104
+ commands.push(...(0, functions_1.buildLogFolderCommands)(this.paths.logRoot, this.paths.log, this.paths.errorLog));
62
105
  }
63
- yield functions_1.ScriptRunner.runAsAdmin(script, {
64
- name: this.options.name,
65
- icns: this.options.icns,
66
- headless: this.options.headless,
67
- });
68
- }
69
- else {
70
- if (this.options.debugging) {
71
- console.log(`NODE-SERVICE DEBUG: RUN`);
72
- console.log(`NODE-SERVICE DEBUG: ${script}`);
106
+ commands.push(`install -m 644 ${(0, functions_1.shellQuote)(unitFile.path)} ${(0, functions_1.shellQuote)(this.paths.config)}`, `systemctl${userCommand} daemon-reload`, `systemctl${userCommand} enable ${(0, functions_1.shellQuote)(`${this.options.slug}.service`)}`);
107
+ const script = commands.join(' && ');
108
+ if (this.options.level === 'system') {
109
+ this.debug(`RUN AS ADMIN`);
110
+ this.debug(script);
111
+ yield functions_1.ScriptRunner.runAsAdmin(script, {
112
+ name: this.options.name,
113
+ icns: this.options.icns,
114
+ headless: this.options.headless,
115
+ });
116
+ }
117
+ else {
118
+ this.debug(`RUN`);
119
+ this.debug(script);
120
+ yield functions_1.ScriptRunner.run(script);
73
121
  }
74
- yield functions_1.ScriptRunner.run(script);
122
+ }
123
+ finally {
124
+ yield unitFile.cleanup();
75
125
  }
76
126
  yield this.updateStatus();
77
127
  });
@@ -88,20 +138,16 @@ class LinuxServiceManager extends os_service_manager_1.OSServiceManager {
88
138
  const userCommand = this.options.level === 'system' ? '' : ' --user';
89
139
  const script = `systemctl${userCommand} start "${this.options.slug}"`;
90
140
  if (this.options.level === 'system') {
91
- if (this.options.debugging) {
92
- console.log(`NODE-SERVICE DEBUG: RUN AS ADMIN`);
93
- console.log(`NODE-SERVICE DEBUG: ${script}`);
94
- }
141
+ this.debug(`RUN AS ADMIN`);
142
+ this.debug(script);
95
143
  yield functions_1.ScriptRunner.runAsAdmin(script, {
96
144
  name: this.options.name,
97
145
  headless: this.options.headless,
98
146
  });
99
147
  }
100
148
  else {
101
- if (this.options.debugging) {
102
- console.log(`NODE-SERVICE DEBUG: RUN`);
103
- console.log(`NODE-SERVICE DEBUG: ${script}`);
104
- }
149
+ this.debug(`RUN`);
150
+ this.debug(script);
105
151
  yield functions_1.ScriptRunner.run(script);
106
152
  }
107
153
  yield this.updateStatus();
@@ -109,34 +155,19 @@ class LinuxServiceManager extends os_service_manager_1.OSServiceManager {
109
155
  }
110
156
  updateStatus() {
111
157
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
112
- try {
113
- const userCommand = this.options.level === 'system' ? '' : ' --user';
114
- const output = yield functions_1.ScriptRunner.run(`systemctl${userCommand} status ${this.options.slug}.service`);
115
- const matches = / *Active: *([^ (]+) \(([^(]+)\)/g.exec(output);
116
- if (matches && matches.length > 0) {
117
- switch (matches[1]) {
118
- case 'active':
119
- this._status = os_service_manager_1.OSServiceStatus.running;
120
- break;
121
- case 'inactive':
122
- this._status = os_service_manager_1.OSServiceStatus.stopped;
123
- break;
124
- case 'activating':
125
- this._status = os_service_manager_1.OSServiceStatus.waiting;
126
- break;
127
- case 'failed':
128
- this._status = os_service_manager_1.OSServiceStatus.failed;
129
- break;
130
- }
131
- }
158
+ const userCommand = this.options.level === 'system' ? '' : ' --user';
159
+ const command = `systemctl${userCommand} status ${this.options.slug}.service`;
160
+ // systemctl status exits with 3 for inactive and 4 for unknown units
161
+ const result = yield functions_1.ScriptRunner.exec(command);
162
+ const status = parseSystemctlState(result.stdout);
163
+ if (status) {
164
+ this._status = status;
132
165
  }
133
- catch (e) {
134
- if (/could not be found./g.exec(e)) {
135
- this._status = os_service_manager_1.OSServiceStatus.not_installed;
136
- }
137
- else {
138
- throw new Error(e);
139
- }
166
+ else if (/could not be found/.test(`${result.stdout}\n${result.stderr}`)) {
167
+ this._status = os_service_manager_1.OSServiceStatus.not_installed;
168
+ }
169
+ else if (result.code !== 0) {
170
+ throw new functions_1.ScriptRunnerError(command, result.code, result.stdout, result.stderr);
140
171
  }
141
172
  });
142
173
  }
@@ -145,20 +176,16 @@ class LinuxServiceManager extends os_service_manager_1.OSServiceManager {
145
176
  const userCommand = this.options.level === 'system' ? '' : ' --user';
146
177
  const script = `systemctl${userCommand} stop '${this.options.slug}'`;
147
178
  if (this.options.level === 'system') {
148
- if (this.options.debugging) {
149
- console.log(`NODE-SERVICE DEBUG: RUN AS ADMIN`);
150
- console.log(`NODE-SERVICE DEBUG: ${script}`);
151
- }
179
+ this.debug(`RUN AS ADMIN`);
180
+ this.debug(script);
152
181
  yield functions_1.ScriptRunner.runAsAdmin(script, {
153
182
  name: this.options.name,
154
183
  headless: this.options.headless,
155
184
  });
156
185
  }
157
186
  else {
158
- if (this.options.debugging) {
159
- console.log(`NODE-SERVICE DEBUG: RUN`);
160
- console.log(`NODE-SERVICE DEBUG: ${script}`);
161
- }
187
+ this.debug(`RUN`);
188
+ this.debug(script);
162
189
  yield functions_1.ScriptRunner.run(script);
163
190
  }
164
191
  yield this.updateStatus();
@@ -175,55 +202,51 @@ class LinuxServiceManager extends os_service_manager_1.OSServiceManager {
175
202
  removeScript += ` && rm -rf '${this.paths.logRoot}'`;
176
203
  }
177
204
  if (this.options.level === 'system') {
178
- if (this.options.debugging) {
179
- console.log(`NODE-SERVICE DEBUG: RUN AS ADMIN`);
180
- console.log(`NODE-SERVICE DEBUG: ${removeScript}`);
181
- }
205
+ this.debug(`RUN AS ADMIN`);
206
+ this.debug(removeScript);
182
207
  yield functions_1.ScriptRunner.runAsAdmin(removeScript, {
183
208
  name: `Uninstallation of ${this.options.name}`,
184
209
  headless: this.options.headless,
185
210
  });
186
211
  }
187
212
  else {
188
- if (this.options.debugging) {
189
- console.log(`NODE-SERVICE DEBUG: RUN`);
190
- console.log(`NODE-SERVICE DEBUG: ${removeScript}`);
191
- }
213
+ this.debug(`RUN`);
214
+ this.debug(removeScript);
192
215
  yield functions_1.ScriptRunner.run(removeScript);
193
216
  }
194
217
  yield this.updateStatus();
195
218
  });
196
219
  }
197
220
  buildServiceFile(options) {
198
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
199
- const command = `${this.command}${this.commandArgs ? ` ${this.commandArgs.join(' ')}` : ''}`;
221
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
222
+ const command = buildSystemdExecStart(this.command, (_a = this.commandArgs) !== null && _a !== void 0 ? _a : []);
200
223
  const configObject = (0, functions_1.removeEmptyProperties)({
201
224
  Unit: {
202
225
  Description: options.description,
203
- After: (_b = (_a = options.linux) === null || _a === void 0 ? void 0 : _a.Unit) === null || _b === void 0 ? void 0 : _b.After,
204
- Before: (_d = (_c = options.linux) === null || _c === void 0 ? void 0 : _c.Unit) === null || _d === void 0 ? void 0 : _d.Before,
205
- StartLimitIntervalSec: (_f = (_e = options.linux) === null || _e === void 0 ? void 0 : _e.Unit) === null || _f === void 0 ? void 0 : _f.StartLimitIntervalSync,
226
+ After: (_c = (_b = options.linux) === null || _b === void 0 ? void 0 : _b.Unit) === null || _c === void 0 ? void 0 : _c.After,
227
+ Before: (_e = (_d = options.linux) === null || _d === void 0 ? void 0 : _d.Unit) === null || _e === void 0 ? void 0 : _e.Before,
228
+ StartLimitIntervalSec: (_g = (_f = options.linux) === null || _f === void 0 ? void 0 : _f.Unit) === null || _g === void 0 ? void 0 : _g.StartLimitIntervalSync,
206
229
  },
207
230
  Service: {
208
- Type: (_h = (_g = options.linux) === null || _g === void 0 ? void 0 : _g.Service) === null || _h === void 0 ? void 0 : _h.Type,
209
- Restart: (_k = (_j = options.linux) === null || _j === void 0 ? void 0 : _j.Service) === null || _k === void 0 ? void 0 : _k.Restart,
210
- RestartSec: (_m = (_l = options.linux) === null || _l === void 0 ? void 0 : _l.Service) === null || _m === void 0 ? void 0 : _m.RestartSec,
211
- StandardOutput: this.paths.log ? `file:${this.paths.log}` : undefined,
231
+ Type: (_j = (_h = options.linux) === null || _h === void 0 ? void 0 : _h.Service) === null || _j === void 0 ? void 0 : _j.Type,
232
+ Restart: (_l = (_k = options.linux) === null || _k === void 0 ? void 0 : _k.Service) === null || _l === void 0 ? void 0 : _l.Restart,
233
+ RestartSec: (_o = (_m = options.linux) === null || _m === void 0 ? void 0 : _m.Service) === null || _o === void 0 ? void 0 : _o.RestartSec,
234
+ StandardOutput: this.paths.log
235
+ ? `file:${escapeSystemdSpecifiers(this.paths.log)}`
236
+ : undefined,
212
237
  StandardError: this.paths.errorLog
213
- ? `file:${this.paths.errorLog}`
238
+ ? `file:${escapeSystemdSpecifiers(this.paths.errorLog)}`
214
239
  : undefined,
215
- User: (_p = (_o = options.linux) === null || _o === void 0 ? void 0 : _o.Service) === null || _p === void 0 ? void 0 : _p.User,
216
- WorkingDirectory: this.cwd,
240
+ User: (_q = (_p = options.linux) === null || _p === void 0 ? void 0 : _p.Service) === null || _q === void 0 ? void 0 : _q.User,
241
+ WorkingDirectory: this.cwd ? escapeSystemdSpecifiers(this.cwd) : undefined,
217
242
  ExecStart: command,
218
243
  },
219
244
  Install: {
220
- WantedBy: (_r = (_q = options.linux) === null || _q === void 0 ? void 0 : _q.Install) === null || _r === void 0 ? void 0 : _r.WantedBy,
245
+ WantedBy: (_s = (_r = options.linux) === null || _r === void 0 ? void 0 : _r.Install) === null || _s === void 0 ? void 0 : _s.WantedBy,
221
246
  },
222
247
  });
223
- if (this.options.debugging) {
224
- console.log(`NODE-SERVICE DEBUG: Build service file from object:`);
225
- console.log(`NODE-SERVICE DEBUG: ${configObject}`);
226
- }
248
+ this.debug(`Build service file from object:`);
249
+ this.debug(JSON.stringify(configObject, null, 2));
227
250
  let configString = ``;
228
251
  for (const attr of Object.keys(configObject)) {
229
252
  configString += `\n[${attr}]\n`;
@@ -231,7 +254,7 @@ class LinuxServiceManager extends os_service_manager_1.OSServiceManager {
231
254
  configString += `${key}=${configObject[attr][key]}\n`;
232
255
  if (key === 'ExecStart' && options.env) {
233
256
  for (const envKey of Object.keys(options.env)) {
234
- configString += `Environment='${envKey}=${options.env[envKey]}'\n`;
257
+ configString += `${buildSystemdEnvironment(envKey, options.env[envKey])}\n`;
235
258
  }
236
259
  }
237
260
  }
@@ -1 +1 @@
1
- {"version":3,"file":"linux-service-manager.js","sourceRoot":"","sources":["../../../../node-service/src/lib/linux-service-manager.ts"],"names":[],"mappings":";;;;AAAA,6DAK8B;AAC9B,2CAA0E;AAC1E,+BAA4B;AAC5B,2BAA6B;AAC7B,kCAAkC;AAClC,0CAA+C;AAE/C,MAAa,mBAAoB,SAAQ,qCAAgB;IAAzD;;QACU,UAAK,GAMT,EAAE,CAAC;IAwST,CAAC;IAnSC,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,OAAQ,CAAC,IAAI,CAAC;IAC5B,CAAC;IAEc,UAAU,CAAC,OAAyB;;;;;YACjD,MAAM,OAAM,UAAU,YAAC,OAAO,CAAC,CAAC;YAChC,IAAI,CAAC,QAAQ,EAAE,CAAC;YAChB,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;YAC5B,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QAC5B,CAAC;KAAA;IAEK,OAAO,CACX,OAAe,EACf,WAAqB,EACrB,OAAqC;;;YAErC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACrC,IAAI,CAAC,GAAG,GAAG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AAC,EAAE,CAAC;wBACzC,MAAM,IAAA,oBAAS,EAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;wBAChE,MAAM,wBAAY,CAAC,GAAG,CAAC,aAAa,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;oBAC7D,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;KAAA;CACF;AA/SD,kDA+SC"}
1
+ {"version":3,"file":"linux-service-manager.js","sourceRoot":"","sources":["../../../../node-service/src/lib/linux-service-manager.ts"],"names":[],"mappings":";;;AAgBA,kDAgBC;AAKD,0DAEC;AAMD,kDAGC;AAED,sDAEC;AAKD,0DAGC;;AA5DD,6DAK8B;AAC9B,2CAAgJ;AAChJ,+BAA4B;AAC5B,2BAA6B;AAC7B,kCAAkC;AAClC,0CAA+C;AAE/C;;;GAGG;AACH,SAAgB,mBAAmB,CAAC,MAAc;;IAChD,MAAM,KAAK,GAAG,MAAA,iCAAiC,CAAC,IAAI,CAAC,MAAM,CAAC,0CAAG,CAAC,CAAC,CAAC;IAClE,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,QAAQ;YACX,OAAO,oCAAe,CAAC,OAAO,CAAC;QACjC,KAAK,UAAU;YACb,OAAO,oCAAe,CAAC,OAAO,CAAC;QACjC,KAAK,YAAY,CAAC;QAClB,KAAK,cAAc,CAAC;QACpB,KAAK,WAAW;YACd,OAAO,oCAAe,CAAC,OAAO,CAAC;QACjC,KAAK,QAAQ;YACX,OAAO,oCAAe,CAAC,MAAM,CAAC;QAChC;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAgB,uBAAuB,CAAC,KAAa;IACnD,OAAO,GAAG,KAAK,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACxC,CAAC;AAED;;;GAGG;AACH,SAAgB,mBAAmB,CAAC,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CAAC;oBACD,IAAI,CAAC,CAAC,MAAM,IAAA,kBAAM,EAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;wBACpC,MAAM,IAAA,oBAAS,EAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;wBAC3D,MAAM,wBAAY,CAAC,GAAG,CAAC,aAAa,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;oBACxD,CAAC;oBACD,IAAI,CAAC,CAAC,MAAM,IAAA,kBAAM,EAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;wBACzC,MAAM,IAAA,oBAAS,EAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;wBAChE,MAAM,wBAAY,CAAC,GAAG,CAAC,aAAa,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;oBAC7D,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;KAAA;CACF;AAzRD,kDAyRC"}
@@ -1,4 +1,9 @@
1
- import { OSServiceInstallationOptions, OSServiceManager, OSServiceOptions } from './os-service-manager';
1
+ import { OSServiceInstallationOptions, OSServiceManager, OSServiceOptions, OSServiceStatus } from './os-service-manager';
2
+ /**
3
+ * Maps the output of `launchctl print <domain>/<label>` to a service status.
4
+ * @returns undefined if the output contains no known state
5
+ */
6
+ export declare function parseLaunchctlState(output: string): OSServiceStatus | undefined;
2
7
  export declare class MacOSServiceManager extends OSServiceManager {
3
8
  private paths;
4
9
  private command?;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MacOSServiceManager = void 0;
4
+ exports.parseLaunchctlState = parseLaunchctlState;
4
5
  const tslib_1 = require("tslib");
5
6
  const os_service_manager_1 = require("./os-service-manager");
6
7
  const plist_1 = require("plist");
@@ -9,6 +10,25 @@ const path_1 = require("path");
9
10
  const os_1 = require("os");
10
11
  const Path = require("node:path");
11
12
  const promises_1 = require("fs/promises");
13
+ /**
14
+ * Maps the output of `launchctl print <domain>/<label>` to a service status.
15
+ * @returns undefined if the output contains no known state
16
+ */
17
+ function parseLaunchctlState(output) {
18
+ var _a, _b;
19
+ const state = (_b = (_a = /state\s*=\s*([^\n]+)/.exec(output)) === null || _a === void 0 ? void 0 : _a[1]) === null || _b === void 0 ? void 0 : _b.trim();
20
+ switch (state) {
21
+ case 'running':
22
+ return os_service_manager_1.OSServiceStatus.running;
23
+ case 'not running':
24
+ return os_service_manager_1.OSServiceStatus.stopped;
25
+ case 'waiting':
26
+ case 'spawn scheduled':
27
+ return os_service_manager_1.OSServiceStatus.waiting;
28
+ default:
29
+ return undefined;
30
+ }
31
+ }
12
32
  class MacOSServiceManager extends os_service_manager_1.OSServiceManager {
13
33
  constructor() {
14
34
  super(...arguments);
@@ -38,34 +58,38 @@ class MacOSServiceManager extends os_service_manager_1.OSServiceManager {
38
58
  this._installationOptions = options;
39
59
  yield this.prepareLogging();
40
60
  if (yield this.isInstalled()) {
41
- throw new Error(`Node-Service Error: Can't install service. Service already exists. Unload it via launchctl unload or call manager.stop();`);
61
+ throw new Error(`Node-Service Error: Can't install service. Service already exists. Unload it via launchctl unload or call manager.uninstall();`);
42
62
  }
43
63
  const plist = this.buildPlist(options);
44
- if (this.options.level === 'system') {
45
- const logFolderCreation = ((_a = options.logging) === null || _a === void 0 ? void 0 : _a.enabled)
46
- ? `mkdir -p ${this.paths.logRoot} 2>/dev/null && chmod 745 ${this.paths.logRoot} && touch ${this.paths.log} 2>/dev/null && chmod 745 ${this.paths.log} && touch ${this.paths.errorLog} 2>/dev/null && chmod 745 ${this.paths.errorLog} && `
47
- : '';
48
- const script = `${logFolderCreation}printf '${plist
49
- .replace(/["']/g, '\\"')
50
- .replace(/\n/g, '\\n')}' > "/tmp/${this.options.slug}.plist" && mv -f "/tmp/${this.options.slug}.plist" /Library/LaunchDaemons/${this.options.slug}.plist && launchctl load -w "${this.paths.plist}"`;
51
- if (this.options.debugging) {
52
- console.log('NODE-SERVICE DEBUG: RUN AS ADMIN');
53
- console.log(`NODE-SERVICE DEBUG: ${script}"`);
64
+ // the plist is written as is and copied by the script - no shell escaping of its content
65
+ const plistFile = yield (0, functions_1.writeTempFile)(`${this.options.slug}.plist`, plist);
66
+ try {
67
+ const commands = [];
68
+ if (this.options.level === 'system') {
69
+ if ((_a = options.logging) === null || _a === void 0 ? void 0 : _a.enabled) {
70
+ commands.push(...(0, functions_1.buildLogFolderCommands)(this.paths.logRoot, this.paths.log, this.paths.errorLog));
71
+ }
72
+ // launchd only loads daemons owned by root:wheel
73
+ commands.push(`install -m 644 -o root -g wheel ${(0, functions_1.shellQuote)(plistFile.path)} ${(0, functions_1.shellQuote)(this.paths.plist)}`, `launchctl load -w ${(0, functions_1.shellQuote)(this.paths.plist)}`);
74
+ const script = commands.join(' && ');
75
+ this.debug('RUN AS ADMIN');
76
+ this.debug(script);
77
+ yield functions_1.ScriptRunner.runAsAdmin(script, {
78
+ name: this.options.name,
79
+ headless: this.options.headless,
80
+ });
54
81
  }
55
- yield functions_1.ScriptRunner.runAsAdmin(script, {
56
- name: this.options.name,
57
- headless: this.options.headless,
58
- });
59
- }
60
- else {
61
- const script = `echo "${plist
62
- .replace(/"/g, '\\"')
63
- .replace(/\n/g, '\\n')}" > "${this.paths.plist}" && launchctl load -w "${this.paths.plist}"`;
64
- if (this.options.debugging) {
65
- console.log('NODE-SERVICE DEBUG: RUN');
66
- console.log(`NODE-SERVICE DEBUG: ${script}`);
82
+ else {
83
+ yield (0, promises_1.mkdir)(this.paths.root, { recursive: true });
84
+ commands.push(`install -m 644 ${(0, functions_1.shellQuote)(plistFile.path)} ${(0, functions_1.shellQuote)(this.paths.plist)}`, `launchctl load -w ${(0, functions_1.shellQuote)(this.paths.plist)}`);
85
+ const script = commands.join(' && ');
86
+ this.debug('RUN');
87
+ this.debug(script);
88
+ yield functions_1.ScriptRunner.run(script);
67
89
  }
68
- yield functions_1.ScriptRunner.run(script);
90
+ }
91
+ finally {
92
+ yield plistFile.cleanup();
69
93
  }
70
94
  yield this.updateStatus();
71
95
  });
@@ -80,20 +104,16 @@ class MacOSServiceManager extends os_service_manager_1.OSServiceManager {
80
104
  start() {
81
105
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
82
106
  if (this.options.level === 'system') {
83
- if (this.options.debugging) {
84
- console.log('NODE-SERVICE DEBUG: RUN AS ADMIN');
85
- console.log(`NODE-SERVICE DEBUG: launchctl start "${this.options.slug}"`);
86
- }
107
+ this.debug('RUN AS ADMIN');
108
+ this.debug(`launchctl start "${this.options.slug}"`);
87
109
  yield functions_1.ScriptRunner.runAsAdmin(`launchctl start "${this.options.slug}"`, {
88
110
  name: this.options.name,
89
111
  headless: this.options.headless,
90
112
  });
91
113
  }
92
114
  else {
93
- if (this.options.debugging) {
94
- console.log('NODE-SERVICE DEBUG: RUN');
95
- console.log(`NODE-SERVICE DEBUG: launchctl start "${this.options.slug}"`);
96
- }
115
+ this.debug('RUN');
116
+ this.debug(`launchctl start "${this.options.slug}"`);
97
117
  yield functions_1.ScriptRunner.run(`launchctl start "${this.options.slug}"`);
98
118
  }
99
119
  yield this.updateStatus();
@@ -101,52 +121,37 @@ class MacOSServiceManager extends os_service_manager_1.OSServiceManager {
101
121
  }
102
122
  updateStatus() {
103
123
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
104
- try {
105
- if (this.domain) {
106
- const output = yield functions_1.ScriptRunner.run(`launchctl print ${this.domain}/${this.label}`);
107
- const matches = /state\s*=\s*([^\n]+)/g.exec(output);
108
- if (matches && matches.length > 0) {
109
- switch (matches[1]) {
110
- case 'running':
111
- this._status = os_service_manager_1.OSServiceStatus.running;
112
- break;
113
- case 'not running':
114
- this._status = os_service_manager_1.OSServiceStatus.stopped;
115
- break;
116
- case 'waiting':
117
- this._status = os_service_manager_1.OSServiceStatus.waiting;
118
- break;
119
- }
120
- }
121
- }
124
+ if (!this.domain) {
125
+ return;
122
126
  }
123
- catch (e) {
124
- if (/Could not find service/g.exec(e)) {
125
- this._status = os_service_manager_1.OSServiceStatus.not_installed;
126
- }
127
- else {
128
- throw new Error(e);
129
- }
127
+ const command = `launchctl print ${this.domain}/${this.label}`;
128
+ // launchctl exits with 113 if the service doesn't exist
129
+ const result = yield functions_1.ScriptRunner.exec(command);
130
+ const status = parseLaunchctlState(result.stdout);
131
+ if (status) {
132
+ this._status = status;
133
+ }
134
+ else if (/Could not find service/.test(`${result.stdout}\n${result.stderr}`)) {
135
+ this._status = os_service_manager_1.OSServiceStatus.not_installed;
136
+ }
137
+ else if (result.code !== 0) {
138
+ throw new functions_1.ScriptRunnerError(command, result.code, result.stdout, result.stderr);
130
139
  }
131
140
  });
132
141
  }
133
142
  stop() {
134
143
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
135
144
  if (this.options.level === 'system') {
136
- if (this.options.debugging) {
137
- console.log('NODE-SERVICE DEBUG: RUN AS ADMIN');
138
- console.log(`NODE-SERVICE DEBUG: launchctl stop "${this.options.slug}"`);
139
- }
145
+ this.debug('RUN AS ADMIN');
146
+ this.debug(`launchctl stop "${this.options.slug}"`);
140
147
  yield functions_1.ScriptRunner.runAsAdmin(`launchctl stop '${this.options.slug}'`, {
141
148
  name: this.options.name,
142
149
  headless: this.options.headless,
143
150
  });
144
151
  }
145
152
  else {
146
- if (this.options.debugging) {
147
- console.log('NODE-SERVICE DEBUG: RUN');
148
- console.log(`NODE-SERVICE DEBUG: launchctl stop "${this.options.slug}"`);
149
- }
153
+ this.debug('RUN');
154
+ this.debug(`launchctl stop "${this.options.slug}"`);
150
155
  yield functions_1.ScriptRunner.run(`launchctl stop '${this.options.slug}'`);
151
156
  }
152
157
  yield this.updateStatus();
@@ -162,20 +167,16 @@ class MacOSServiceManager extends os_service_manager_1.OSServiceManager {
162
167
  removeScript += ` '${this.paths.logRoot}'`;
163
168
  }
164
169
  if (this.options.level === 'system') {
165
- if (this.options.debugging) {
166
- console.log('NODE-SERVICE DEBUG: RUN AS ADMIN');
167
- console.log(`NODE-SERVICE DEBUG: ${removeScript}`);
168
- }
170
+ this.debug('RUN AS ADMIN');
171
+ this.debug(removeScript);
169
172
  yield functions_1.ScriptRunner.runAsAdmin(removeScript, {
170
173
  name: `Uninstallation of ${this.options.name}`,
171
174
  headless: this.options.headless,
172
175
  });
173
176
  }
174
177
  else {
175
- if (this.options.debugging) {
176
- console.log('NODE-SERVICE DEBUG: RUN');
177
- console.log(`NODE-SERVICE DEBUG: ${removeScript}`);
178
- }
178
+ this.debug('RUN');
179
+ this.debug(removeScript);
179
180
  yield functions_1.ScriptRunner.run(removeScript);
180
181
  }
181
182
  yield this.updateStatus();
@@ -198,10 +199,8 @@ class MacOSServiceManager extends os_service_manager_1.OSServiceManager {
198
199
  if (options.env) {
199
200
  plistValue = Object.assign(Object.assign({}, plistValue), { EnvironmentVariables: options.env });
200
201
  }
201
- if (this.options.debugging) {
202
- console.log('NODE-SERVICE DEBUG: CREATE MACOS PLIST FROM OBJECT:');
203
- console.log(plistValue);
204
- }
202
+ this.debug('CREATE MACOS PLIST FROM OBJECT:');
203
+ this.debug(plistValue);
205
204
  return (0, plist_1.build)((0, functions_1.removeEmptyProperties)(plistValue));
206
205
  }
207
206
  setPaths() {
@@ -247,10 +246,8 @@ class MacOSServiceManager extends os_service_manager_1.OSServiceManager {
247
246
  encoding: 'utf-8',
248
247
  });
249
248
  const plist = (0, plist_1.parse)(plistContent);
250
- if (this.options.debugging) {
251
- console.log('NODE-SERVICE DEBUG: Parse Plist');
252
- console.log(plist);
253
- }
249
+ this.debug('Parse Plist');
250
+ this.debug(plist);
254
251
  this.cwd = plist['WorkingDirectory'];
255
252
  this.paths.log = plist['StandardOutPath'];
256
253
  this.paths.errorLog = plist['StandardErrorPath'];