@julianpoemp/node-service 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,47 @@
1
+ # Changelog
2
+
3
+ This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
+
5
+ ## [0.1.1](https://github.com/julianpoemp/node-service/compare/node-service-0.1.0...node-service-0.1.1) (2024-07-30)
6
+
7
+
8
+
9
+ # [0.1.0](https://github.com/julianpoemp/node-service/compare/node-service-0.0.1...node-service-0.1.0) (2024-07-30)
10
+
11
+
12
+
13
+ ## 0.0.1 (2024-07-30)
14
+
15
+
16
+ ### Bug Fixes
17
+
18
+ * **node-service:** can't install macos service under LaunchDaemons ([35d2b11](https://github.com/julianpoemp/node-service/commit/35d2b11a5d9626f38a29f05c7a0c4e962da8485f))
19
+ * **node-service:** uninstallation on windows not working ([fa9d754](https://github.com/julianpoemp/node-service/commit/fa9d75403a75f3f491940ab4d203a7aa39c21fa6))
20
+
21
+
22
+ ### Features
23
+
24
+ * **node-service:** macos service manager can now install user or system services ([acf19a5](https://github.com/julianpoemp/node-service/commit/acf19a57037831e8a8fa5bea7d0fb9eef815b728))
25
+ * **node-service:** os service management on macos ([651def8](https://github.com/julianpoemp/node-service/commit/651def8dcc11732849ee346a15b7113cebebddad))
26
+ * **node-service:** service manager implementation for linux ([8f406c1](https://github.com/julianpoemp/node-service/commit/8f406c14858de3498445529a4638d7ef35a61cf4))
27
+ * **node-windows:** implementation for windows ([fbb35d1](https://github.com/julianpoemp/node-service/commit/fbb35d19d0b142a013fc1ee0150f4446dc7ef288))
28
+ * **node-windows:** re-implementation for windows using winsw ([99ece41](https://github.com/julianpoemp/node-service/commit/99ece4153b779f404396af2286706cd1d846945b))
29
+
30
+
31
+
32
+ # 0.1.0 (2024-07-30)
33
+
34
+
35
+ ### Bug Fixes
36
+
37
+ * **node-service:** can't install macos service under LaunchDaemons ([35d2b11](https://github.com/julianpoemp/node-service/commit/35d2b11a5d9626f38a29f05c7a0c4e962da8485f))
38
+ * **node-service:** uninstallation on windows not working ([fa9d754](https://github.com/julianpoemp/node-service/commit/fa9d75403a75f3f491940ab4d203a7aa39c21fa6))
39
+
40
+
41
+ ### Features
42
+
43
+ * **node-service:** macos service manager can now install user or system services ([acf19a5](https://github.com/julianpoemp/node-service/commit/acf19a57037831e8a8fa5bea7d0fb9eef815b728))
44
+ * **node-service:** os service management on macos ([651def8](https://github.com/julianpoemp/node-service/commit/651def8dcc11732849ee346a15b7113cebebddad))
45
+ * **node-service:** service manager implementation for linux ([8f406c1](https://github.com/julianpoemp/node-service/commit/8f406c14858de3498445529a4638d7ef35a61cf4))
46
+ * **node-windows:** implementation for windows ([fbb35d1](https://github.com/julianpoemp/node-service/commit/fbb35d19d0b142a013fc1ee0150f4446dc7ef288))
47
+ * **node-windows:** re-implementation for windows using winsw ([99ece41](https://github.com/julianpoemp/node-service/commit/99ece4153b779f404396af2286706cd1d846945b))
package/README.md ADDED
@@ -0,0 +1,139 @@
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
+
3
+ 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.
4
+
5
+ ## Goal
6
+ The goal of this repository is to simplify the creation and management of OS services using NodeJS.
7
+
8
+ ## Features
9
+
10
+ - One configuration for all OS services: Windows, MacOS, Linux
11
+ - Supported functions: installation/uninstallation, start, stop, status
12
+ - Supported scopes: "system" (user asked for admin privileges) or "user"
13
+ - TS typings
14
+ - Async functions
15
+
16
+ ## Disclaimer
17
+
18
+ This project is in an early development stage. There may be bugs or missing features. Currently this package doesn't parse existing service config files (e.g. on Linux).
19
+
20
+ ## Remarks
21
+
22
+ - 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.
23
+ - MacOS: Make sure, that the plist package is installed: `npm install plist`
24
+
25
+ ## Installation
26
+
27
+ Make sure that sudo-prompt is installed:
28
+
29
+ ```shell
30
+ npm install sudo-prompt
31
+ ```
32
+
33
+ ```shell
34
+ npm install @julianpoemp/node-service
35
+ ```
36
+
37
+ On macOS targets "plist" is needed:
38
+
39
+ ```shell
40
+ npm install plist
41
+ ```
42
+
43
+ ## Example
44
+
45
+ ````javascript
46
+ import {initializeOSService} from 'node-service';
47
+ import {join, resolve} from 'path';
48
+
49
+ async function wait(seconds: number) {
50
+ return new Promise((resolve) => {
51
+ setTimeout(() => {
52
+ resolve();
53
+ }, 1000 * seconds)
54
+ });
55
+ }
56
+
57
+ async function main() {
58
+ const manager = await initializeOSService({
59
+ name: 'Hello World Service Example',
60
+ level: 'system',
61
+ slug: 'hello-world',
62
+ windows: {
63
+ pathToWinswConfig: resolve(join("data", "winsw.xml"))
64
+ }
65
+ });
66
+
67
+ console.log("UNINSTALL!");
68
+ await manager.uninstall();
69
+
70
+ if (manager.status === 'not_installed') {
71
+ console.log('Install...');
72
+ const args: string[] = [
73
+ "node"
74
+ ];
75
+
76
+ await manager.install(resolve(join("demo", "src", "assets", "hello-world.js")), args, {
77
+ description: "This service just prints 'Hello world' every second.",
78
+ logging: {
79
+ enabled: true
80
+ },
81
+ linux: {
82
+ Unit: {
83
+ After: "network.target",
84
+ StartLimitIntervalSync: 0
85
+ },
86
+ Service: {
87
+ Type: "simple",
88
+ Restart: "always",
89
+ RestartSec: 5
90
+ },
91
+ Install: {
92
+ WantedBy: "multi-user.target"
93
+ }
94
+ }
95
+ });
96
+ console.log('installed!');
97
+ await manager.start();
98
+ }
99
+
100
+ while (true) {
101
+ console.log(`STATUS: ${manager.status}`);
102
+ await manager.updateStatus();
103
+ await wait(1);
104
+ console.log(`STATUS: ${manager.status}`);
105
+ await manager.updateStatus();
106
+ await wait(1);
107
+ console.log(`STAsTUS: ${manager.status}`);
108
+ await manager.updateStatus();
109
+ await wait(1);
110
+ console.log(`STATUS: ${manager.status}`);
111
+ await manager.updateStatus();
112
+ await wait(1);
113
+ console.log(`STATUS: ${manager.status}`);
114
+ await manager.updateStatus();
115
+ await wait(1);
116
+ await manager.stop();
117
+ console.log(`STATUS: ${manager.status}`);
118
+ await manager.updateStatus();
119
+ await wait(1);
120
+ console.log(`STATUS: ${manager.status}`);
121
+ await manager.updateStatus();
122
+ await wait(1);
123
+ console.log(`STATUS: ${manager.status}`);
124
+ await manager.updateStatus();
125
+ await wait(1);
126
+ console.log(`STATUS: ${manager.status}`);
127
+ await manager.updateStatus();
128
+ await wait(1);
129
+ console.log(`STATUS: ${manager.status}`);
130
+ await manager.updateStatus();
131
+ await wait(1);
132
+ await manager.start();
133
+ }
134
+ }
135
+
136
+ main().catch((e)=>{
137
+ console.log(e?.message ?? e);
138
+ })
139
+ ````
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@julianpoemp/node-service",
3
+ "version": "0.1.1",
4
+ "peerDependencies": {
5
+ "sudo-prompt": "^9.2.1"
6
+ },
7
+ "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
+ "private": false,
9
+ "author": "Julian Poemp",
10
+ "license": "MIT",
11
+ "bugs": {
12
+ "url": "https://github.com/julianpoemp/node-service/issues"
13
+ },
14
+ "homepage": "https://github.com/julianpoemp/node-service",
15
+ "keywords": [
16
+ "nodejs",
17
+ "os-service",
18
+ "service",
19
+ "typescript",
20
+ "javascript"
21
+ ],
22
+ "main": "./src/index.js",
23
+ "type": "commonjs"
24
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './lib/os-service-manager';
2
+ export * from './lib/macos-service-manager';
3
+ export * from './lib/public-functions';
package/src/index.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./lib/os-service-manager"), exports);
5
+ tslib_1.__exportStar(require("./lib/macos-service-manager"), exports);
6
+ tslib_1.__exportStar(require("./lib/public-functions"), exports);
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../node-service/src/index.ts"],"names":[],"mappings":";;;AAAA,mEAAyC;AACzC,sEAA4C;AAC5C,iEAAuC"}
@@ -0,0 +1,29 @@
1
+ import { ChildProcess } from 'child_process';
2
+ /**
3
+ * removes all empty values from an given object.
4
+ * @param obj
5
+ * @param options
6
+ */
7
+ export declare function removeEmptyProperties<T>(obj: T, options?: {
8
+ removeEmptyStrings?: boolean;
9
+ removeNull?: boolean;
10
+ removeUndefined?: boolean;
11
+ }): T;
12
+ export declare class ScriptRunnerOptions {
13
+ showOutput: boolean;
14
+ env: any;
15
+ catchOutput: (data: string) => void;
16
+ catchError: (data: string) => void;
17
+ constructor(partial?: Partial<ScriptRunnerOptions>);
18
+ }
19
+ export declare class ScriptRunner {
20
+ static runAsAdmin(command: string, options: {
21
+ name?: string;
22
+ icns?: string;
23
+ env?: {
24
+ [key: string]: string;
25
+ };
26
+ }): Promise<any>;
27
+ static run(scriptPath: string, options?: Partial<ScriptRunnerOptions>, processCreatedCallback?: (process: ChildProcess) => void): Promise<string>;
28
+ }
29
+ export declare function exists(path: string): Promise<boolean>;
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ScriptRunner = exports.ScriptRunnerOptions = void 0;
4
+ exports.removeEmptyProperties = removeEmptyProperties;
5
+ exports.exists = exists;
6
+ const tslib_1 = require("tslib");
7
+ const child_process_1 = require("child_process");
8
+ const SudoPrompt = require("sudo-prompt");
9
+ const fs = require("fs");
10
+ /**
11
+ * removes all empty values from an given object.
12
+ * @param obj
13
+ * @param options
14
+ */
15
+ function removeEmptyProperties(obj, options = {
16
+ removeEmptyStrings: true,
17
+ removeNull: true,
18
+ removeUndefined: true
19
+ }) {
20
+ if (Array.isArray(obj)) {
21
+ const filtered = obj.filter((a) => (!options.removeUndefined || a !== undefined) &&
22
+ (!options.removeNull || a !== null) &&
23
+ (!options.removeEmptyStrings ||
24
+ typeof a !== 'string' ||
25
+ a.trim() !== ''));
26
+ return filtered.map((a) => removeEmptyProperties(a, options));
27
+ }
28
+ else {
29
+ if (typeof obj === 'object') {
30
+ const anyObj = obj;
31
+ const keys = Object.keys(anyObj !== null && anyObj !== void 0 ? anyObj : {});
32
+ for (const key of keys) {
33
+ if ((options.removeNull && anyObj[key] === null) ||
34
+ (options.removeUndefined && anyObj[key] === undefined) ||
35
+ (anyObj[key] !== undefined &&
36
+ anyObj[key] !== null &&
37
+ anyObj[key].toString() === 'NaN') ||
38
+ (options.removeEmptyStrings &&
39
+ typeof anyObj[key] === 'string' &&
40
+ anyObj[key].toString().trim() === '')) {
41
+ delete anyObj[key];
42
+ }
43
+ else if (typeof anyObj[key] === 'object') {
44
+ anyObj[key] = removeEmptyProperties(anyObj[key], options);
45
+ }
46
+ }
47
+ return anyObj;
48
+ }
49
+ }
50
+ return obj;
51
+ }
52
+ class ScriptRunnerOptions {
53
+ constructor(partial) {
54
+ this.showOutput = false;
55
+ this.env = {};
56
+ this.catchOutput = (data) => {
57
+ console.log(data);
58
+ };
59
+ this.catchError = (data) => {
60
+ process.stderr.write(data);
61
+ };
62
+ Object.assign(this, Object.assign({}, (partial !== null && partial !== void 0 ? partial : {})));
63
+ }
64
+ }
65
+ exports.ScriptRunnerOptions = ScriptRunnerOptions;
66
+ class ScriptRunner {
67
+ static runAsAdmin(command, options) {
68
+ return new Promise((resolve, reject) => {
69
+ SudoPrompt.exec(command, options, (error, stdout, stderr) => {
70
+ if (error)
71
+ reject(stderr !== null && stderr !== void 0 ? stderr : error);
72
+ else
73
+ resolve();
74
+ });
75
+ });
76
+ }
77
+ static run(scriptPath_1) {
78
+ return tslib_1.__awaiter(this, arguments, void 0, function* (scriptPath, options = new ScriptRunnerOptions(), processCreatedCallback = (process) => {
79
+ }) {
80
+ return new Promise((resolve, reject) => {
81
+ options = new ScriptRunnerOptions(options);
82
+ let output = '';
83
+ let error = '';
84
+ const childProcess = (0, child_process_1.exec)(scriptPath, {
85
+ env: Object.assign(Object.assign({}, process.env), options.env)
86
+ });
87
+ let pipeLine;
88
+ if (childProcess) {
89
+ processCreatedCallback(childProcess);
90
+ // redirect inputs from parent to child
91
+ process.stdin.pipe(childProcess.stdin).on('error', (err) => {
92
+ console.log(err);
93
+ });
94
+ childProcess.stdin.on('data', (data) => {
95
+ }); // hack to allow inputs to child
96
+ childProcess.stdout.on('data', (data) => {
97
+ output += data;
98
+ if (options.showOutput) {
99
+ options.catchOutput(data);
100
+ }
101
+ });
102
+ childProcess.stdout.on('error', (data) => {
103
+ error += data;
104
+ if (options.showOutput) {
105
+ options.catchError(data.message);
106
+ }
107
+ });
108
+ childProcess.stderr.on('data', (data) => {
109
+ error += data;
110
+ if (options.showOutput) {
111
+ options.catchError(data);
112
+ }
113
+ });
114
+ // what to do when the command is done
115
+ childProcess.on('close', (code) => {
116
+ if (pipeLine) {
117
+ pipeLine.destroy();
118
+ }
119
+ if (code !== null && code !== 0 && error !== '') {
120
+ reject(error);
121
+ }
122
+ else {
123
+ resolve(output);
124
+ }
125
+ });
126
+ // redirect inputs from parent to child
127
+ process.stdin.pipe(childProcess.stdin).on('error', (err) => {
128
+ console.log(err);
129
+ });
130
+ childProcess.stdin.on('data', (data) => {
131
+ }); // hack to allow inputs to child
132
+ }
133
+ else {
134
+ if (pipeLine) {
135
+ pipeLine.destroy();
136
+ }
137
+ reject('Can\'t run script.');
138
+ }
139
+ });
140
+ });
141
+ }
142
+ }
143
+ exports.ScriptRunner = ScriptRunner;
144
+ function exists(path) {
145
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
146
+ return new Promise((resolve) => {
147
+ fs.access(path, (error) => {
148
+ if (error)
149
+ resolve(false);
150
+ else
151
+ resolve(true);
152
+ });
153
+ });
154
+ });
155
+ }
156
+ //# sourceMappingURL=functions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../../node-service/src/lib/functions.ts"],"names":[],"mappings":";;;AASA,sDA+CC;AA4GD,wBAOC;;AA3KD,iDAAmD;AACnD,0CAA0C;AAC1C,yBAAyB;AAEzB;;;;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,CAAC;oBAC5C,CAAC,OAAO,CAAC,eAAe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AAC,KAAK,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;wBACzD,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;oBACnB,CAAC,CAAC,CAAC;oBACH,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;oBACvC,CAAC,CAAC,CAAC,CAAC,gCAAgC;gBACtC,CAAC;qBAAM,CAAC;oBACN,IAAI,QAAQ,EAAE,CAAC;wBACb,QAAQ,CAAC,OAAO,EAAE,CAAC;oBACrB,CAAC;oBACD,MAAM,CAAC,oBAAoB,CAAC,CAAC;gBAC/B,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;KAAA;CACF;AAvFD,oCAuFC;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"}
@@ -0,0 +1,18 @@
1
+ import { OSServiceInstallationOptions, OSServiceManager, OSServiceOptions } from './os-service-manager';
2
+ export declare class LinuxServiceManager extends OSServiceManager {
3
+ private paths;
4
+ private command?;
5
+ private commandArgs?;
6
+ private cwd?;
7
+ get label(): string;
8
+ initialize(options: OSServiceOptions): Promise<void>;
9
+ install(command: string, commandArgs: string[], options: OSServiceInstallationOptions): Promise<void>;
10
+ isInstalled(): Promise<boolean>;
11
+ start(): Promise<void>;
12
+ updateStatus(): Promise<void>;
13
+ stop(): Promise<void>;
14
+ uninstall(): Promise<void>;
15
+ private buildServiceFile;
16
+ private setPaths;
17
+ private prepareLogging;
18
+ }
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LinuxServiceManager = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const os_service_manager_1 = require("./os-service-manager");
6
+ const functions_1 = require("./functions");
7
+ const path_1 = require("path");
8
+ const os_1 = require("os");
9
+ const Path = require("node:path");
10
+ const promises_1 = require("fs/promises");
11
+ class LinuxServiceManager extends os_service_manager_1.OSServiceManager {
12
+ constructor() {
13
+ super(...arguments);
14
+ this.paths = {};
15
+ }
16
+ get label() {
17
+ return this.options.slug;
18
+ }
19
+ initialize(options) {
20
+ const _super = Object.create(null, {
21
+ initialize: { get: () => super.initialize }
22
+ });
23
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
24
+ yield _super.initialize.call(this, options);
25
+ this.setPaths();
26
+ yield this.prepareLogging();
27
+ yield this.updateStatus();
28
+ });
29
+ }
30
+ install(command, commandArgs, options) {
31
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
32
+ var _a;
33
+ this.command = Path.resolve(command);
34
+ this.cwd = options.cwd;
35
+ this.commandArgs = commandArgs;
36
+ this._installationOptions = options;
37
+ yield this.prepareLogging();
38
+ if (yield this.isInstalled()) {
39
+ throw new Error(`Can't install service. Service already exists. Unload it via launchctl unload or call manager.stop();`);
40
+ }
41
+ const configString = this.buildServiceFile(options);
42
+ if (!(yield (0, functions_1.exists)(this.paths.root))) {
43
+ yield (0, promises_1.mkdir)(this.paths.root, {
44
+ recursive: true
45
+ });
46
+ }
47
+ const userCommand = this.options.level === 'system' ? '' : ' --user';
48
+ const logFolderCreation = ((_a = options.logging) === null || _a === void 0 ? void 0 : _a.enabled) ? `&& 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} ` : '';
49
+ let script = `printf '${configString.replace(/'/g, '"').replace(/\n/g, '\\n')}' > "/tmp/${this.options.slug}.service" `;
50
+ script += `${logFolderCreation}`;
51
+ script += `&& mv -f "/tmp/${this.options.slug}.service" "${this.paths.config}" `;
52
+ script += `&& systemctl${userCommand} daemon-reload && `;
53
+ script += `systemctl${userCommand} enable ${this.options.slug}.service`;
54
+ if (this.options.level === 'system') {
55
+ yield functions_1.ScriptRunner.runAsAdmin(script, {
56
+ name: this.options.name,
57
+ icns: this.options.icns
58
+ });
59
+ }
60
+ else {
61
+ yield functions_1.ScriptRunner.run(script);
62
+ }
63
+ yield this.updateStatus();
64
+ });
65
+ }
66
+ isInstalled() {
67
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
68
+ yield this.updateStatus();
69
+ return this._status !== os_service_manager_1.OSServiceStatus.not_installed && this._status !== os_service_manager_1.OSServiceStatus.unknown;
70
+ });
71
+ }
72
+ start() {
73
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
74
+ const userCommand = this.options.level === 'system' ? '' : ' --user';
75
+ const script = `systemctl${userCommand} start "${this.options.slug}"`;
76
+ if (this.options.level === 'system') {
77
+ yield functions_1.ScriptRunner.runAsAdmin(script, {
78
+ name: this.options.name
79
+ });
80
+ }
81
+ else {
82
+ yield functions_1.ScriptRunner.run(script);
83
+ }
84
+ yield this.updateStatus();
85
+ });
86
+ }
87
+ updateStatus() {
88
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
89
+ try {
90
+ const userCommand = this.options.level === 'system' ? '' : ' --user';
91
+ const output = yield functions_1.ScriptRunner.run(`systemctl${userCommand} status ${this.options.slug}.service`);
92
+ const matches = / *Active: *([^ (]+) \(([^(]+)\)/g.exec(output);
93
+ if (matches && matches.length > 0) {
94
+ switch (matches[1]) {
95
+ case 'active':
96
+ this._status = os_service_manager_1.OSServiceStatus.running;
97
+ break;
98
+ case 'inactive':
99
+ this._status = os_service_manager_1.OSServiceStatus.stopped;
100
+ break;
101
+ case 'activating':
102
+ this._status = os_service_manager_1.OSServiceStatus.waiting;
103
+ break;
104
+ case 'failed':
105
+ this._status = os_service_manager_1.OSServiceStatus.failed;
106
+ break;
107
+ }
108
+ }
109
+ }
110
+ catch (e) {
111
+ if (/could not be found./g.exec(e)) {
112
+ this._status = os_service_manager_1.OSServiceStatus.not_installed;
113
+ }
114
+ else {
115
+ throw new Error(e);
116
+ }
117
+ }
118
+ });
119
+ }
120
+ stop() {
121
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
122
+ const userCommand = this.options.level === 'system' ? '' : ' --user';
123
+ const script = `systemctl${userCommand} stop '${this.options.slug}'`;
124
+ if (this.options.level === 'system') {
125
+ yield functions_1.ScriptRunner.runAsAdmin(script, {
126
+ name: this.options.name
127
+ });
128
+ }
129
+ else {
130
+ yield functions_1.ScriptRunner.run(script);
131
+ }
132
+ yield this.updateStatus();
133
+ });
134
+ }
135
+ uninstall() {
136
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
137
+ var _a, _b;
138
+ const userCommand = this.options.level === 'system' ? '' : ' --user';
139
+ let removeScript = `systemctl${userCommand} stop ${this.options.slug} && systemctl${userCommand} disable ${this.options.slug} && rm -f '${this.paths.config}' && systemctl${userCommand} daemon-reload`;
140
+ if (((_b = (_a = this._installationOptions) === null || _a === void 0 ? void 0 : _a.logging) === null || _b === void 0 ? void 0 : _b.enabled) && this.paths.logRoot !== '/var/log/' && this.paths.logRoot !== (0, path_1.join)((0, os_1.homedir)(), '/log/')) {
141
+ removeScript += ` && rm -rf '${this.paths.logRoot}'`;
142
+ }
143
+ if (this.options.level === 'system') {
144
+ yield functions_1.ScriptRunner.runAsAdmin(removeScript, {
145
+ name: `Uninstallation of ${this.options.name}`
146
+ });
147
+ }
148
+ else {
149
+ yield functions_1.ScriptRunner.run(removeScript);
150
+ }
151
+ yield this.updateStatus();
152
+ });
153
+ }
154
+ buildServiceFile(options) {
155
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
156
+ const command = `${this.command}${this.commandArgs ? ` ${this.commandArgs.join(' ')}` : ''}`;
157
+ const configObject = (0, functions_1.removeEmptyProperties)({
158
+ Unit: {
159
+ Description: options.description,
160
+ After: (_b = (_a = options.linux) === null || _a === void 0 ? void 0 : _a.Unit) === null || _b === void 0 ? void 0 : _b.After,
161
+ Before: (_d = (_c = options.linux) === null || _c === void 0 ? void 0 : _c.Unit) === null || _d === void 0 ? void 0 : _d.Before,
162
+ StartLimitIntervalSec: (_f = (_e = options.linux) === null || _e === void 0 ? void 0 : _e.Unit) === null || _f === void 0 ? void 0 : _f.StartLimitIntervalSync
163
+ },
164
+ Service: {
165
+ Type: (_h = (_g = options.linux) === null || _g === void 0 ? void 0 : _g.Service) === null || _h === void 0 ? void 0 : _h.Type,
166
+ Restart: (_k = (_j = options.linux) === null || _j === void 0 ? void 0 : _j.Service) === null || _k === void 0 ? void 0 : _k.Restart,
167
+ RestartSec: (_m = (_l = options.linux) === null || _l === void 0 ? void 0 : _l.Service) === null || _m === void 0 ? void 0 : _m.RestartSec,
168
+ StandardOutput: this.paths.log ? `file:${this.paths.log}` : undefined,
169
+ StandardError: this.paths.errorLog ? `file:${this.paths.errorLog}` : undefined,
170
+ User: (_p = (_o = options.linux) === null || _o === void 0 ? void 0 : _o.Service) === null || _p === void 0 ? void 0 : _p.User,
171
+ WorkingDirectory: this.cwd,
172
+ ExecStart: command
173
+ },
174
+ Install: {
175
+ WantedBy: (_r = (_q = options.linux) === null || _q === void 0 ? void 0 : _q.Install) === null || _r === void 0 ? void 0 : _r.WantedBy
176
+ }
177
+ });
178
+ let configString = ``;
179
+ for (const attr of Object.keys(configObject)) {
180
+ configString += `\n[${attr}]\n`;
181
+ for (const key of Object.keys(configObject[attr])) {
182
+ configString += `${key}=${configObject[attr][key]}\n`;
183
+ }
184
+ }
185
+ return configString;
186
+ }
187
+ setPaths() {
188
+ this.paths.root = this.options.level === 'system' ? '/etc/systemd/system/' : (0, path_1.join)((0, os_1.homedir)(), '.config/systemd/user/');
189
+ this.paths.config = (0, path_1.join)(this.paths.root, `${this.options.slug}.service`);
190
+ }
191
+ prepareLogging() {
192
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
193
+ var _a, _b, _c, _d;
194
+ if ((_b = (_a = this._installationOptions) === null || _a === void 0 ? void 0 : _a.logging) === null || _b === void 0 ? void 0 : _b.enabled) {
195
+ this.paths.logRoot = (_d = (_c = this._installationOptions.logging) === null || _c === void 0 ? void 0 : _c.outDir) !== null && _d !== void 0 ? _d : (this.options.level === "system" ? '/var/log/' : (0, path_1.join)((0, os_1.homedir)(), 'log/')) + this.options.name.replace(/\s/g, '');
196
+ this.paths.log = (0, path_1.join)(this.paths.logRoot, `${this.label}.log`);
197
+ this.paths.errorLog = (0, path_1.join)(this.paths.logRoot, `${this.label}_error.log`);
198
+ if (this.options.level === 'user') {
199
+ if (!(yield (0, functions_1.exists)(this.paths.logRoot))) {
200
+ yield (0, promises_1.mkdir)(this.paths.logRoot, { recursive: true });
201
+ yield functions_1.ScriptRunner.run(`chmod 745 ${this.paths.logRoot}`);
202
+ }
203
+ if (!(yield (0, functions_1.exists)(this.paths.log))) {
204
+ yield (0, promises_1.writeFile)(this.paths.log, '', { encoding: 'utf-8' });
205
+ yield functions_1.ScriptRunner.run(`chmod 745 ${this.paths.log}`);
206
+ }
207
+ if (!(yield (0, functions_1.exists)(this.paths.errorLog))) {
208
+ yield (0, promises_1.writeFile)(this.paths.errorLog, '', { encoding: 'utf-8' });
209
+ yield functions_1.ScriptRunner.run(`chmod 745 ${this.paths.errorLog}`);
210
+ }
211
+ }
212
+ }
213
+ });
214
+ }
215
+ }
216
+ exports.LinuxServiceManager = LinuxServiceManager;
217
+ //# sourceMappingURL=linux-service-manager.js.map
@@ -0,0 +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,0CA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
+ export declare class MacOSServiceManager extends OSServiceManager {
3
+ private paths;
4
+ private command?;
5
+ private commandArgs?;
6
+ private cwd?;
7
+ private domain?;
8
+ get label(): string;
9
+ initialize(options: OSServiceOptions): Promise<void>;
10
+ install(command: string, commandArgs: string[], options: OSServiceInstallationOptions): Promise<void>;
11
+ isInstalled(): Promise<boolean>;
12
+ start(): Promise<void>;
13
+ updateStatus(): Promise<void>;
14
+ stop(): Promise<void>;
15
+ uninstall(): Promise<void>;
16
+ private buildPlist;
17
+ private setPaths;
18
+ private prepareLogging;
19
+ readFromPlist(): Promise<void>;
20
+ private getUID;
21
+ private getServiceDomain;
22
+ }
@@ -0,0 +1,220 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MacOSServiceManager = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const os_service_manager_1 = require("./os-service-manager");
6
+ const plist_1 = require("plist");
7
+ const functions_1 = require("./functions");
8
+ const path_1 = require("path");
9
+ const os_1 = require("os");
10
+ const Path = require("node:path");
11
+ const promises_1 = require("fs/promises");
12
+ class MacOSServiceManager extends os_service_manager_1.OSServiceManager {
13
+ constructor() {
14
+ super(...arguments);
15
+ this.paths = {};
16
+ }
17
+ get label() {
18
+ return this.options.slug;
19
+ }
20
+ initialize(options) {
21
+ const _super = Object.create(null, {
22
+ initialize: { get: () => super.initialize }
23
+ });
24
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
25
+ yield _super.initialize.call(this, options);
26
+ this.domain = yield this.getServiceDomain();
27
+ this.setPaths();
28
+ yield this.readFromPlist();
29
+ yield this.prepareLogging();
30
+ yield this.updateStatus();
31
+ });
32
+ }
33
+ install(command, commandArgs, options) {
34
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
35
+ var _a;
36
+ this.command = Path.resolve(command);
37
+ this.commandArgs = commandArgs;
38
+ this._installationOptions = options;
39
+ yield this.prepareLogging();
40
+ if (yield this.isInstalled()) {
41
+ throw new Error(`Can't install service. Service already exists. Unload it via launchctl unload or call manager.stop();`);
42
+ }
43
+ 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) ? `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} ` : '';
46
+ yield functions_1.ScriptRunner.runAsAdmin(`${logFolderCreation}printf '${plist.replace(/'/g, '"').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}"`, {
47
+ name: this.options.name
48
+ });
49
+ }
50
+ else {
51
+ yield functions_1.ScriptRunner.run(`echo "${plist.replace(/"/g, '\\"').replace(/\n/g, '\\n')}" > "${this.paths.plist}" && launchctl load -w "${this.paths.plist}"`);
52
+ }
53
+ yield this.updateStatus();
54
+ });
55
+ }
56
+ isInstalled() {
57
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
58
+ yield this.updateStatus();
59
+ return this._status !== os_service_manager_1.OSServiceStatus.not_installed && this._status !== os_service_manager_1.OSServiceStatus.unknown;
60
+ });
61
+ }
62
+ start() {
63
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
64
+ if (this.options.level === 'system') {
65
+ yield functions_1.ScriptRunner.runAsAdmin(`launchctl start "${this.options.slug}"`, {
66
+ name: this.options.name
67
+ });
68
+ }
69
+ else {
70
+ yield functions_1.ScriptRunner.run(`launchctl start "${this.options.slug}"`);
71
+ }
72
+ yield this.updateStatus();
73
+ });
74
+ }
75
+ updateStatus() {
76
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
77
+ try {
78
+ if (this.domain) {
79
+ const output = yield functions_1.ScriptRunner.run(`launchctl print ${this.domain}/${this.label}`);
80
+ const matches = /state\s*=\s*([^\n]+)/g.exec(output);
81
+ if (matches && matches.length > 0) {
82
+ switch (matches[1]) {
83
+ case 'running':
84
+ this._status = os_service_manager_1.OSServiceStatus.running;
85
+ break;
86
+ case 'not running':
87
+ this._status = os_service_manager_1.OSServiceStatus.stopped;
88
+ break;
89
+ case 'waiting':
90
+ this._status = os_service_manager_1.OSServiceStatus.waiting;
91
+ break;
92
+ }
93
+ }
94
+ }
95
+ }
96
+ catch (e) {
97
+ if (/Could not find service/g.exec(e)) {
98
+ this._status = os_service_manager_1.OSServiceStatus.not_installed;
99
+ }
100
+ else {
101
+ throw new Error(e);
102
+ }
103
+ }
104
+ });
105
+ }
106
+ stop() {
107
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
108
+ if (this.options.level === 'system') {
109
+ yield functions_1.ScriptRunner.runAsAdmin(`launchctl stop '${this.options.slug}'`, {
110
+ name: this.options.name
111
+ });
112
+ }
113
+ else {
114
+ yield functions_1.ScriptRunner.run(`launchctl stop '${this.options.slug}'`);
115
+ }
116
+ yield this.updateStatus();
117
+ });
118
+ }
119
+ uninstall() {
120
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
121
+ var _a, _b;
122
+ let removeScript = `launchctl unload '${this.paths.plist}' && rm -rf '${this.paths.plist}'`;
123
+ if (((_b = (_a = this._installationOptions) === null || _a === void 0 ? void 0 : _a.logging) === null || _b === void 0 ? void 0 : _b.enabled) && this.paths.logRoot !== '/Library/Logs/' && this.paths.logRoot !== (0, path_1.join)((0, os_1.homedir)(), '/Library/Logs/')) {
124
+ removeScript += ` '${this.paths.logRoot}'`;
125
+ }
126
+ if (this.options.level === 'system') {
127
+ yield functions_1.ScriptRunner.runAsAdmin(removeScript, {
128
+ name: `Uninstallation of ${this.options.name}`
129
+ });
130
+ }
131
+ else {
132
+ yield functions_1.ScriptRunner.run(removeScript);
133
+ }
134
+ yield this.updateStatus();
135
+ });
136
+ }
137
+ buildPlist(options) {
138
+ var _a, _b, _c, _d;
139
+ const plistValue = {
140
+ 'Label': this.label,
141
+ 'ProgramArguments': [
142
+ this.command,
143
+ ...this.commandArgs
144
+ ],
145
+ 'StartInterval': (_a = options.macos) === null || _a === void 0 ? void 0 : _a.startInterval,
146
+ 'KeepAlive': (_b = options.macos) === null || _b === void 0 ? void 0 : _b.keepAlive,
147
+ 'RunAtLoad': true,
148
+ 'WorkingDirectory': options.cwd,
149
+ 'StandardOutPath': ((_c = options.logging) === null || _c === void 0 ? void 0 : _c.enabled) ? this.paths.log : undefined,
150
+ 'StandardErrorPath': ((_d = options.logging) === null || _d === void 0 ? void 0 : _d.enabled) ? this.paths.errorLog : undefined
151
+ };
152
+ return (0, plist_1.build)((0, functions_1.removeEmptyProperties)(plistValue));
153
+ }
154
+ setPaths() {
155
+ this.paths.root = this.options.level === 'system' ? '/Library/LaunchDaemons/' : (0, path_1.join)((0, os_1.homedir)(), '/Library/LaunchAgents/');
156
+ this.paths.plist = (0, path_1.join)(this.paths.root, `${this.options.slug}.plist`);
157
+ }
158
+ prepareLogging() {
159
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
160
+ var _a, _b, _c, _d;
161
+ if ((_b = (_a = this._installationOptions) === null || _a === void 0 ? void 0 : _a.logging) === null || _b === void 0 ? void 0 : _b.enabled) {
162
+ this.paths.logRoot = (_d = (_c = this._installationOptions.logging) === null || _c === void 0 ? void 0 : _c.outDir) !== null && _d !== void 0 ? _d : (this.options.level === 'system' ? '/Library/Logs/' : (0, path_1.join)((0, os_1.homedir)(), '/Library/Logs/')) + this.options.name.replace(/\s/g, '');
163
+ this.paths.log = (0, path_1.join)(this.paths.logRoot, `${this.label}.log`);
164
+ this.paths.errorLog = (0, path_1.join)(this.paths.logRoot, `${this.label}_error.log`);
165
+ if (this.options.level === 'user') {
166
+ if (!(yield (0, functions_1.exists)(this.paths.logRoot))) {
167
+ yield (0, promises_1.mkdir)(this.paths.logRoot, { recursive: true });
168
+ yield functions_1.ScriptRunner.run(`chmod 745 ${this.paths.logRoot}`);
169
+ }
170
+ if (!(yield (0, functions_1.exists)(this.paths.log))) {
171
+ yield (0, promises_1.writeFile)(this.paths.log, '', { encoding: 'utf-8' });
172
+ yield functions_1.ScriptRunner.run(`chmod 745 ${this.paths.log}`);
173
+ }
174
+ if (!(yield (0, functions_1.exists)(this.paths.errorLog))) {
175
+ yield (0, promises_1.writeFile)(this.paths.errorLog, '', { encoding: 'utf-8' });
176
+ yield functions_1.ScriptRunner.run(`chmod 745 ${this.paths.errorLog}`);
177
+ }
178
+ }
179
+ }
180
+ });
181
+ }
182
+ readFromPlist() {
183
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
184
+ var _a;
185
+ if (this.paths.plist && (yield (0, functions_1.exists)(this.paths.plist))) {
186
+ const plistContent = yield (0, promises_1.readFile)(this.paths.plist, {
187
+ encoding: 'utf-8'
188
+ });
189
+ const plist = (0, plist_1.parse)(plistContent);
190
+ this.cwd = plist['WorkingDirectory'];
191
+ this.paths.log = plist['StandardOutPath'];
192
+ this.paths.errorLog = plist['StandardErrorPath'];
193
+ this.command = plist['ProgramArguments'][0];
194
+ this.commandArgs = plist['ProgramArguments'].slice(1);
195
+ this._installationOptions = (_a = this._installationOptions) !== null && _a !== void 0 ? _a : {};
196
+ this._installationOptions = Object.assign(Object.assign({}, this._installationOptions), { logging: {
197
+ enabled: plist['StandardOutPath'] !== undefined && plist['StandardErrorPath'] !== undefined,
198
+ outDir: plist['StandardOutPath'] !== undefined && plist['StandardErrorPath'] !== undefined ? Path.parse(plist['StandardOutPath']).dir : undefined
199
+ }, macos: Object.assign(Object.assign({}, this._installationOptions.macos), { startInterval: plist['StartInterval'], keepAlive: plist['KeepAlive'] }) });
200
+ }
201
+ });
202
+ }
203
+ getUID() {
204
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
205
+ return (yield functions_1.ScriptRunner.run('id -u')).replace(/[\n\r\s]/g, '');
206
+ });
207
+ }
208
+ getServiceDomain() {
209
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
210
+ if (this.options.level === 'system') {
211
+ return 'system';
212
+ }
213
+ else if (this.options.level === 'user') {
214
+ return `gui/${yield this.getUID()}`;
215
+ }
216
+ });
217
+ }
218
+ }
219
+ exports.MacOSServiceManager = MacOSServiceManager;
220
+ //# sourceMappingURL=macos-service-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"macos-service-manager.js","sourceRoot":"","sources":["../../../../node-service/src/lib/macos-service-manager.ts"],"names":[],"mappings":";;;;AAAA,6DAAuH;AACvH,iCAAgD;AAChD,2CAAwE;AACxE,+BAA0B;AAC1B,2BAA2B;AAC3B,kCAAkC;AAClC,0CAAuD;AAEvD,MAAa,mBAAoB,SAAQ,qCAAgB;IAAzD;;QACU,UAAK,GAMT,EAAE,CAAC;IA2NT,CAAC;IArNC,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,MAAM,GAAG,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC5C,IAAI,CAAC,QAAQ,EAAE,CAAC;YAChB,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;YAC3B,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;YAC5B,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QAC5B,CAAC;KAAA;IAEK,OAAO,CAAC,OAAe,EAAE,WAAqB,EAAE,OAAqC;;;YACzF,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACrC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;YAC/B,IAAI,CAAC,oBAAoB,GAAG,OAAO,CAAC;YACpC,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;YAE5B,IAAI,MAAM,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;gBAC7B,MAAM,IAAI,KAAK,CAA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AAC,OAAO,CAAC,KAAK,KAAK,MAAM,EAAE,CAAC;gBACzC,OAAO,OAAO,MAAM,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;YACtC,CAAC;QACH,CAAC;KAAA;CACF;AAlOD,kDAkOC"}
@@ -0,0 +1,70 @@
1
+ export interface OSServiceOptions {
2
+ name: string;
3
+ slug: string;
4
+ level: 'system' | 'user';
5
+ windows?: WindowsOSServiceOptions;
6
+ icns?: string;
7
+ }
8
+ export interface OSServiceInstallationOptions {
9
+ description?: string;
10
+ cwd?: string;
11
+ env?: Record<string, any>;
12
+ logging?: {
13
+ enabled: boolean;
14
+ outDir?: string;
15
+ };
16
+ macos?: MacOSServiceOptions;
17
+ linux?: LinuxOSServiceOptions;
18
+ }
19
+ export interface MacOSServiceOptions {
20
+ label: string;
21
+ startInterval?: number;
22
+ keepAlive?: boolean;
23
+ }
24
+ export interface LinuxOSServiceOptions {
25
+ Unit?: {
26
+ Before?: string;
27
+ After?: string;
28
+ StartLimitIntervalSync?: number;
29
+ };
30
+ Service?: {
31
+ Type?: string;
32
+ Restart?: string;
33
+ RestartSec?: number;
34
+ StandardOutput?: string;
35
+ StandardError?: string;
36
+ User?: string;
37
+ WorkingDirectory?: string;
38
+ ExecStart?: string;
39
+ };
40
+ Install: {
41
+ WantedBy?: string;
42
+ };
43
+ }
44
+ export interface WindowsOSServiceOptions {
45
+ pathToWinswExe?: string;
46
+ pathToWinswConfig?: string;
47
+ }
48
+ export declare enum OSServiceStatus {
49
+ 'not_installed' = "not_installed",
50
+ 'installing' = "installing",
51
+ 'unknown' = "unknown",
52
+ 'waiting' = "waiting",
53
+ 'running' = "running",
54
+ 'stopped' = "stopped",
55
+ 'failed' = "failed"
56
+ }
57
+ export declare abstract class OSServiceManager {
58
+ get installationOptions(): OSServiceInstallationOptions;
59
+ get status(): OSServiceStatus;
60
+ protected options?: OSServiceOptions;
61
+ protected _status: OSServiceStatus;
62
+ protected _installationOptions?: OSServiceInstallationOptions;
63
+ initialize(options: OSServiceOptions): Promise<void>;
64
+ abstract install(command: string, commandArgs: string[], options: OSServiceInstallationOptions): Promise<void>;
65
+ abstract uninstall(): Promise<void>;
66
+ abstract start(): Promise<void>;
67
+ abstract stop(): Promise<void>;
68
+ abstract isInstalled(): Promise<boolean>;
69
+ abstract updateStatus(): Promise<void>;
70
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OSServiceManager = exports.OSServiceStatus = void 0;
4
+ const tslib_1 = require("tslib");
5
+ var OSServiceStatus;
6
+ (function (OSServiceStatus) {
7
+ OSServiceStatus["not_installed"] = "not_installed";
8
+ OSServiceStatus["installing"] = "installing";
9
+ OSServiceStatus["unknown"] = "unknown";
10
+ OSServiceStatus["waiting"] = "waiting";
11
+ OSServiceStatus["running"] = "running";
12
+ OSServiceStatus["stopped"] = "stopped";
13
+ OSServiceStatus["failed"] = "failed";
14
+ })(OSServiceStatus || (exports.OSServiceStatus = OSServiceStatus = {}));
15
+ class OSServiceManager {
16
+ constructor() {
17
+ this._status = OSServiceStatus.not_installed;
18
+ }
19
+ get installationOptions() {
20
+ return this._installationOptions;
21
+ }
22
+ get status() {
23
+ return this._status;
24
+ }
25
+ initialize(options) {
26
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
27
+ this.options = options;
28
+ yield this.updateStatus();
29
+ });
30
+ }
31
+ }
32
+ exports.OSServiceManager = OSServiceManager;
33
+ //# sourceMappingURL=os-service-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"os-service-manager.js","sourceRoot":"","sources":["../../../../node-service/src/lib/os-service-manager.ts"],"names":[],"mappings":";;;;AAoDA,IAAY,eAQX;AARD,WAAY,eAAe;IACzB,kDAAiC,CAAA;IACjC,4CAA2B,CAAA;IAC3B,sCAAqB,CAAA;IACrB,sCAAqB,CAAA;IACrB,sCAAqB,CAAA;IACrB,sCAAqB,CAAA;IACrB,oCAAmB,CAAA;AACrB,CAAC,EARW,eAAe,+BAAf,eAAe,QAQ1B;AAED,MAAsB,gBAAgB;IAAtC;QAUY,YAAO,GAAG,eAAe,CAAC,aAAa,CAAC;IAmBpD,CAAC;IA5BC,IAAI,mBAAmB;QACrB,OAAO,IAAI,CAAC,oBAAoB,CAAC;IACnC,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAMY,UAAU,CAAC,OAAyB;;YAC/C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;YACvB,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QAC5B,CAAC;KAAA;CAaF;AA7BD,4CA6BC"}
@@ -0,0 +1,2 @@
1
+ import { OSServiceManager, OSServiceOptions } from './os-service-manager';
2
+ export declare function initializeOSService(options: OSServiceOptions): Promise<OSServiceManager>;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initializeOSService = initializeOSService;
4
+ const tslib_1 = require("tslib");
5
+ const os_1 = require("os");
6
+ const macos_service_manager_1 = require("./macos-service-manager");
7
+ const windows_service_manager_1 = require("./windows-service-manager");
8
+ const linux_service_manager_1 = require("./linux-service-manager");
9
+ function initializeOSService(options) {
10
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
11
+ if ((0, os_1.platform)() === 'darwin') {
12
+ const manager = new macos_service_manager_1.MacOSServiceManager();
13
+ yield manager.initialize(options);
14
+ return manager;
15
+ }
16
+ else if ((0, os_1.platform)() === 'win32') {
17
+ const manager = new windows_service_manager_1.WindowsServiceManager();
18
+ yield manager.initialize(options);
19
+ return manager;
20
+ }
21
+ else if ((0, os_1.platform)() === "linux") {
22
+ const manager = new linux_service_manager_1.LinuxServiceManager();
23
+ yield manager.initialize(options);
24
+ return manager;
25
+ }
26
+ throw new Error('Not implemented');
27
+ });
28
+ }
29
+ //# sourceMappingURL=public-functions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public-functions.js","sourceRoot":"","sources":["../../../../node-service/src/lib/public-functions.ts"],"names":[],"mappings":";;AAMA,kDAgBC;;AAtBD,2BAA4B;AAC5B,mEAA4D;AAC5D,uEAAgE;AAChE,mEAA8D;AAG9D,SAAsB,mBAAmB,CAAC,OAAyB;;QACjE,IAAI,IAAA,aAAQ,GAAE,KAAK,QAAQ,EAAE,CAAC;YAC5B,MAAM,OAAO,GAAG,IAAI,2CAAmB,EAAE,CAAC;YAC1C,MAAM,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;YAClC,OAAO,OAAO,CAAC;QACjB,CAAC;aAAM,IAAI,IAAA,aAAQ,GAAE,KAAK,OAAO,EAAE,CAAC;YAClC,MAAM,OAAO,GAAG,IAAI,+CAAqB,EAAE,CAAC;YAC5C,MAAM,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;YAClC,OAAO,OAAO,CAAC;QACjB,CAAC;aAAM,IAAG,IAAA,aAAQ,GAAE,KAAK,OAAO,EAAE,CAAC;YACjC,MAAM,OAAO,GAAG,IAAI,2CAAmB,EAAE,CAAC;YAC1C,MAAM,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;YAClC,OAAO,OAAO,CAAC;QACjB,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;CAAA"}
@@ -0,0 +1,13 @@
1
+ import { OSServiceInstallationOptions, OSServiceManager, OSServiceOptions } from './os-service-manager';
2
+ export declare class WindowsServiceManager extends OSServiceManager {
3
+ initialize(options: OSServiceOptions): Promise<void>;
4
+ private get winswExePath();
5
+ checkRequirements(): Promise<void>;
6
+ install(command: string, commandArgs: string[], options: OSServiceInstallationOptions): Promise<void>;
7
+ uninstall(): Promise<void>;
8
+ start(): Promise<void>;
9
+ stop(): Promise<void>;
10
+ isInstalled(): Promise<boolean>;
11
+ updateStatus(): Promise<void>;
12
+ private buildWinsXML;
13
+ }
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WindowsServiceManager = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const functions_1 = require("./functions");
6
+ const promises_1 = require("fs/promises");
7
+ const os_service_manager_1 = require("./os-service-manager");
8
+ const Path = require("node:path");
9
+ class WindowsServiceManager extends os_service_manager_1.OSServiceManager {
10
+ initialize(options) {
11
+ const _super = Object.create(null, {
12
+ initialize: { get: () => super.initialize }
13
+ });
14
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
15
+ yield _super.initialize.call(this, options);
16
+ yield this.checkRequirements();
17
+ yield this.updateStatus();
18
+ });
19
+ }
20
+ get winswExePath() {
21
+ var _a, _b;
22
+ return (_b = (_a = this.options.windows) === null || _a === void 0 ? void 0 : _a.pathToWinswExe) !== null && _b !== void 0 ? _b : 'winsw';
23
+ }
24
+ checkRequirements() {
25
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
26
+ var _a;
27
+ let version = '';
28
+ try {
29
+ version = yield functions_1.ScriptRunner.run(`${this.winswExePath} --version`);
30
+ }
31
+ catch (e) {
32
+ throw new Error(`Can't find winsw.exe binary. Make sure to have winsw v3 installed and referenced to %PATH$ environment variable. Or set the path to winsw.exe in options.windows.winsw.path.`);
33
+ }
34
+ if (!version) {
35
+ throw new Error(`Can't read version information. Make sure that you have winsw v3 installed.`);
36
+ }
37
+ if (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.windows.pathToWinswConfig)) {
38
+ throw new Error('You have to define a path to a (non)-existing winsw configuration file. Please check options.windows.pathToWinswConfig');
39
+ }
40
+ });
41
+ }
42
+ install(command, commandArgs, options) {
43
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
44
+ var _a, _b, _c, _d;
45
+ if (!(yield (0, functions_1.exists)((_a = this.options.windows) === null || _a === void 0 ? void 0 : _a.pathToWinswConfig))) {
46
+ // create new winsw.xml config file
47
+ yield (0, promises_1.writeFile)((_b = this.options.windows) === null || _b === void 0 ? void 0 : _b.pathToWinswConfig, this.buildWinsXML(command, commandArgs, options), {
48
+ encoding: 'utf-8'
49
+ });
50
+ }
51
+ const configDir = Path.parse((_c = this.options.windows) === null || _c === void 0 ? void 0 : _c.pathToWinswConfig).dir;
52
+ const configName = Path.parse((_d = this.options.windows) === null || _d === void 0 ? void 0 : _d.pathToWinswConfig).base;
53
+ const script = `cd "${configDir}" && ${this.winswExePath} install ${configName}`;
54
+ yield functions_1.ScriptRunner.runAsAdmin(script, {
55
+ name: this.options.name
56
+ });
57
+ yield this.updateStatus();
58
+ });
59
+ }
60
+ uninstall() {
61
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
62
+ var _a, _b;
63
+ yield functions_1.ScriptRunner.runAsAdmin(`${this.winswExePath} stop "${(_a = this.options.windows) === null || _a === void 0 ? void 0 : _a.pathToWinswConfig}" && ${this.winswExePath} uninstall "${(_b = this.options.windows) === null || _b === void 0 ? void 0 : _b.pathToWinswConfig}"`, {
64
+ name: this.options.name
65
+ });
66
+ yield this.updateStatus();
67
+ });
68
+ }
69
+ start() {
70
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
71
+ var _a;
72
+ yield functions_1.ScriptRunner.runAsAdmin(`${this.winswExePath} start ${(_a = this.options.windows) === null || _a === void 0 ? void 0 : _a.pathToWinswConfig}`, {
73
+ name: this.options.name
74
+ });
75
+ yield this.updateStatus();
76
+ });
77
+ }
78
+ stop() {
79
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
80
+ var _a;
81
+ yield functions_1.ScriptRunner.runAsAdmin(`${this.winswExePath} stop ${(_a = this.options.windows) === null || _a === void 0 ? void 0 : _a.pathToWinswConfig}`, {
82
+ name: this.options.name
83
+ });
84
+ yield this.updateStatus();
85
+ });
86
+ }
87
+ isInstalled() {
88
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
89
+ var _a;
90
+ yield this.updateStatus();
91
+ return (yield (0, functions_1.exists)((_a = this.options) === null || _a === void 0 ? void 0 : _a.windows.pathToWinswConfig)) && this._status !== os_service_manager_1.OSServiceStatus.not_installed;
92
+ });
93
+ }
94
+ updateStatus() {
95
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
96
+ var _a, _b;
97
+ if ((_a = this.options.windows) === null || _a === void 0 ? void 0 : _a.pathToWinswConfig) {
98
+ try {
99
+ const output = yield functions_1.ScriptRunner.run(`${this.winswExePath} status "${(_b = this.options.windows) === null || _b === void 0 ? void 0 : _b.pathToWinswConfig}"`);
100
+ const matches = /I?n?[aA]ctive \(([^)]+)\)/g.exec(output);
101
+ if (matches && matches.length > 0) {
102
+ switch (matches[1]) {
103
+ case 'running':
104
+ this._status = os_service_manager_1.OSServiceStatus.running;
105
+ break;
106
+ case 'stopped':
107
+ this._status = os_service_manager_1.OSServiceStatus.stopped;
108
+ break;
109
+ case 'waiting':
110
+ this._status = os_service_manager_1.OSServiceStatus.waiting;
111
+ break;
112
+ default:
113
+ this._status = os_service_manager_1.OSServiceStatus.unknown;
114
+ }
115
+ }
116
+ else if (output === 'NonExistent\n') {
117
+ this._status = os_service_manager_1.OSServiceStatus.not_installed;
118
+ }
119
+ }
120
+ catch (e) {
121
+ throw new Error(e);
122
+ }
123
+ }
124
+ else {
125
+ this._status = os_service_manager_1.OSServiceStatus.not_installed;
126
+ }
127
+ });
128
+ }
129
+ buildWinsXML(command, commandArgs, installationOptions) {
130
+ var _a, _b, _c;
131
+ let winswFileContent = `<service>
132
+ <id>${this.options.slug}</id>
133
+ <name>${this.options.name}</name>
134
+ <description>${installationOptions.description}</description>
135
+ <executable>${command}</executable>
136
+ <arguments>${commandArgs.join(' ')}</arguments>`;
137
+ if (installationOptions.cwd) {
138
+ winswFileContent += `
139
+ <workingdirectory>${installationOptions.cwd}</workingdirectory>`;
140
+ }
141
+ if (installationOptions.env && Object.keys(installationOptions.env).length > 0) {
142
+ for (const key of Object.keys(installationOptions.env)) {
143
+ winswFileContent += `
144
+ <env name="${key}" value="${installationOptions.env[key].replace(/"/g, '"')}" />`;
145
+ }
146
+ }
147
+ if ((_a = installationOptions.logging) === null || _a === void 0 ? void 0 : _a.enabled) {
148
+ if ((_b = installationOptions.logging) === null || _b === void 0 ? void 0 : _b.outDir) {
149
+ winswFileContent += `
150
+ <logpath>${(_c = installationOptions.logging) === null || _c === void 0 ? void 0 : _c.outDir}</logpath>`;
151
+ }
152
+ winswFileContent += `
153
+ <log mode="roll-by-size">
154
+ <sizeThreshold>10240</sizeThreshold>
155
+ <keepFiles>4</keepFiles>`;
156
+ winswFileContent += `
157
+ </log>`;
158
+ }
159
+ else {
160
+ winswFileContent += `
161
+ <log mode="none"></log>`;
162
+ }
163
+ winswFileContent += `
164
+ </service>`;
165
+ return winswFileContent;
166
+ }
167
+ }
168
+ exports.WindowsServiceManager = WindowsServiceManager;
169
+ //# sourceMappingURL=windows-service-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"windows-service-manager.js","sourceRoot":"","sources":["../../../../node-service/src/lib/windows-service-manager.ts"],"names":[],"mappings":";;;;AAAA,2CAAiD;AACjD,0CAAsC;AACtC,6DAAuH;AACvH,kCAAkC;AAElC,MAAa,qBAAsB,SAAQ,qCAAgB;IAC1C,UAAU,CAAC,OAAyB;;;;;YACjD,MAAM,OAAM,UAAU,YAAC,OAAO,CAAC,CAAC;YAChC,MAAM,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC/B,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QAC5B,CAAC;KAAA;IAED,IAAY,YAAY;;QACtB,OAAO,MAAA,MAAA,IAAI,CAAC,OAAO,CAAC,OAAO,0CAAE,cAAc,mCAAI,OAAO,CAAC;IACzD,CAAC;IAEK,iBAAiB;;;YACrB,IAAI,OAAO,GAAG,EAAE,CAAC;YACjB,IAAI,CAAC;gBACH,OAAO,GAAG,MAAM,wBAAY,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,YAAY,YAAY,CAAC,CAAC;YACrE,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,MAAM,IAAI,KAAK,CAAC,8KAA8K,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