|
|
|
@ -6,16 +6,21 @@ import { ISmartDaemonServiceConstructorOptions, SmartDaemonService } from './sma
|
|
|
|
|
export class SmartDaemonSystemdManager {
|
|
|
|
|
// STATIC
|
|
|
|
|
private static smartDaemonNamespace = 'smartdaemon';
|
|
|
|
|
public static createFileNameFromServiceName = (serviceNameArg: string) => {
|
|
|
|
|
return `${SmartDaemonSystemdManager.smartDaemonNamespace}_${serviceNameArg}.service`;
|
|
|
|
|
|
|
|
|
|
public static createServiceNameFromServiceName (serviceNameArg: string) {
|
|
|
|
|
return `${SmartDaemonSystemdManager.smartDaemonNamespace}_${serviceNameArg}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static createFileNameFromServiceName (serviceNameArg: string) {
|
|
|
|
|
return `${SmartDaemonSystemdManager.createServiceNameFromServiceName(serviceNameArg)}.service`;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public static createFilePathFromServiceName = (serviceNameArg: string) => {
|
|
|
|
|
public static createFilePathFromServiceName (serviceNameArg: string) {
|
|
|
|
|
return plugins.path.join(
|
|
|
|
|
paths.systemdDir,
|
|
|
|
|
SmartDaemonSystemdManager.createFileNameFromServiceName(serviceNameArg)
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// INSTANCE
|
|
|
|
|
public smartdaemonRef: SmartDaemon;
|
|
|
|
@ -74,24 +79,24 @@ export class SmartDaemonSystemdManager {
|
|
|
|
|
|
|
|
|
|
public async startService(serviceArg: SmartDaemonService) {
|
|
|
|
|
if (await this.checkElegibility()) {
|
|
|
|
|
if (serviceArg.alreadyExists) {
|
|
|
|
|
await this.stopService(serviceArg);
|
|
|
|
|
}
|
|
|
|
|
await this.execute(
|
|
|
|
|
`systemctl start ${SmartDaemonSystemdManager.createFilePathFromServiceName(serviceArg.name)}`
|
|
|
|
|
`systemctl start ${SmartDaemonSystemdManager.createServiceNameFromServiceName(serviceArg.name)}`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public async stopService(serviceArg: SmartDaemonService) {
|
|
|
|
|
if (await this.checkElegibility()) {
|
|
|
|
|
await this.execute(
|
|
|
|
|
`systemctl stop ${SmartDaemonSystemdManager.createFilePathFromServiceName(serviceArg.name)}`
|
|
|
|
|
`systemctl stop ${SmartDaemonSystemdManager.createServiceNameFromServiceName(serviceArg.name)}`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async saveService(serviceArg: SmartDaemonService) {
|
|
|
|
|
if (await this.checkElegibility()) {
|
|
|
|
|
if (serviceArg.alreadyExists) {
|
|
|
|
|
this.stopService(serviceArg);
|
|
|
|
|
}
|
|
|
|
|
await plugins.smartfile.memory.toFs(
|
|
|
|
|
this.smartdaemonRef.templateManager.generateUnitFileForService(serviceArg),
|
|
|
|
|
SmartDaemonSystemdManager.createFilePathFromServiceName(serviceArg.name)
|
|
|
|
@ -102,7 +107,7 @@ export class SmartDaemonSystemdManager {
|
|
|
|
|
public async deleteService(serviceArg: SmartDaemonService) {
|
|
|
|
|
if (await this.checkElegibility()) {
|
|
|
|
|
await plugins.smartfile.fs.remove(
|
|
|
|
|
SmartDaemonSystemdManager.createFilePathFromServiceName(serviceArg.name)
|
|
|
|
|
SmartDaemonSystemdManager.createServiceNameFromServiceName(serviceArg.name)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -110,15 +115,18 @@ export class SmartDaemonSystemdManager {
|
|
|
|
|
public async enableService(serviceArg: SmartDaemonService) {
|
|
|
|
|
if (await this.checkElegibility()) {
|
|
|
|
|
await this.saveService(serviceArg);
|
|
|
|
|
if (serviceArg.alreadyExists) {
|
|
|
|
|
await this.execute(`systemctl daemon-reload`);
|
|
|
|
|
}
|
|
|
|
|
await this.execute(
|
|
|
|
|
`systemctl enable ${SmartDaemonSystemdManager.createFileNameFromServiceName(serviceArg.name)}`
|
|
|
|
|
`systemctl enable ${SmartDaemonSystemdManager.createServiceNameFromServiceName(serviceArg.name)}`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public async disableService(serviceArg: SmartDaemonService) {
|
|
|
|
|
if (await this.checkElegibility()) {
|
|
|
|
|
await this.execute(
|
|
|
|
|
`systemctl disable ${SmartDaemonSystemdManager.createFileNameFromServiceName(serviceArg.name)}`
|
|
|
|
|
`systemctl disable ${SmartDaemonSystemdManager.createServiceNameFromServiceName(serviceArg.name)}`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|