fix(systemdmanager): migrate systemd file operations to smartfs and tighten TypeScript safety

This commit is contained in:
2026-05-01 15:24:08 +00:00
parent a8b6ecb1a6
commit ddb77fd37d
12 changed files with 2569 additions and 3270 deletions
+36
View File
@@ -0,0 +1,36 @@
{
"@git.zone/cli": {
"projectType": "npm",
"module": {
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "smartdaemon",
"description": "Start scripts as long running daemons and manage them.",
"npmPackagename": "@push.rocks/smartdaemon",
"license": "MIT",
"keywords": [
"daemon",
"service management",
"Linux systemd",
"process management",
"Node.js",
"system administration",
"background services"
]
},
"release": {
"registries": [
"https://verdaccio.lossless.digital",
"https://registry.npmjs.org"
],
"accessLevel": "public"
}
},
"@git.zone/tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
},
"@ship.zone/szci": {
"npmGlobalTools": [],
"npmRegistryUrl": "registry.npmjs.org"
}
}
+8
View File
@@ -1,5 +1,13 @@
# Changelog # Changelog
## 2026-05-01 - 2.1.1 - fix(systemdmanager)
migrate systemd file operations to smartfs and tighten TypeScript safety
- replace smartfile usage with smartfs for listing, reading, writing, and deleting systemd service files
- store service constructor options explicitly and initialize service properties with definite assignment to satisfy stricter TypeScript settings
- update tests to mock systemd manager interactions when creating services
- refresh package metadata, build scripts, and dependency versions to align with the updated toolchain
## 2025-09-03 - 2.1.0 - feat(systemd-manager) ## 2025-09-03 - 2.1.0 - feat(systemd-manager)
Support sudo password and root detection in SystemdManager; add user/group support in services and templates; add tests and expand README Support sudo password and root detection in SystemdManager; add user/group support in services and templates; add tests and expand README
+4 -3
View File
@@ -1,5 +1,6 @@
Copyright (c) 2019 Lossless GmbH (hello@lossless.com) The MIT License (MIT)
Copyright (c) 2017-2019, braces lab
Copyright (c) 2026 Task Venture Capital GmbH
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
@@ -17,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
+14 -8
View File
@@ -1,5 +1,5 @@
{ {
"gitzone": { "@git.zone/cli": {
"projectType": "npm", "projectType": "npm",
"module": { "module": {
"githost": "code.foss.global", "githost": "code.foss.global",
@@ -8,7 +8,6 @@
"description": "Start scripts as long running daemons and manage them.", "description": "Start scripts as long running daemons and manage them.",
"npmPackagename": "@push.rocks/smartdaemon", "npmPackagename": "@push.rocks/smartdaemon",
"license": "MIT", "license": "MIT",
"projectDomain": "push.rocks",
"keywords": [ "keywords": [
"daemon", "daemon",
"service management", "service management",
@@ -18,13 +17,20 @@
"system administration", "system administration",
"background services" "background services"
] ]
},
"release": {
"registries": [
"https://verdaccio.lossless.digital",
"https://registry.npmjs.org"
],
"accessLevel": "public"
} }
}, },
"npmci": { "@git.zone/tsdoc": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n" "legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
},
"@ship.zone/szci": {
"npmGlobalTools": [],
"npmRegistryUrl": "registry.npmjs.org"
} }
} }
+36 -30
View File
@@ -5,28 +5,47 @@
"description": "Start scripts as long running daemons and manage them.", "description": "Start scripts as long running daemons and manage them.",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts", "typings": "dist_ts/index.d.ts",
"author": "Lossless GmbH", "type": "module",
"author": "Task Venture Capital GmbH <hello@task.vc>",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"test": "(tstest test/ --verbose --logfile --timeout 60)", "test": "tstest test/ --verbose --timeout 60",
"build": "(tsbuild --web --allowimplicitany)", "build": "tsbuild --web",
"format": "gitzone format",
"buildDocs": "tsdoc" "buildDocs": "tsdoc"
}, },
"repository": {
"type": "git",
"url": "https://code.foss.global/push.rocks/smartdaemon.git"
},
"keywords": [
"daemon",
"service management",
"Linux systemd",
"process management",
"Node.js",
"system administration",
"background services"
],
"bugs": {
"url": "https://gitlab.com/push.rocks/smartdaemon/issues"
},
"homepage": "https://code.foss.global/push.rocks/smartdaemon",
"devDependencies": { "devDependencies": {
"@git.zone/tsbuild": "^2.6.7", "@git.zone/tsbuild": "^4.4.0",
"@git.zone/tsrun": "^1.2.44", "@git.zone/tsrun": "^2.0.3",
"@git.zone/tstest": "^2.3.5", "@git.zone/tstest": "^3.6.3",
"@types/node": "^22.13.8" "@types/node": "^25.6.0"
}, },
"dependencies": { "dependencies": {
"@push.rocks/lik": "^6.2.2", "@push.rocks/lik": "^6.4.1",
"@push.rocks/smartfile": "^11.2.7", "@push.rocks/smartfm": "^2.2.2",
"@push.rocks/smartfm": "^2.0.4", "@push.rocks/smartfs": "^1.5.1",
"@push.rocks/smartlog": "^3.1.8", "@push.rocks/smartlog": "^3.2.2",
"@push.rocks/smartlog-destination-local": "^9.0.1", "@push.rocks/smartlog-destination-local": "^9.0.2",
"@push.rocks/smartpath": "^6.0.0", "@push.rocks/smartpath": "^6.0.0",
"@push.rocks/smartshell": "^3.3.0", "@push.rocks/smartshell": "^3.3.8",
"@push.rocks/smartsystem": "^3.0.7" "@push.rocks/smartsystem": "^3.0.8"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",
@@ -37,26 +56,13 @@
"dist_ts_web/**/*", "dist_ts_web/**/*",
"assets/**/*", "assets/**/*",
"cli.js", "cli.js",
".smartconfig.json",
"license",
"npmextra.json", "npmextra.json",
"readme.md" "readme.md"
], ],
"browserslist": [ "browserslist": [
"last 1 chrome versions" "last 1 chrome versions"
], ],
"type": "module", "packageManager": "pnpm@10.28.2"
"keywords": [
"daemon",
"service management",
"Linux systemd",
"process management",
"Node.js",
"system administration",
"background services"
],
"homepage": "https://code.foss.global/push.rocks/smartdaemon",
"repository": {
"type": "git",
"url": "https://code.foss.global/push.rocks/smartdaemon.git"
},
"packageManager": "pnpm@10.14.0+sha512.ad27a79641b49c3e481a16a805baa71817a04bbe06a38d17e60e2eaee83f6a146c6a688125f5792e48dd5ba30e7da52a5cda4c3992b9ccf333f9ce223af84748"
} }
+2443 -3203
View File
File diff suppressed because it is too large Load Diff
+4 -1
View File
@@ -12,13 +12,16 @@ tap.test('should create an instance of smartdaemon', async () => {
}); });
tap.test('should create a service', async () => { tap.test('should create a service', async () => {
testSmartdaemon.addService({ testSmartdaemon.systemdManager.getServices = async () => [];
testSmartdaemon.systemdManager.saveService = async () => {};
const testService = await testSmartdaemon.addService({
name: 'npmversion', name: 'npmversion',
version: 'x.x.x', version: 'x.x.x',
command: 'npm -v', command: 'npm -v',
description: 'displays the npm version', description: 'displays the npm version',
workingDir: plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url), workingDir: plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
}); });
expect(testService.name).toEqual('npmversion');
}); });
export default tap.start(); export default tap.start();
+1 -1
View File
@@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/smartdaemon', name: '@push.rocks/smartdaemon',
version: '2.1.0', version: '2.1.1',
description: 'Start scripts as long running daemons and manage them.' description: 'Start scripts as long running daemons and manage them.'
} }
+8 -9
View File
@@ -21,20 +21,19 @@ export class SmartDaemonService implements ISmartDaemonServiceConstructorOptions
optionsArg: ISmartDaemonServiceConstructorOptions optionsArg: ISmartDaemonServiceConstructorOptions
) { ) {
const service = new SmartDaemonService(smartdaemonRef); const service = new SmartDaemonService(smartdaemonRef);
for (const key of Object.keys(optionsArg)) { Object.assign(service, optionsArg);
service[key] = optionsArg[key]; service.options = optionsArg;
}
return service; return service;
} }
public options: ISmartDaemonServiceConstructorOptions; public options!: ISmartDaemonServiceConstructorOptions;
public alreadyExists = false; public alreadyExists = false;
public name: string; public name!: string;
public version: string; public version!: string;
public command: string; public command!: string;
public workingDir: string; public workingDir!: string;
public description: string; public description!: string;
public user?: string; public user?: string;
public group?: string; public group?: string;
+9 -9
View File
@@ -29,6 +29,7 @@ export class SmartDaemonSystemdManager {
public smartdaemonRef: SmartDaemon; public smartdaemonRef: SmartDaemon;
public smartshellInstance: plugins.smartshell.Smartshell; public smartshellInstance: plugins.smartshell.Smartshell;
public smartsystem: plugins.smartsystem.Smartsystem; public smartsystem: plugins.smartsystem.Smartsystem;
public smartFs: plugins.smartfs.SmartFs;
public shouldExecute: boolean = false; public shouldExecute: boolean = false;
public isRoot: boolean = false; public isRoot: boolean = false;
@@ -40,6 +41,7 @@ export class SmartDaemonSystemdManager {
executor: 'bash', executor: 'bash',
}); });
this.smartsystem = new plugins.smartsystem.Smartsystem(); this.smartsystem = new plugins.smartsystem.Smartsystem();
this.smartFs = new plugins.smartfs.SmartFs(new plugins.smartfs.SmartFsProviderNode());
this.sudoPassword = sudoPasswordArg; this.sudoPassword = sudoPasswordArg;
// Check if we're running as root // Check if we're running as root
@@ -85,7 +87,7 @@ export class SmartDaemonSystemdManager {
try { try {
await this.smartshellInstance.exec(commandArg); await this.smartshellInstance.exec(commandArg);
} catch (error) { } catch (error) {
if (!this.isRoot && error.message && error.message.includes('authentication')) { if (!this.isRoot && error instanceof Error && error.message.includes('authentication')) {
throw new Error('Sudo authentication failed. Please configure passwordless sudo or provide a sudo password.'); throw new Error('Sudo authentication failed. Please configure passwordless sudo or provide a sudo password.');
} }
throw error; throw error;
@@ -102,12 +104,10 @@ export class SmartDaemonSystemdManager {
const smartfmInstance = new plugins.smartfm.Smartfm({ const smartfmInstance = new plugins.smartfm.Smartfm({
fmType: 'yaml', fmType: 'yaml',
}); });
const availableServices = await plugins.smartfile.fs.fileTreeToObject( const availableServices = await this.smartFs.directory(paths.systemdDir).filter('smartdaemon_*.service').list();
paths.systemdDir,
'smartdaemon_*.service'
);
for (const serviceFile of availableServices) { for (const serviceFile of availableServices) {
const data = smartfmInstance.parseFromComments('# ', serviceFile.contentBuffer.toString()) const serviceFileContent = await this.smartFs.file(serviceFile.path).encoding('utf8').read();
const data = smartfmInstance.parseFromComments('# ', serviceFileContent.toString())
.data as ISmartDaemonServiceConstructorOptions; .data as ISmartDaemonServiceConstructorOptions;
const service = await SmartDaemonService.createFromOptions(this.smartdaemonRef, data); const service = await SmartDaemonService.createFromOptions(this.smartdaemonRef, data);
service.alreadyExists = true; service.alreadyExists = true;
@@ -143,11 +143,11 @@ export class SmartDaemonSystemdManager {
if (this.isRoot) { if (this.isRoot) {
// Direct write when running as root // Direct write when running as root
await plugins.smartfile.memory.toFs(content, targetPath); await this.smartFs.file(targetPath).encoding('utf8').mode(0o644).write(content);
} else { } else {
// Use sudo to write when not root // Use sudo to write when not root
const tempPath = `/tmp/smartdaemon_${serviceArg.name}.service`; const tempPath = `/tmp/smartdaemon_${serviceArg.name}.service`;
await plugins.smartfile.memory.toFs(content, tempPath); await this.smartFs.file(tempPath).encoding('utf8').mode(0o644).write(content);
await this.execute(`mv ${tempPath} ${targetPath}`); // execute() will add sudo await this.execute(`mv ${tempPath} ${targetPath}`); // execute() will add sudo
await this.execute(`chmod 644 ${targetPath}`); // execute() will add sudo await this.execute(`chmod 644 ${targetPath}`); // execute() will add sudo
} }
@@ -159,7 +159,7 @@ export class SmartDaemonSystemdManager {
const filePath = SmartDaemonSystemdManager.createFilePathFromServiceName(serviceArg.name); const filePath = SmartDaemonSystemdManager.createFilePathFromServiceName(serviceArg.name);
if (this.isRoot) { if (this.isRoot) {
await plugins.smartfile.fs.remove(filePath); await this.smartFs.file(filePath).delete();
} else { } else {
await this.execute(`rm ${filePath}`); // execute() will add sudo await this.execute(`rm ${filePath}`); // execute() will add sudo
} }
+2 -2
View File
@@ -5,8 +5,8 @@ export { path };
// @pushrocks scope // @pushrocks scope
import * as lik from '@push.rocks/lik'; import * as lik from '@push.rocks/lik';
import * as smartfile from '@push.rocks/smartfile';
import * as smartfm from '@push.rocks/smartfm'; import * as smartfm from '@push.rocks/smartfm';
import * as smartfs from '@push.rocks/smartfs';
import * as smartlog from '@push.rocks/smartlog'; import * as smartlog from '@push.rocks/smartlog';
import * as smartlogDestinationLocal from '@push.rocks/smartlog-destination-local'; import * as smartlogDestinationLocal from '@push.rocks/smartlog-destination-local';
import * as smartpath from '@push.rocks/smartpath'; import * as smartpath from '@push.rocks/smartpath';
@@ -15,8 +15,8 @@ import * as smartsystem from '@push.rocks/smartsystem';
export { export {
lik, lik,
smartfile,
smartfm, smartfm,
smartfs,
smartlog, smartlog,
smartlogDestinationLocal, smartlogDestinationLocal,
smartpath, smartpath,
+4 -4
View File
@@ -5,10 +5,10 @@
"target": "ES2022", "target": "ES2022",
"module": "NodeNext", "module": "NodeNext",
"moduleResolution": "NodeNext", "moduleResolution": "NodeNext",
"noImplicitAny": true,
"esModuleInterop": true, "esModuleInterop": true,
"verbatimModuleSyntax": true "verbatimModuleSyntax": true,
"types": ["node"]
}, },
"exclude": [ "exclude": ["dist_*/**/*.d.ts"]
"dist_*/**/*.d.ts"
]
} }