@julianpoemp/node-service 1.0.1 → 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.
- package/CHANGELOG.md +18 -0
- package/README.md +38 -7
- package/package.json +5 -1
- package/src/index.d.ts +0 -1
- package/src/index.js +0 -1
- package/src/index.js.map +1 -1
- package/src/lib/functions.d.ts +41 -0
- package/src/lib/functions.js +120 -56
- package/src/lib/functions.js.map +1 -1
- package/src/lib/linux-service-manager.d.ts +20 -1
- package/src/lib/linux-service-manager.js +141 -67
- package/src/lib/linux-service-manager.js.map +1 -1
- package/src/lib/macos-service-manager.d.ts +6 -1
- package/src/lib/macos-service-manager.js +114 -56
- package/src/lib/macos-service-manager.js.map +1 -1
- package/src/lib/os-service-manager.d.ts +12 -1
- package/src/lib/os-service-manager.js +11 -0
- package/src/lib/os-service-manager.js.map +1 -1
- package/src/lib/public-functions.js +1 -1
- package/src/lib/public-functions.js.map +1 -1
- package/src/lib/windows-service-manager.d.ts +23 -1
- package/src/lib/windows-service-manager.js +117 -46
- package/src/lib/windows-service-manager.js.map +1 -1
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.0](https://github.com/julianpoemp/node-service/compare/node-service-1.1.0...node-service-1.2.0) (2026-11-16)
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
* **node-service:** quote ExecStart and Environment in linux unit files ([f912a9d](https://github.com/julianpoemp/node-service/commit/f912a9d45d05b25491415985bc938af684ec5a51))
|
|
10
|
+
* **node-service:** reliable service status without process.exit ([09a2c74](https://github.com/julianpoemp/node-service/commit/09a2c74249a9f6ad639766bffa3fe5e41ab5d612))
|
|
11
|
+
* **node-service:** write service files directly instead of printf ([52586b0](https://github.com/julianpoemp/node-service/commit/52586b0f5420779811f1a90d6a18abff3fa4769a))
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* **node-service:** logger option for debug output ([adfb10f](https://github.com/julianpoemp/node-service/commit/adfb10fcf16fac60b1424c094273e88ec054a473))
|
|
16
|
+
|
|
17
|
+
# [1.1.0](https://github.com/julianpoemp/node-service/compare/node-service-1.0.1...node-service-1.1.0) (2026-08-03)
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
* **node-service:** extended debugging mode ([7b3dada](https://github.com/julianpoemp/node-service/commit/7b3dada6562340793359adebd5969fe89c127e16))
|
|
22
|
+
|
|
5
23
|
## [1.0.1](https://github.com/julianpoemp/node-service/compare/node-service-1.0.0...node-service-1.0.1) (2026-07-01)
|
|
6
24
|
|
|
7
25
|
|
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/
|
|
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,45 @@ This project is in an early development stage. There may be bugs or missing feat
|
|
|
20
21
|
|
|
21
22
|
## Requirements
|
|
22
23
|
|
|
23
|
-
- Windows:
|
|
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`.
|
|
24
27
|
- MacOS: Make sure, that the plist package is installed: `npm install plist`
|
|
25
28
|
|
|
29
|
+
## Windows notes
|
|
30
|
+
|
|
31
|
+
- servy only supports system services: the level `user` is installed as system service, all commands except the status
|
|
32
|
+
query need admin privileges (UAC prompt).
|
|
33
|
+
- The status is read via `sc.exe query` (works without admin privileges and independent of the system language).
|
|
34
|
+
- Environment variables (`env`) are escaped for servy: `=`, `;`, `"` and `\` are prefixed with a backslash, so Windows
|
|
35
|
+
paths and named pipes (`\\.\pipe\name`) arrive unchanged in the service.
|
|
36
|
+
|
|
37
|
+
## Debugging
|
|
38
|
+
|
|
39
|
+
With `debugging: true` the commands and generated service files are logged. Set `logger` to pass the output to your own
|
|
40
|
+
logging instead of `console.log`:
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
const manager = await initializeOSService({
|
|
44
|
+
name: 'Hello World Service Example',
|
|
45
|
+
slug: 'hello-world',
|
|
46
|
+
level: 'user',
|
|
47
|
+
debugging: true,
|
|
48
|
+
logger: (message, ...params) => myLogger.debug(message, ...params),
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Errors
|
|
53
|
+
|
|
54
|
+
Failing commands reject with a `ScriptRunnerError` (`Error` with `code`, `stdout` and `stderr`). Status queries don't
|
|
55
|
+
throw if a service doesn't exist, the status is `not_installed` then.
|
|
56
|
+
|
|
26
57
|
## Installation
|
|
27
58
|
|
|
28
|
-
Make sure that sudo-prompt is installed:
|
|
59
|
+
Make sure that @vscode/sudo-prompt is installed (peer dependency):
|
|
29
60
|
|
|
30
61
|
```shell
|
|
31
|
-
npm install sudo-prompt
|
|
62
|
+
npm install @vscode/sudo-prompt
|
|
32
63
|
```
|
|
33
64
|
|
|
34
65
|
```shell
|
|
@@ -44,7 +75,7 @@ On macOS targets "plist" is needed:
|
|
|
44
75
|
## Example
|
|
45
76
|
|
|
46
77
|
````javascript
|
|
47
|
-
import {initializeOSService} from 'node-service';
|
|
78
|
+
import {initializeOSService} from '@julianpoemp/node-service';
|
|
48
79
|
import {join, resolve} from 'path';
|
|
49
80
|
|
|
50
81
|
async function wait(seconds: number) {
|
|
@@ -61,7 +92,7 @@ async function main() {
|
|
|
61
92
|
level: 'system',
|
|
62
93
|
slug: 'hello-world',
|
|
63
94
|
windows: {
|
|
64
|
-
|
|
95
|
+
pathToServyCliExe: resolve(join("bin", "servy-cli.exe"))
|
|
65
96
|
}
|
|
66
97
|
});
|
|
67
98
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@julianpoemp/node-service",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
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",
|
package/src/index.d.ts
CHANGED
package/src/index.js
CHANGED
|
@@ -2,6 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./lib/os-service-manager"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./lib/macos-service-manager"), exports);
|
|
6
5
|
tslib_1.__exportStar(require("./lib/public-functions"), exports);
|
|
7
6
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../node-service/src/index.ts"],"names":[],"mappings":";;;AAAA,mEAAyC;AACzC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../node-service/src/index.ts"],"names":[],"mappings":";;;AAAA,mEAAyC;AACzC,iEAAuC"}
|
package/src/lib/functions.d.ts
CHANGED
|
@@ -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[];
|
package/src/lib/functions.js
CHANGED
|
@@ -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
|
|
@@ -16,7 +21,7 @@ const os = require("node:os");
|
|
|
16
21
|
function removeEmptyProperties(obj, options = {
|
|
17
22
|
removeEmptyStrings: true,
|
|
18
23
|
removeNull: true,
|
|
19
|
-
removeUndefined: true
|
|
24
|
+
removeUndefined: true,
|
|
20
25
|
}) {
|
|
21
26
|
if (Array.isArray(obj)) {
|
|
22
27
|
const filtered = obj.filter((a) => (!options.removeUndefined || a !== undefined) &&
|
|
@@ -64,80 +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
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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 = (
|
|
115
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* (scriptPath, options = new ScriptRunnerOptions(), processCreatedCallback = () => {
|
|
116
|
+
// nothing
|
|
88
117
|
}) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (code !== null && code !== 0 && error !== '') {
|
|
125
|
-
reject(error);
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
resolve(output);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
childProcess.stdin.on('data', (data) => {
|
|
132
|
-
}); // hack to allow inputs to child
|
|
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);
|
|
133
153
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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);
|
|
139
159
|
}
|
|
140
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
|
+
});
|
|
141
173
|
});
|
|
142
174
|
}
|
|
143
175
|
}
|
|
@@ -154,4 +186,36 @@ function exists(path) {
|
|
|
154
186
|
});
|
|
155
187
|
});
|
|
156
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
|
+
}
|
|
157
221
|
//# sourceMappingURL=functions.js.map
|
package/src/lib/functions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../../node-service/src/lib/functions.ts"],"names":[],"mappings":";;;
|
|
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CAAC;QACpC,MAAM,IAAA,oBAAS,EAAC,IAAI,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QACnE,OAAO;YACL,IAAI;YACJ,OAAO,EAAE,GAAG,EAAE,CAAC,IAAA,aAAE,EAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;SAC5D,CAAC;IACJ,CAAC;CAAA;AAED;;GAEG;AACH,SAAgB,sBAAsB,CAAC,OAAe,EAAE,GAAW,EAAE,QAAgB;IACnF,OAAO;QACL,YAAY,UAAU,CAAC,OAAO,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?;
|