smartdaemon/ts/smartdaemon.classes.smartdaemon.ts

45 lines
1.4 KiB
TypeScript
Raw Normal View History

2019-09-03 09:29:14 +00:00
import * as plugins from './smartdaemon.plugins';
import { SmartDaemonTemplateManager } from './smartdaemon.classes.templatemanager';
2019-09-03 17:58:08 +00:00
import { SmartDaemonService, SmartDaemonServiceConstructorOptions } from './smartdaemon.classes.service';
2019-09-03 13:21:30 +00:00
import { SmartDaemonSystemdManager } from './smartdaemon.classes.systemdmanager';
2019-09-03 09:29:14 +00:00
export class SmartDaemon {
2019-09-03 13:21:30 +00:00
public serviceMap: plugins.lik.Objectmap<SmartDaemonService>;
public templateManager: SmartDaemonTemplateManager;
public systemdManager: SmartDaemonSystemdManager;
2019-09-03 09:29:14 +00:00
constructor() {
2019-09-03 13:21:30 +00:00
this.serviceMap = new plugins.lik.Objectmap<SmartDaemonService>();
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
* @param commandArg
* @param workingDirectoryArg
*/
public async addService(optionsArg: SmartDaemonServiceConstructorOptions): Promise<SmartDaemonService> {
2019-09-03 13:24:49 +00:00
let serviceToAdd: SmartDaemonService;
2019-09-03 13:21:30 +00:00
const existingService = this.serviceMap.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);
await serviceToAdd.save();
2019-09-03 13:24:49 +00:00
}
return serviceToAdd;
2019-09-03 09:29:14 +00:00
};
2019-09-03 13:21:30 +00:00
public async init() {
await this.systemdManager.init();
2019-09-03 09:29:14 +00:00
}
2019-09-03 13:21:30 +00:00
}