2019-09-03 09:29:14 +00:00
|
|
|
import * as plugins from './smartdaemon.plugins';
|
|
|
|
import { SmartDaemonTemplateManager } from './smartdaemon.classes.templatemanager';
|
2019-09-05 09:15:17 +00:00
|
|
|
import { SmartDaemonService, ISmartDaemonServiceConstructorOptions } 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 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
|
|
|
|
* @param commandArg
|
|
|
|
* @param workingDirectoryArg
|
|
|
|
*/
|
2019-09-05 09:15:17 +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();
|
|
|
|
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
|
|
|
}
|