@julianpoemp/node-service 1.1.0 → 1.2.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,24 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [1.2.1](https://github.com/julianpoemp/node-service/compare/node-service-1.2.0...node-service-1.2.1) (2026-11-16)
6
+
7
+ ### Bug Fixes
8
+
9
+ * **node-service:** don't run servy-cli without admin privileges ([4776f56](https://github.com/julianpoemp/node-service/commit/4776f56c12a62eb37d7f1a744fce5600def74943))
10
+
11
+ # [1.2.0](https://github.com/julianpoemp/node-service/compare/node-service-1.1.0...node-service-1.2.0) (2026-11-16)
12
+
13
+ ### Bug Fixes
14
+
15
+ * **node-service:** quote ExecStart and Environment in linux unit files ([f912a9d](https://github.com/julianpoemp/node-service/commit/f912a9d45d05b25491415985bc938af684ec5a51))
16
+ * **node-service:** reliable service status without process.exit ([09a2c74](https://github.com/julianpoemp/node-service/commit/09a2c74249a9f6ad639766bffa3fe5e41ab5d612))
17
+ * **node-service:** write service files directly instead of printf ([52586b0](https://github.com/julianpoemp/node-service/commit/52586b0f5420779811f1a90d6a18abff3fa4769a))
18
+
19
+ ### Features
20
+
21
+ * **node-service:** logger option for debug output ([adfb10f](https://github.com/julianpoemp/node-service/commit/adfb10fcf16fac60b1424c094273e88ec054a473))
22
+
5
23
  # [1.1.0](https://github.com/julianpoemp/node-service/compare/node-service-1.0.1...node-service-1.1.0) (2026-08-03)
6
24
 
7
25
  ### Features
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  <h1>node-service <a href="https://www.npmjs.com/package/@julianpoemp/node-service?activeTab=readme"><img alt="NPM Version" src="https://img.shields.io/npm/v/@julianpoemp/node-service"></a></h1>
2
2
 
3
- This NodeJS library allows to easily install and control OS background services on Windows, MacOS and Linux using shell commands. Uses [sudo-prompt](https://github.com/jorangreef/sudo-prompt) to request on desktop and "sudo" only on headless servers.
3
+ This NodeJS library allows to easily install and control OS background services on Windows, MacOS and Linux using shell commands. Uses [@vscode/sudo-prompt](https://github.com/microsoft/vscode-sudo-prompt) to request admin privileges on desktop and "sudo" only on headless servers.
4
4
 
5
5
  ## Goal
6
6
  The goal of this repository is to simplify the creation and management of OS services using NodeJS.
@@ -9,7 +9,8 @@ The goal of this repository is to simplify the creation and management of OS ser
9
9
 
10
10
  - One configuration for all OS services: Windows, MacOS, Linux
11
11
  - Supported functions: installation/uninstallation, start, stop, status
12
- - Supported scopes: "system" (user asked for admin privileges) or "user"
12
+ - Supported scopes: "system" (user asked for admin privileges) or "user" (macOS, Linux)
13
+ - Status queries without admin privileges
13
14
  - Option "headless" for headless servers (Linux, MacOS only)
14
15
  - TS typings
15
16
  - Async functions
@@ -20,15 +21,46 @@ This project is in an early development stage. There may be bugs or missing feat
20
21
 
21
22
  ## Requirements
22
23
 
23
- - Windows: If you plan to use this library for windows, make sure that winsw is installed on the user's machine. You can add a winsw.exe binary to your application and define the path to that file in the options.
24
+ - Windows: [servy-cli](https://servy-win.github.io/) v8 or newer. Add servy-cli.exe to %PATH% or set the path in
25
+ `options.windows.pathToServyCliExe`. servy-cli is only needed to install, uninstall, start and stop a service - the
26
+ status is read via `sc.exe`. servy-cli needs administrator privileges for every call, node-service only checks that
27
+ it exists and runs it in the elevated scripts.
24
28
  - MacOS: Make sure, that the plist package is installed: `npm install plist`
25
29
 
30
+ ## Windows notes
31
+
32
+ - servy only supports system services: the level `user` is installed as system service, all commands except the status
33
+ query need admin privileges (UAC prompt).
34
+ - The status is read via `sc.exe query` (works without admin privileges and independent of the system language).
35
+ - Environment variables (`env`) are escaped for servy: `=`, `;`, `"` and `\` are prefixed with a backslash, so Windows
36
+ paths and named pipes (`\\.\pipe\name`) arrive unchanged in the service.
37
+
38
+ ## Debugging
39
+
40
+ With `debugging: true` the commands and generated service files are logged. Set `logger` to pass the output to your own
41
+ logging instead of `console.log`:
42
+
43
+ ```typescript
44
+ const manager = await initializeOSService({
45
+ name: 'Hello World Service Example',
46
+ slug: 'hello-world',
47
+ level: 'user',
48
+ debugging: true,
49
+ logger: (message, ...params) => myLogger.debug(message, ...params),
50
+ });
51
+ ```
52
+
53
+ ## Errors
54
+
55
+ Failing commands reject with a `ScriptRunnerError` (`Error` with `code`, `stdout` and `stderr`). Status queries don't
56
+ throw if a service doesn't exist, the status is `not_installed` then.
57
+
26
58
  ## Installation
27
59
 
28
- Make sure that sudo-prompt is installed:
60
+ Make sure that @vscode/sudo-prompt is installed (peer dependency):
29
61
 
30
62
  ```shell
31
- npm install sudo-prompt
63
+ npm install @vscode/sudo-prompt
32
64
  ```
33
65
 
34
66
  ```shell
@@ -44,7 +76,7 @@ On macOS targets "plist" is needed:
44
76
  ## Example
45
77
 
46
78
  ````javascript
47
- import {initializeOSService} from 'node-service';
79
+ import {initializeOSService} from '@julianpoemp/node-service';
48
80
  import {join, resolve} from 'path';
49
81
 
50
82
  async function wait(seconds: number) {
@@ -61,7 +93,7 @@ async function main() {
61
93
  level: 'system',
62
94
  slug: 'hello-world',
63
95
  windows: {
64
- pathToWinswConfig: resolve(join("data", "winsw.xml"))
96
+ pathToServyCliExe: resolve(join("bin", "servy-cli.exe"))
65
97
  }
66
98
  });
67
99
 
package/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "@julianpoemp/node-service",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "peerDependencies": {
5
5
  "@vscode/sudo-prompt": "^9.3.2"
6
6
  },
7
+ "dependencies": {
8
+ "plist": "^3.1.0",
9
+ "tslib": "^2.3.0"
10
+ },
7
11
  "description": "This NodeJS library allows to easily install and control OS services on Windows, MacOS and Linux using shell commands. Uses sudo-prompt if admin privileges are needed.",
8
12
  "private": false,
9
13
  "author": "Julian Poemp",
@@ -16,6 +16,22 @@ export declare class ScriptRunnerOptions {
16
16
  catchError: (data: string) => void;
17
17
  constructor(partial?: Partial<ScriptRunnerOptions>);
18
18
  }
19
+ /**
20
+ * Error of a failed command. Contains the exit code and the complete output, the message contains stderr (or stdout if
21
+ * stderr is empty) so that string matches like `/could not be found/` keep working on `${error}`.
22
+ */
23
+ export declare class ScriptRunnerError extends Error {
24
+ readonly command: string;
25
+ readonly code: number | null;
26
+ readonly stdout: string;
27
+ readonly stderr: string;
28
+ constructor(command: string, code: number | null, stdout: string, stderr: string, message?: string);
29
+ }
30
+ export interface ScriptRunnerResult {
31
+ code: number | null;
32
+ stdout: string;
33
+ stderr: string;
34
+ }
19
35
  export declare class ScriptRunner {
20
36
  static runAsAdmin(command: string, options: {
21
37
  name?: string;
@@ -25,6 +41,31 @@ export declare class ScriptRunner {
25
41
  [key: string]: string;
26
42
  };
27
43
  }): Promise<any>;
44
+ /**
45
+ * Runs a command and resolves with stdout. Rejects with a ScriptRunnerError if the command exits with a code != 0.
46
+ */
28
47
  static run(scriptPath: string, options?: Partial<ScriptRunnerOptions>, processCreatedCallback?: (process: ChildProcess) => void): Promise<string>;
48
+ /**
49
+ * Runs a command and resolves with exit code, stdout and stderr - also if the exit code is != 0. Used for status
50
+ * queries whose tools report states via exit codes (e.g. `systemctl status` exits with 3 for inactive services).
51
+ * Rejects only if the command can't be started.
52
+ */
53
+ static exec(scriptPath: string, options?: Partial<ScriptRunnerOptions>, processCreatedCallback?: (process: ChildProcess) => void): Promise<ScriptRunnerResult>;
29
54
  }
30
55
  export declare function exists(path: string): Promise<boolean>;
56
+ /**
57
+ * Quotes a value for POSIX shells (single quotes, embedded single quotes escaped).
58
+ */
59
+ export declare function shellQuote(value: string): string;
60
+ /**
61
+ * Writes content to a file in a new temporary folder. Service files are written this way and moved to their target
62
+ * by the (privileged) install script - no escaping of the file content in shell commands needed.
63
+ */
64
+ export declare function writeTempFile(fileName: string, content: string): Promise<{
65
+ path: string;
66
+ cleanup: () => Promise<void>;
67
+ }>;
68
+ /**
69
+ * Shell commands that create the log folder and files (readable for the service).
70
+ */
71
+ export declare function buildLogFolderCommands(logRoot: string, log: string, errorLog: string): string[];
@@ -1,13 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ScriptRunner = exports.ScriptRunnerOptions = void 0;
3
+ exports.ScriptRunner = exports.ScriptRunnerError = exports.ScriptRunnerOptions = void 0;
4
4
  exports.removeEmptyProperties = removeEmptyProperties;
5
5
  exports.exists = exists;
6
+ exports.shellQuote = shellQuote;
7
+ exports.writeTempFile = writeTempFile;
8
+ exports.buildLogFolderCommands = buildLogFolderCommands;
6
9
  const tslib_1 = require("tslib");
7
10
  const child_process_1 = require("child_process");
8
11
  const SudoPrompt = require("@vscode/sudo-prompt");
9
12
  const fs = require("fs");
13
+ const promises_1 = require("node:fs/promises");
10
14
  const os = require("node:os");
15
+ const node_path_1 = require("node:path");
11
16
  /**
12
17
  * removes all empty values from an given object.
13
18
  * @param obj
@@ -64,77 +69,107 @@ class ScriptRunnerOptions {
64
69
  }
65
70
  }
66
71
  exports.ScriptRunnerOptions = ScriptRunnerOptions;
72
+ /**
73
+ * Error of a failed command. Contains the exit code and the complete output, the message contains stderr (or stdout if
74
+ * stderr is empty) so that string matches like `/could not be found/` keep working on `${error}`.
75
+ */
76
+ class ScriptRunnerError extends Error {
77
+ constructor(command, code, stdout, stderr, message) {
78
+ super(message !== null && message !== void 0 ? message : `Command failed with exit code ${code}: ${command}\n${stderr.trim() !== '' ? stderr : stdout}`);
79
+ this.command = command;
80
+ this.code = code;
81
+ this.stdout = stdout;
82
+ this.stderr = stderr;
83
+ this.name = 'ScriptRunnerError';
84
+ }
85
+ }
86
+ exports.ScriptRunnerError = ScriptRunnerError;
67
87
  class ScriptRunner {
68
88
  static runAsAdmin(command, options) {
69
89
  if (os.platform() === 'win32') {
70
90
  options = Object.assign(Object.assign({}, (options !== null && options !== void 0 ? options : {})), { headless: false });
71
91
  }
72
92
  if (options === null || options === void 0 ? void 0 : options.headless) {
73
- return ScriptRunner.run(`sudo -- sh -c '${command.replace(/'/g, '"')}'`, options);
93
+ return ScriptRunner.run(`sudo -- sh -c ${shellQuote(command)}`, options);
74
94
  }
75
95
  else {
76
96
  return new Promise((resolve, reject) => {
77
97
  SudoPrompt.exec(command, options, (error, stdout, stderr) => {
78
- if (error)
79
- reject(stderr !== null && stderr !== void 0 ? stderr : error);
80
- else
98
+ var _a;
99
+ if (error) {
100
+ // stderr is usually an empty string (e.g. if the user cancelled the prompt) - keep the error message
101
+ const stderrString = `${stderr !== null && stderr !== void 0 ? stderr : ''}`;
102
+ reject(new ScriptRunnerError(command, (_a = error.code) !== null && _a !== void 0 ? _a : null, `${stdout !== null && stdout !== void 0 ? stdout : ''}`, stderrString, `${error.message}${stderrString.trim() !== '' ? `\n${stderrString}` : ''}`));
103
+ }
104
+ else {
81
105
  resolve();
106
+ }
82
107
  });
83
108
  });
84
109
  }
85
110
  }
111
+ /**
112
+ * Runs a command and resolves with stdout. Rejects with a ScriptRunnerError if the command exits with a code != 0.
113
+ */
86
114
  static run(scriptPath_1) {
87
- return tslib_1.__awaiter(this, arguments, void 0, function* (scriptPath, options = new ScriptRunnerOptions(), processCreatedCallback = (process) => { }) {
88
- return new Promise((resolve, reject) => {
89
- options = new ScriptRunnerOptions(options);
90
- let output = '';
91
- let error = '';
92
- const childProcess = (0, child_process_1.exec)(scriptPath, {
93
- env: Object.assign(Object.assign({}, process.env), options.env),
94
- });
95
- let pipeLine;
96
- if (childProcess) {
97
- processCreatedCallback(childProcess);
98
- childProcess.stdin.on('data', (data) => { }); // hack to allow inputs to child
99
- childProcess.stdout.on('data', (data) => {
100
- output += data;
101
- if (options.showOutput) {
102
- options.catchOutput(data);
103
- }
104
- });
105
- childProcess.stdout.on('error', (data) => {
106
- error += data;
107
- if (options.showOutput) {
108
- options.catchError(data.message);
109
- }
110
- });
111
- childProcess.stderr.on('data', (data) => {
112
- error += data;
113
- if (options.showOutput) {
114
- options.catchError(data);
115
- }
116
- });
117
- // what to do when the command is done
118
- childProcess.on('close', (code) => {
119
- if (pipeLine) {
120
- pipeLine.destroy();
121
- }
122
- if (code !== null && code !== 0 && error !== '') {
123
- reject(error);
124
- }
125
- else {
126
- resolve(output);
127
- }
128
- });
129
- childProcess.stdin.on('data', (data) => { }); // hack to allow inputs to child
115
+ return tslib_1.__awaiter(this, arguments, void 0, function* (scriptPath, options = new ScriptRunnerOptions(), processCreatedCallback = () => {
116
+ // nothing
117
+ }) {
118
+ const result = yield ScriptRunner.exec(scriptPath, options, processCreatedCallback);
119
+ if (result.code !== null && result.code !== 0) {
120
+ throw new ScriptRunnerError(scriptPath, result.code, result.stdout, result.stderr);
121
+ }
122
+ return result.stdout;
123
+ });
124
+ }
125
+ /**
126
+ * Runs a command and resolves with exit code, stdout and stderr - also if the exit code is != 0. Used for status
127
+ * queries whose tools report states via exit codes (e.g. `systemctl status` exits with 3 for inactive services).
128
+ * Rejects only if the command can't be started.
129
+ */
130
+ static exec(scriptPath, options = new ScriptRunnerOptions(), processCreatedCallback = () => {
131
+ // nothing
132
+ }) {
133
+ return new Promise((resolve, reject) => {
134
+ var _a, _b, _c, _d;
135
+ const runnerOptions = new ScriptRunnerOptions(options);
136
+ let stdout = '';
137
+ let stderr = '';
138
+ const childProcess = (0, child_process_1.exec)(scriptPath, {
139
+ env: Object.assign(Object.assign({}, process.env), runnerOptions.env),
140
+ });
141
+ if (!childProcess) {
142
+ reject(new ScriptRunnerError(scriptPath, null, '', '', `Can't run script: ${scriptPath}`));
143
+ return;
144
+ }
145
+ processCreatedCallback(childProcess);
146
+ (_a = childProcess.stdin) === null || _a === void 0 ? void 0 : _a.on('data', () => {
147
+ // allows inputs to child
148
+ });
149
+ (_b = childProcess.stdout) === null || _b === void 0 ? void 0 : _b.on('data', (data) => {
150
+ stdout += data;
151
+ if (runnerOptions.showOutput) {
152
+ runnerOptions.catchOutput(data);
130
153
  }
131
- else {
132
- if (pipeLine) {
133
- pipeLine.destroy();
134
- }
135
- reject("Can't run script.");
154
+ });
155
+ (_c = childProcess.stdout) === null || _c === void 0 ? void 0 : _c.on('error', (data) => {
156
+ stderr += data;
157
+ if (runnerOptions.showOutput) {
158
+ runnerOptions.catchError(data.message);
136
159
  }
137
160
  });
161
+ (_d = childProcess.stderr) === null || _d === void 0 ? void 0 : _d.on('data', (data) => {
162
+ stderr += data;
163
+ if (runnerOptions.showOutput) {
164
+ runnerOptions.catchError(data);
165
+ }
166
+ });
167
+ childProcess.on('error', (error) => {
168
+ reject(new ScriptRunnerError(scriptPath, null, stdout, stderr, `Can't run script ${scriptPath}: ${error.message}`));
169
+ });
170
+ childProcess.on('close', (code) => {
171
+ resolve({ code, stdout, stderr });
172
+ });
138
173
  });
139
174
  }
140
175
  }
@@ -151,4 +186,36 @@ function exists(path) {
151
186
  });
152
187
  });
153
188
  }
189
+ /**
190
+ * Quotes a value for POSIX shells (single quotes, embedded single quotes escaped).
191
+ */
192
+ function shellQuote(value) {
193
+ return `'${`${value}`.replace(/'/g, `'\\''`)}'`;
194
+ }
195
+ /**
196
+ * Writes content to a file in a new temporary folder. Service files are written this way and moved to their target
197
+ * by the (privileged) install script - no escaping of the file content in shell commands needed.
198
+ */
199
+ function writeTempFile(fileName, content) {
200
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
201
+ const folder = yield (0, promises_1.mkdtemp)((0, node_path_1.join)(os.tmpdir(), 'node-service-'));
202
+ const path = (0, node_path_1.join)(folder, fileName);
203
+ yield (0, promises_1.writeFile)(path, content, { encoding: 'utf-8', mode: 0o644 });
204
+ return {
205
+ path,
206
+ cleanup: () => (0, promises_1.rm)(folder, { recursive: true, force: true }),
207
+ };
208
+ });
209
+ }
210
+ /**
211
+ * Shell commands that create the log folder and files (readable for the service).
212
+ */
213
+ function buildLogFolderCommands(logRoot, log, errorLog) {
214
+ return [
215
+ `mkdir -p ${shellQuote(logRoot)}`,
216
+ `chmod 745 ${shellQuote(logRoot)}`,
217
+ `touch ${shellQuote(log)} ${shellQuote(errorLog)}`,
218
+ `chmod 745 ${shellQuote(log)} ${shellQuote(errorLog)}`,
219
+ ];
220
+ }
154
221
  //# sourceMappingURL=functions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../../node-service/src/lib/functions.ts"],"names":[],"mappings":";;;AAUA,sDA+CC;AAqHD,wBAOC;;AArLD,iDAAmD;AACnD,kDAAkD;AAClD,yBAAyB;AACzB,8BAA8B;AAE9B;;;;GAIG;AACH,SAAgB,qBAAqB,CACnC,GAAM,EACN,UAII;IACF,kBAAkB,EAAE,IAAI;IACxB,UAAU,EAAE,IAAI;IAChB,eAAe,EAAE,IAAI;CACtB;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACvB,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,CACzB,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,CAAC,OAAO,CAAC,eAAe,IAAI,CAAC,KAAK,SAAS,CAAC;YAC7C,CAAC,CAAC,OAAO,CAAC,UAAU,IAAI,CAAC,KAAK,IAAI,CAAC;YACnC,CAAC,CAAC,OAAO,CAAC,kBAAkB;gBAC1B,OAAO,CAAC,KAAK,QAAQ;gBACrB,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CACrB,CAAC;QACF,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,qBAAqB,CAAI,CAAC,EAAE,OAAO,CAAC,CAAM,CAAC;IACxE,CAAC;SAAM,CAAC;QACN,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YAC5B,MAAM,MAAM,GAAG,GAAU,CAAC;YAC1B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,CAAC;YAEvC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;gBACvB,IACE,CAAC,OAAO,CAAC,UAAU,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,CA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KAAK,KAAK,EAAE,EAAE,CAAC;4BAChD,MAAM,CAAC,KAAK,CAAC,CAAC;wBAChB,CAAC;6BAAM,CAAC;4BACN,OAAO,CAAC,MAAM,CAAC,CAAC;wBAClB,CAAC;oBACH,CAAC,CAAC,CAAC;oBACH,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,GAAE,CAAC,CAAC,CAAC,CAAC,gCAAgC;gBAC/E,CAAC;qBAAM,CAAC;oBACN,IAAI,QAAQ,EAAE,CAAC;wBACb,QAAQ,CAAC,OAAO,EAAE,CAAC;oBACrB,CAAC;oBACD,MAAM,CAAC,mBAAmB,CAAC,CAAC;gBAC9B,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;KAAA;CACF;AAhGD,oCAgGC;AAED,SAAsB,MAAM,CAAC,IAAY;;QACvC,OAAO,IAAI,OAAO,CAAU,CAAC,OAAO,EAAE,EAAE;YACtC,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE;gBACxB,IAAI,KAAK;oBAAE,OAAO,CAAC,KAAK,CAAC,CAAC;;oBACrB,OAAO,CAAC,IAAI,CAAC,CAAC;YACrB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CAAA"}
1
+ {"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../../node-service/src/lib/functions.ts"],"names":[],"mappings":";;;AAYA,sDA+CC;AAoLD,wBAOC;AAKD,gCAEC;AAMD,sCAWC;AAKD,wDAOC;;AA1RD,iDAAmD;AACnD,kDAAkD;AAClD,yBAAyB;AACzB,+CAA0D;AAC1D,8BAA8B;AAC9B,yCAAiC;AAEjC;;;;GAIG;AACH,SAAgB,qBAAqB,CACnC,GAAM,EACN,UAII;IACF,kBAAkB,EAAE,IAAI;IACxB,UAAU,EAAE,IAAI;IAChB,eAAe,EAAE,IAAI;CACtB;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,G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AAO,CAAC,EAAE;QACjC,aAAa,UAAU,CAAC,OAAO,CAAC,EAAE;QAClC,SAAS,UAAU,CAAC,GAAG,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE;QAClD,aAAa,UAAU,CAAC,GAAG,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE;KACvD,CAAC;AACJ,CAAC"}
@@ -1,4 +1,23 @@
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 `systemctl status <name>.service` to a service status.
4
+ * @returns undefined if the output contains no known state
5
+ */
6
+ export declare function parseSystemctlState(output: string): OSServiceStatus | undefined;
7
+ /**
8
+ * Escapes systemd specifiers (`%n`, `%h`, …) in a unit file value.
9
+ */
10
+ export declare function escapeSystemdSpecifiers(value: string): string;
11
+ /**
12
+ * Quotes one word of ExecStart: paths and arguments with spaces, quotes, backslashes, `%` or `$` stay one argument
13
+ * and arrive unchanged (systemd would otherwise expand specifiers and environment variables).
14
+ */
15
+ export declare function quoteSystemdExecArg(value: string): string;
16
+ export declare function buildSystemdExecStart(command: string, args: string[]): string;
17
+ /**
18
+ * `Environment="KEY=value"` with quotes, backslashes and specifiers escaped. Environment= doesn't expand `$`.
19
+ */
20
+ export declare function buildSystemdEnvironment(key: string, value: unknown): string;
2
21
  export declare class LinuxServiceManager extends OSServiceManager {
3
22
  private paths;
4
23
  private command?;