fix(core): update

This commit is contained in:
2019-09-03 15:21:30 +02:00
parent 513337355f
commit 49ebf991a2
9 changed files with 180 additions and 180 deletions

View File

@ -1,3 +1 @@
import * as plugins from './smartdaemon.plugins';
export let standardExport = 'Hi there! :) This is an exported string';
export * from './smartdaemon.classes.smartdaemon';

View File

@ -0,0 +1,53 @@
import * as plugins from './smartdaemon.plugins';
import * as paths from './smartdaemon.paths';
import { SmartDaemon } from './smartdaemon.classes.smartdaemon';
export interface SmartDaemonServiceConstructorOptions {
name: string;
command: string;
workingDir: string;
}
/**
* represents a service that is being spawned by SmartDaemon
*/
export class SmartDaemonService implements SmartDaemonServiceConstructorOptions {
public static async createFromOptions(smartdaemonRef: SmartDaemon, optionsArg: SmartDaemonServiceConstructorOptions) {
const service = new SmartDaemonService(smartdaemonRef);
for (const key of Object.keys(optionsArg)) {
service[key] = optionsArg[key];
}
}
public options: SmartDaemonServiceConstructorOptions;
public name: string;
public command: string;
public workingDir: string;
public smartdaemonRef: SmartDaemon;
constructor(smartdaemonRegfArg: SmartDaemon) {
this.smartdaemonRef = smartdaemonRegfArg;
}
/**
* enables the service
*/
public async enable() {
this.smartdaemonRef
}
/**
* disables the service
*/
public async disable() {
}
/**
* pauses the service
*/
public pause() {};
}

View File

@ -1,60 +1,29 @@
import * as plugins from './smartdaemon.plugins';
import { SmartDaemonTemplateManager } from './smartdaemon.classes.templatemanager';
import { SmartDaemonService } from './smartdaemon.classes.service';
import { SmartDaemonSystemdManager } from './smartdaemon.classes.systemdmanager';
const smartDaemonNamespace = 'smartdaemon_';
interface SmartDaemonConstructorOptions {
name: string;
scriptPath: string;
workingDir: string;
}
export class SmartDaemon {
private templateManager: SmartDaemonTemplateManager;
private smartshellInstance: plugins.smartshell.Smartshell;
private smartsystem: plugins.smartsystem.Smartsystem;
private shouldExecute: boolean = false;
public serviceMap: plugins.lik.Objectmap<SmartDaemonService>;
public templateManager: SmartDaemonTemplateManager;
public systemdManager: SmartDaemonSystemdManager;
constructor() {
this.templateManager = new SmartDaemonTemplateManager;
this.smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash'
});
this.smartsystem = new plugins.smartsystem.Smartsystem();
this.serviceMap = new plugins.lik.Objectmap<SmartDaemonService>();
this.templateManager = new SmartDaemonTemplateManager(this);
this.systemdManager = new SmartDaemonSystemdManager(this);
}
public async checkElegibility () {
if (await this.smartsystem.env.isLinuxAsync()) {
this.shouldExecute = true;
} else {
console.log('Smartdaemon can only be used on Linuc systems! Refusing to set up a service.');
this.shouldExecute = false;
}
return this.shouldExecute;
}
/**
* enables the service
*/
public async enable() {
public async addService(serviceName: string, workingDirectory): Promise<SmartDaemonService> {
const existingService = this.serviceMap.find(serviceArg => {
return serviceArg
})
};
/**
* disables the service
*/
public async disable() {
};
/**
* pauses the service
*/
public pause() {};
private async execute(commandArg: string) {
this.smartshellInstance.exec(commandArg);
public async init() {
await this.systemdManager.init();
}
}
}

View File

@ -0,0 +1,43 @@
import * as plugins from './smartdaemon.plugins';
import * as paths from './smartdaemon.paths';
import { SmartDaemon } from './smartdaemon.classes.smartdaemon';
export class SmartDaemonSystemdManager {
private smartDaemonNamespace = 'smartdaemon_';
public smartdaemonRef: SmartDaemon;
public smartshellInstance: plugins.smartshell.Smartshell;
public smartsystem: plugins.smartsystem.Smartsystem;
public shouldExecute: boolean = false;
constructor(smartdaemonRefArg: SmartDaemon) {
this.smartdaemonRef = smartdaemonRefArg;
this.smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash'
});
this.smartsystem = new plugins.smartsystem.Smartsystem();
}
public async checkElegibility() {
if (await this.smartsystem.env.isLinuxAsync()) {
this.shouldExecute = true;
} else {
console.log('Smartdaemon can only be used on Linuc systems! Refusing to set up a service.');
this.shouldExecute = false;
}
return this.shouldExecute;
}
public async execute(commandArg: string) {
(await this.checkElegibility()) ? await this.smartshellInstance.exec(commandArg) : null;
}
public async getServices () {
const availableServices = plugins.smartfile.fs.listAllItems(paths.systemdDir, new RegExp(`${this.smartDaemonNamespace}`));
}
public async init() {
};
}

View File

@ -1,11 +1,18 @@
import * as plugins from './smartdaemon.plugins';
import { SmartDaemon } from './smartdaemon.classes.smartdaemon';
export class SmartDaemonTemplateManager {
public smartdaemonRef: SmartDaemon;
constructor(smartdaemonRefArg: SmartDaemon) {
this.smartdaemonRef = smartdaemonRefArg;
}
public generateServiceTemplate = (optionsArg: {
serviceName: string;
description: string;
serviceVersion: string;
pathNodeJs: string;
command: string;
pathWorkkingDir;
pathJsFileToRun;
}) => {
@ -18,7 +25,7 @@ After=network.target
[Service]
Type=simple
ExecStart=${optionsArg.pathNodeJs} ${optionsArg.pathJsFileToRun}
ExecStart=/bin/bash -c "cd ${optionsArg.pathWorkkingDir} && ${optionsArg.command}"
WorkingDirectory=${optionsArg.pathWorkkingDir}
Restart=on-failure
LimitNOFILE=infinity
@ -30,5 +37,5 @@ Restart=always
[Install]
WantedBy=multi-user.target
`;
};
}
}

View File

@ -7,12 +7,16 @@ export {
};
// @pushrocks scope
import * as lik from '@pushrocks/lik';
import * as smartfile from '@pushrocks/smartfile';
import * as smartlog from '@pushrocks/smartlog';
import * as smartlogDestinationLocal from '@pushrocks/smartlog-destination-local';
import * as smartshell from '@pushrocks/smartshell';
import * as smartsystem from '@pushrocks/smartsystem';
export {
lik,
smartfile,
smartlog,
smartlogDestinationLocal,
smartshell,