fix(core): update

This commit is contained in:
2021-01-30 00:41:40 +00:00
parent 769d7d6419
commit 060f635989
14 changed files with 10601 additions and 792 deletions

View File

@ -14,7 +14,10 @@ export interface ISmartDaemonServiceConstructorOptions {
* represents a service that is being spawned by SmartDaemon
*/
export class SmartDaemonService implements ISmartDaemonServiceConstructorOptions {
public static async createFromOptions(smartdaemonRef: SmartDaemon, optionsArg: ISmartDaemonServiceConstructorOptions) {
public static async createFromOptions(
smartdaemonRef: SmartDaemon,
optionsArg: ISmartDaemonServiceConstructorOptions
) {
const service = new SmartDaemonService(smartdaemonRef);
for (const key of Object.keys(optionsArg)) {
service[key] = optionsArg[key];
@ -65,7 +68,6 @@ export class SmartDaemonService implements ISmartDaemonServiceConstructorOptions
await this.smartdaemonRef.systemdManager.stopService(this);
}
// Save and Delete
public async save() {
await this.smartdaemonRef.systemdManager.saveService(this);

View File

@ -1,10 +1,11 @@
import * as plugins from './smartdaemon.plugins';
import { SmartDaemonTemplateManager } from './smartdaemon.classes.templatemanager';
import { SmartDaemonService, ISmartDaemonServiceConstructorOptions } from './smartdaemon.classes.service';
import {
SmartDaemonService,
ISmartDaemonServiceConstructorOptions,
} from './smartdaemon.classes.service';
import { SmartDaemonSystemdManager } from './smartdaemon.classes.systemdmanager';
export class SmartDaemon {
public templateManager: SmartDaemonTemplateManager;
public systemdManager: SmartDaemonSystemdManager;
@ -17,13 +18,15 @@ export class SmartDaemon {
/**
* adds a service
* @param nameArg
* @param commandArg
* @param workingDirectoryArg
* @param commandArg
* @param workingDirectoryArg
*/
public async addService(optionsArg: ISmartDaemonServiceConstructorOptions): Promise<SmartDaemonService> {
public async addService(
optionsArg: ISmartDaemonServiceConstructorOptions
): Promise<SmartDaemonService> {
let serviceToAdd: SmartDaemonService;
const existingServices = await this.systemdManager.getServices();
const existingService = existingServices.find(serviceArg => {
const existingService = existingServices.find((serviceArg) => {
return serviceArg.name === optionsArg.name;
});
if (!existingService) {

View File

@ -1,21 +1,24 @@
import * as plugins from './smartdaemon.plugins';
import * as paths from './smartdaemon.paths';
import { SmartDaemon } from './smartdaemon.classes.smartdaemon';
import { ISmartDaemonServiceConstructorOptions, SmartDaemonService } from './smartdaemon.classes.service';
import {
ISmartDaemonServiceConstructorOptions,
SmartDaemonService,
} from './smartdaemon.classes.service';
export class SmartDaemonSystemdManager {
// STATIC
private static smartDaemonNamespace = 'smartdaemon';
public static createServiceNameFromServiceName (serviceNameArg: string) {
public static createServiceNameFromServiceName(serviceNameArg: string) {
return `${SmartDaemonSystemdManager.smartDaemonNamespace}_${serviceNameArg}`;
}
public static createFileNameFromServiceName (serviceNameArg: string) {
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)
@ -32,7 +35,7 @@ export class SmartDaemonSystemdManager {
constructor(smartdaemonRefArg: SmartDaemon) {
this.smartdaemonRef = smartdaemonRefArg;
this.smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash'
executor: 'bash',
});
this.smartsystem = new plugins.smartsystem.Smartsystem();
}
@ -60,7 +63,7 @@ export class SmartDaemonSystemdManager {
const existingServices: SmartDaemonService[] = [];
if (await this.checkElegibility()) {
const smartfmInstance = new plugins.smartfm.Smartfm({
fmType: 'yaml'
fmType: 'yaml',
});
const availableServices = await plugins.smartfile.fs.fileTreeToObject(
paths.systemdDir,
@ -80,14 +83,18 @@ export class SmartDaemonSystemdManager {
public async startService(serviceArg: SmartDaemonService) {
if (await this.checkElegibility()) {
await this.execute(
`systemctl start ${SmartDaemonSystemdManager.createServiceNameFromServiceName(serviceArg.name)}`
`systemctl start ${SmartDaemonSystemdManager.createServiceNameFromServiceName(
serviceArg.name
)}`
);
}
}
public async stopService(serviceArg: SmartDaemonService) {
if (await this.checkElegibility()) {
await this.execute(
`systemctl stop ${SmartDaemonSystemdManager.createServiceNameFromServiceName(serviceArg.name)}`
`systemctl stop ${SmartDaemonSystemdManager.createServiceNameFromServiceName(
serviceArg.name
)}`
);
}
}
@ -116,23 +123,25 @@ export class SmartDaemonSystemdManager {
await this.execute(`systemctl daemon-reload`);
}
await this.execute(
`systemctl enable ${SmartDaemonSystemdManager.createServiceNameFromServiceName(serviceArg.name)}`
`systemctl enable ${SmartDaemonSystemdManager.createServiceNameFromServiceName(
serviceArg.name
)}`
);
}
}
public async disableService(serviceArg: SmartDaemonService) {
if (await this.checkElegibility()) {
await this.execute(
`systemctl disable ${SmartDaemonSystemdManager.createServiceNameFromServiceName(serviceArg.name)}`
`systemctl disable ${SmartDaemonSystemdManager.createServiceNameFromServiceName(
serviceArg.name
)}`
);
}
}
public async reload() {
if (await this.checkElegibility()) {
await this.execute(
`systemctl daemon-reload`
);
await this.execute(`systemctl daemon-reload`);
}
}
}

View File

@ -37,5 +37,5 @@ Restart=always
[Install]
WantedBy=multi-user.target
`;
}
};
}

View File

@ -1,10 +1,7 @@
// node native scope
import * as path from 'path';
export {
path
};
export { path };
// @pushrocks scope
import * as lik from '@pushrocks/lik';
@ -15,14 +12,6 @@ import * as smartlogDestinationLocal from '@pushrocks/smartlog-destination-local
import * as smartshell from '@pushrocks/smartshell';
import * as smartsystem from '@pushrocks/smartsystem';
export {
lik,
smartfile,
smartfm,
smartlog,
smartlogDestinationLocal,
smartshell,
smartsystem
};
export { lik, smartfile, smartfm, smartlog, smartlogDestinationLocal, smartshell, smartsystem };
// third party

View File

@ -7,9 +7,9 @@ export const logger = new plugins.smartlog.Smartlog({
containerName: 'Some Containername',
environment: 'local',
runtime: 'node',
zone: 'gitzone'
zone: 'gitzone',
},
minimumLogLevel: 'silly'
minimumLogLevel: 'silly',
});
logger.addLogDestination(new plugins.smartlogDestinationLocal.DestinationLocal());