Compare commits

...

2 Commits

Author SHA1 Message Date
jkunz 704d8328ef v2.1.1
Default (tags) / security (push) Failing after 1s
Default (tags) / test (push) Failing after 1s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2026-05-01 15:24:08 +00:00
jkunz ddb77fd37d fix(systemdmanager): migrate systemd file operations to smartfs and tighten TypeScript safety 2026-05-01 15:24:08 +00:00
12 changed files with 2570 additions and 3271 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
## 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)
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)
Copyright (c) 2017-2019, braces lab
The MIT License (MIT)
Copyright (c) 2026 Task Venture Capital GmbH
Permission is hereby granted, free of charge, to any person obtaining a copy
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
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
SOFTWARE.
SOFTWARE.
+14 -8
View File
@@ -1,5 +1,5 @@
{
"gitzone": {
"@git.zone/cli": {
"projectType": "npm",
"module": {
"githost": "code.foss.global",
@@ -8,7 +8,6 @@
"description": "Start scripts as long running daemons and manage them.",
"npmPackagename": "@push.rocks/smartdaemon",
"license": "MIT",
"projectDomain": "push.rocks",
"keywords": [
"daemon",
"service management",
@@ -18,13 +17,20 @@
"system administration",
"background services"
]
},
"release": {
"registries": [
"https://verdaccio.lossless.digital",
"https://registry.npmjs.org"
],
"accessLevel": "public"
}
},
"npmci": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
},
"tsdoc": {
"@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"
}
}
}
+37 -31
View File
@@ -1,32 +1,51 @@
{
"name": "@push.rocks/smartdaemon",
"version": "2.1.0",
"version": "2.1.1",
"private": false,
"description": "Start scripts as long running daemons and manage them.",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"author": "Lossless GmbH",
"type": "module",
"author": "Task Venture Capital GmbH <hello@task.vc>",
"license": "MIT",
"scripts": {
"test": "(tstest test/ --verbose --logfile --timeout 60)",
"build": "(tsbuild --web --allowimplicitany)",
"test": "tstest test/ --verbose --timeout 60",
"build": "tsbuild --web",
"format": "gitzone format",
"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": {
"@git.zone/tsbuild": "^2.6.7",
"@git.zone/tsrun": "^1.2.44",
"@git.zone/tstest": "^2.3.5",
"@types/node": "^22.13.8"
"@git.zone/tsbuild": "^4.4.0",
"@git.zone/tsrun": "^2.0.3",
"@git.zone/tstest": "^3.6.3",
"@types/node": "^25.6.0"
},
"dependencies": {
"@push.rocks/lik": "^6.2.2",
"@push.rocks/smartfile": "^11.2.7",
"@push.rocks/smartfm": "^2.0.4",
"@push.rocks/smartlog": "^3.1.8",
"@push.rocks/smartlog-destination-local": "^9.0.1",
"@push.rocks/lik": "^6.4.1",
"@push.rocks/smartfm": "^2.2.2",
"@push.rocks/smartfs": "^1.5.1",
"@push.rocks/smartlog": "^3.2.2",
"@push.rocks/smartlog-destination-local": "^9.0.2",
"@push.rocks/smartpath": "^6.0.0",
"@push.rocks/smartshell": "^3.3.0",
"@push.rocks/smartsystem": "^3.0.7"
"@push.rocks/smartshell": "^3.3.8",
"@push.rocks/smartsystem": "^3.0.8"
},
"files": [
"ts/**/*",
@@ -37,26 +56,13 @@
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
".smartconfig.json",
"license",
"npmextra.json",
"readme.md"
],
"browserslist": [
"last 1 chrome versions"
],
"type": "module",
"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"
"packageManager": "pnpm@10.28.2"
}
+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 () => {
testSmartdaemon.addService({
testSmartdaemon.systemdManager.getServices = async () => [];
testSmartdaemon.systemdManager.saveService = async () => {};
const testService = await testSmartdaemon.addService({
name: 'npmversion',
version: 'x.x.x',
command: 'npm -v',
description: 'displays the npm version',
workingDir: plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
});
expect(testService.name).toEqual('npmversion');
});
export default tap.start();
+1 -1
View File
@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartdaemon',
version: '2.1.0',
version: '2.1.1',
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
) {
const service = new SmartDaemonService(smartdaemonRef);
for (const key of Object.keys(optionsArg)) {
service[key] = optionsArg[key];
}
Object.assign(service, optionsArg);
service.options = optionsArg;
return service;
}
public options: ISmartDaemonServiceConstructorOptions;
public options!: ISmartDaemonServiceConstructorOptions;
public alreadyExists = false;
public name: string;
public version: string;
public command: string;
public workingDir: string;
public description: string;
public name!: string;
public version!: string;
public command!: string;
public workingDir!: string;
public description!: string;
public user?: string;
public group?: string;
+9 -9
View File
@@ -29,6 +29,7 @@ export class SmartDaemonSystemdManager {
public smartdaemonRef: SmartDaemon;
public smartshellInstance: plugins.smartshell.Smartshell;
public smartsystem: plugins.smartsystem.Smartsystem;
public smartFs: plugins.smartfs.SmartFs;
public shouldExecute: boolean = false;
public isRoot: boolean = false;
@@ -40,6 +41,7 @@ export class SmartDaemonSystemdManager {
executor: 'bash',
});
this.smartsystem = new plugins.smartsystem.Smartsystem();
this.smartFs = new plugins.smartfs.SmartFs(new plugins.smartfs.SmartFsProviderNode());
this.sudoPassword = sudoPasswordArg;
// Check if we're running as root
@@ -85,7 +87,7 @@ export class SmartDaemonSystemdManager {
try {
await this.smartshellInstance.exec(commandArg);
} 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 error;
@@ -102,12 +104,10 @@ export class SmartDaemonSystemdManager {
const smartfmInstance = new plugins.smartfm.Smartfm({
fmType: 'yaml',
});
const availableServices = await plugins.smartfile.fs.fileTreeToObject(
paths.systemdDir,
'smartdaemon_*.service'
);
const availableServices = await this.smartFs.directory(paths.systemdDir).filter('smartdaemon_*.service').list();
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;
const service = await SmartDaemonService.createFromOptions(this.smartdaemonRef, data);
service.alreadyExists = true;
@@ -143,11 +143,11 @@ export class SmartDaemonSystemdManager {
if (this.isRoot) {
// 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 {
// Use sudo to write when not root
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(`chmod 644 ${targetPath}`); // execute() will add sudo
}
@@ -159,7 +159,7 @@ export class SmartDaemonSystemdManager {
const filePath = SmartDaemonSystemdManager.createFilePathFromServiceName(serviceArg.name);
if (this.isRoot) {
await plugins.smartfile.fs.remove(filePath);
await this.smartFs.file(filePath).delete();
} else {
await this.execute(`rm ${filePath}`); // execute() will add sudo
}
+2 -2
View File
@@ -5,8 +5,8 @@ export { path };
// @pushrocks scope
import * as lik from '@push.rocks/lik';
import * as smartfile from '@push.rocks/smartfile';
import * as smartfm from '@push.rocks/smartfm';
import * as smartfs from '@push.rocks/smartfs';
import * as smartlog from '@push.rocks/smartlog';
import * as smartlogDestinationLocal from '@push.rocks/smartlog-destination-local';
import * as smartpath from '@push.rocks/smartpath';
@@ -15,8 +15,8 @@ import * as smartsystem from '@push.rocks/smartsystem';
export {
lik,
smartfile,
smartfm,
smartfs,
smartlog,
smartlogDestinationLocal,
smartpath,
+4 -4
View File
@@ -5,10 +5,10 @@
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"noImplicitAny": true,
"esModuleInterop": true,
"verbatimModuleSyntax": true
"verbatimModuleSyntax": true,
"types": ["node"]
},
"exclude": [
"dist_*/**/*.d.ts"
]
"exclude": ["dist_*/**/*.d.ts"]
}