2022-10-19 17:27:42 +00:00
|
|
|
import * as plugins from './smartdaemon.plugins.js';
|
|
|
|
import { SmartDaemonTemplateManager } from './smartdaemon.classes.templatemanager.js';
|
2021-01-30 00:41:40 +00:00
|
|
|
import {
|
2024-04-19 11:54:20 +00:00
|
|
|
type ISmartDaemonServiceConstructorOptions,
|
2021-01-30 00:41:40 +00:00
|
|
|
SmartDaemonService,
|
2022-10-19 17:27:42 +00:00
|
|
|
} from './smartdaemon.classes.service.js';
|
|
|
|
import { SmartDaemonSystemdManager } from './smartdaemon.classes.systemdmanager.js';
|
2019-09-03 09:29:14 +00:00
|
|
|
|
|
|
|
export class SmartDaemon {
|
2019-09-03 13:21:30 +00:00
|
|
|
public templateManager: SmartDaemonTemplateManager;
|
|
|
|
public systemdManager: SmartDaemonSystemdManager;
|
2019-09-03 09:29:14 +00:00
|
|
|
|
|
|
|
constructor() {
|
2019-09-03 13:21:30 +00:00
|
|
|
this.templateManager = new SmartDaemonTemplateManager(this);
|
|
|
|
this.systemdManager = new SmartDaemonSystemdManager(this);
|
2019-09-03 09:29:14 +00:00
|
|
|
}
|
|
|
|
|
2019-09-03 17:58:08 +00:00
|
|
|
/**
|
|
|
|
* adds a service
|
|
|
|
* @param nameArg
|
2021-01-30 00:41:40 +00:00
|
|
|
* @param commandArg
|
|
|
|
* @param workingDirectoryArg
|
2019-09-03 17:58:08 +00:00
|
|
|
*/
|
2021-01-30 00:41:40 +00:00
|
|
|
public async addService(
|
|
|
|
optionsArg: ISmartDaemonServiceConstructorOptions
|
|
|
|
): Promise<SmartDaemonService> {
|
2019-09-03 13:24:49 +00:00
|
|
|
let serviceToAdd: SmartDaemonService;
|
2019-09-05 09:15:17 +00:00
|
|
|
const existingServices = await this.systemdManager.getServices();
|
2021-01-30 00:41:40 +00:00
|
|
|
const existingService = existingServices.find((serviceArg) => {
|
2019-09-03 17:58:08 +00:00
|
|
|
return serviceArg.name === optionsArg.name;
|
2019-09-03 13:24:49 +00:00
|
|
|
});
|
|
|
|
if (!existingService) {
|
2019-09-03 17:58:08 +00:00
|
|
|
serviceToAdd = await SmartDaemonService.createFromOptions(this, optionsArg);
|
2019-09-03 13:24:49 +00:00
|
|
|
} else {
|
2019-09-03 17:58:08 +00:00
|
|
|
serviceToAdd = existingService;
|
|
|
|
Object.assign(serviceToAdd, optionsArg);
|
2019-09-03 13:24:49 +00:00
|
|
|
}
|
2019-09-03 20:09:30 +00:00
|
|
|
await serviceToAdd.save();
|
2019-09-03 13:24:49 +00:00
|
|
|
return serviceToAdd;
|
2019-09-03 20:09:30 +00:00
|
|
|
}
|
2019-09-03 13:21:30 +00:00
|
|
|
}
|