Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
119f20915e | |||
ce1fa6640b | |||
8957e03445 | |||
3df86bee10 | |||
65326710ab | |||
2e174c9f55 | |||
9e42910456 | |||
ff85cee528 | |||
2a9fff0185 | |||
67689d79bd | |||
f8c851de97 | |||
09e9d8c190 | |||
80f5df3317 | |||
6cf3ff6e83 | |||
ceb30c7ac2 | |||
0df90eec5d |
53
package-lock.json
generated
53
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartdaemon",
|
"name": "@pushrocks/smartdaemon",
|
||||||
"version": "1.0.10",
|
"version": "1.0.18",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -215,6 +215,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@pushrocks/smartfm": {
|
||||||
|
"version": "2.0.4",
|
||||||
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartfm/-/smartfm-2.0.4.tgz",
|
||||||
|
"integrity": "sha512-QYxmIGhRfnE57rTCjsDBilPTrO/3VmajDxQt5z14pxAm9CeZypyGc4N6+Ts3KT1VGbs68NzCsGOM5ZYJW0Wmfg==",
|
||||||
|
"requires": {
|
||||||
|
"gray-matter": "^4.0.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@pushrocks/smartlog": {
|
"@pushrocks/smartlog": {
|
||||||
"version": "2.0.19",
|
"version": "2.0.19",
|
||||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartlog/-/smartlog-2.0.19.tgz",
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartlog/-/smartlog-2.0.19.tgz",
|
||||||
@ -770,6 +778,14 @@
|
|||||||
"strip-eof": "^1.0.0"
|
"strip-eof": "^1.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"extend-shallow": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://verdaccio.lossless.one/extend-shallow/-/extend-shallow-2.0.1.tgz",
|
||||||
|
"integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=",
|
||||||
|
"requires": {
|
||||||
|
"is-extendable": "^0.1.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"figures": {
|
"figures": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://verdaccio.lossless.one/figures/-/figures-3.0.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/figures/-/figures-3.0.0.tgz",
|
||||||
@ -850,6 +866,17 @@
|
|||||||
"resolved": "https://verdaccio.lossless.one/graceful-fs/-/graceful-fs-4.2.2.tgz",
|
"resolved": "https://verdaccio.lossless.one/graceful-fs/-/graceful-fs-4.2.2.tgz",
|
||||||
"integrity": "sha512-IItsdsea19BoLC7ELy13q1iJFNmd7ofZH5+X/pJr90/nRoPEX0DJo1dHDbgtYWOhJhcCgMDTOw84RZ72q6lB+Q=="
|
"integrity": "sha512-IItsdsea19BoLC7ELy13q1iJFNmd7ofZH5+X/pJr90/nRoPEX0DJo1dHDbgtYWOhJhcCgMDTOw84RZ72q6lB+Q=="
|
||||||
},
|
},
|
||||||
|
"gray-matter": {
|
||||||
|
"version": "4.0.2",
|
||||||
|
"resolved": "https://verdaccio.lossless.one/gray-matter/-/gray-matter-4.0.2.tgz",
|
||||||
|
"integrity": "sha512-7hB/+LxrOjq/dd8APlK0r24uL/67w7SkYnfwhNFwg/VDIGWGmduTDYf3WNstLW2fbbmRwrDGCVSJ2isuf2+4Hw==",
|
||||||
|
"requires": {
|
||||||
|
"js-yaml": "^3.11.0",
|
||||||
|
"kind-of": "^6.0.2",
|
||||||
|
"section-matter": "^1.0.0",
|
||||||
|
"strip-bom-string": "^1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"has-flag": {
|
"has-flag": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://verdaccio.lossless.one/has-flag/-/has-flag-3.0.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/has-flag/-/has-flag-3.0.0.tgz",
|
||||||
@ -875,6 +902,11 @@
|
|||||||
"integrity": "sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA==",
|
"integrity": "sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"is-extendable": {
|
||||||
|
"version": "0.1.1",
|
||||||
|
"resolved": "https://verdaccio.lossless.one/is-extendable/-/is-extendable-0.1.1.tgz",
|
||||||
|
"integrity": "sha1-YrEQ4omkcUGOPsNqYX1HLjAd/Ik="
|
||||||
|
},
|
||||||
"is-fullwidth-code-point": {
|
"is-fullwidth-code-point": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://verdaccio.lossless.one/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz",
|
||||||
@ -930,6 +962,11 @@
|
|||||||
"graceful-fs": "^4.1.6"
|
"graceful-fs": "^4.1.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"kind-of": {
|
||||||
|
"version": "6.0.2",
|
||||||
|
"resolved": "https://verdaccio.lossless.one/kind-of/-/kind-of-6.0.2.tgz",
|
||||||
|
"integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA=="
|
||||||
|
},
|
||||||
"lcid": {
|
"lcid": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://verdaccio.lossless.one/lcid/-/lcid-2.0.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/lcid/-/lcid-2.0.0.tgz",
|
||||||
@ -1286,6 +1323,15 @@
|
|||||||
"resolved": "https://verdaccio.lossless.one/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
"resolved": "https://verdaccio.lossless.one/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
||||||
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
|
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
|
||||||
},
|
},
|
||||||
|
"section-matter": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://verdaccio.lossless.one/section-matter/-/section-matter-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-vfD3pmTzGpufjScBh50YHKzEu2lxBWhVEHsNGoEXmCmn2hKGfeNLYMzCJpe8cD7gqX7TJluOVpBkAequ6dgMmA==",
|
||||||
|
"requires": {
|
||||||
|
"extend-shallow": "^2.0.1",
|
||||||
|
"kind-of": "^6.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"semver": {
|
"semver": {
|
||||||
"version": "5.7.0",
|
"version": "5.7.0",
|
||||||
"resolved": "https://verdaccio.lossless.one/semver/-/semver-5.7.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/semver/-/semver-5.7.0.tgz",
|
||||||
@ -1405,6 +1451,11 @@
|
|||||||
"strip-bom": "^2.0.0"
|
"strip-bom": "^2.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"strip-bom-string": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://verdaccio.lossless.one/strip-bom-string/-/strip-bom-string-1.0.0.tgz",
|
||||||
|
"integrity": "sha1-5SEekiQ2n7uB1jOi8ABE3IztrZI="
|
||||||
|
},
|
||||||
"strip-eof": {
|
"strip-eof": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://verdaccio.lossless.one/strip-eof/-/strip-eof-1.0.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/strip-eof/-/strip-eof-1.0.0.tgz",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartdaemon",
|
"name": "@pushrocks/smartdaemon",
|
||||||
"version": "1.0.10",
|
"version": "1.0.18",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "start scripts as long running daemons and manage them",
|
"description": "start scripts as long running daemons and manage them",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
@ -23,6 +23,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/lik": "^3.0.11",
|
"@pushrocks/lik": "^3.0.11",
|
||||||
"@pushrocks/smartfile": "^7.0.4",
|
"@pushrocks/smartfile": "^7.0.4",
|
||||||
|
"@pushrocks/smartfm": "^2.0.4",
|
||||||
"@pushrocks/smartlog": "^2.0.19",
|
"@pushrocks/smartlog": "^2.0.19",
|
||||||
"@pushrocks/smartlog-destination-local": "^8.0.2",
|
"@pushrocks/smartlog-destination-local": "^8.0.2",
|
||||||
"@pushrocks/smartshell": "^2.0.25",
|
"@pushrocks/smartshell": "^2.0.25",
|
||||||
|
@ -10,9 +10,10 @@ tap.test('should create an instance of smartdaemon', async () => {
|
|||||||
|
|
||||||
tap.test('should create a service', async () => {
|
tap.test('should create a service', async () => {
|
||||||
testSmartdaemon.addService({
|
testSmartdaemon.addService({
|
||||||
|
name: 'npmversion',
|
||||||
|
version: 'x.x.x',
|
||||||
command: 'npm -v',
|
command: 'npm -v',
|
||||||
description: 'displays the npm version',
|
description: 'displays the npm version',
|
||||||
name: 'npmversion',
|
|
||||||
workingDir: __dirname
|
workingDir: __dirname
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -2,18 +2,19 @@ import * as plugins from './smartdaemon.plugins';
|
|||||||
import * as paths from './smartdaemon.paths';
|
import * as paths from './smartdaemon.paths';
|
||||||
import { SmartDaemon } from './smartdaemon.classes.smartdaemon';
|
import { SmartDaemon } from './smartdaemon.classes.smartdaemon';
|
||||||
|
|
||||||
export interface SmartDaemonServiceConstructorOptions {
|
export interface ISmartDaemonServiceConstructorOptions {
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
command: string;
|
command: string;
|
||||||
workingDir: string;
|
workingDir: string;
|
||||||
|
version: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* represents a service that is being spawned by SmartDaemon
|
* represents a service that is being spawned by SmartDaemon
|
||||||
*/
|
*/
|
||||||
export class SmartDaemonService implements SmartDaemonServiceConstructorOptions {
|
export class SmartDaemonService implements ISmartDaemonServiceConstructorOptions {
|
||||||
public static async createFromOptions(smartdaemonRef: SmartDaemon, optionsArg: SmartDaemonServiceConstructorOptions) {
|
public static async createFromOptions(smartdaemonRef: SmartDaemon, optionsArg: ISmartDaemonServiceConstructorOptions) {
|
||||||
const service = new SmartDaemonService(smartdaemonRef);
|
const service = new SmartDaemonService(smartdaemonRef);
|
||||||
for (const key of Object.keys(optionsArg)) {
|
for (const key of Object.keys(optionsArg)) {
|
||||||
service[key] = optionsArg[key];
|
service[key] = optionsArg[key];
|
||||||
@ -21,12 +22,14 @@ export class SmartDaemonService implements SmartDaemonServiceConstructorOptions
|
|||||||
return service;
|
return service;
|
||||||
}
|
}
|
||||||
|
|
||||||
public options: SmartDaemonServiceConstructorOptions;
|
public options: ISmartDaemonServiceConstructorOptions;
|
||||||
|
public alreadyExists = false;
|
||||||
|
|
||||||
public name: string;
|
public name: string;
|
||||||
public description: string;
|
public version: string;
|
||||||
public command: string;
|
public command: string;
|
||||||
public workingDir: string;
|
public workingDir: string;
|
||||||
|
public description: string;
|
||||||
|
|
||||||
public smartdaemonRef: SmartDaemon;
|
public smartdaemonRef: SmartDaemon;
|
||||||
|
|
||||||
@ -38,45 +41,44 @@ export class SmartDaemonService implements SmartDaemonServiceConstructorOptions
|
|||||||
* enables the service
|
* enables the service
|
||||||
*/
|
*/
|
||||||
public async enable() {
|
public async enable() {
|
||||||
await this.save();
|
await this.smartdaemonRef.systemdManager.enableService(this);
|
||||||
await this.smartdaemonRef.systemdManager.enableService(this.name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* disables the service
|
* disables the service
|
||||||
*/
|
*/
|
||||||
public async disable() {
|
public async disable() {
|
||||||
await this.smartdaemonRef.systemdManager.disableService(this.name);
|
await this.smartdaemonRef.systemdManager.disableService(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* starts a service
|
* starts a service
|
||||||
*/
|
*/
|
||||||
public async start() {
|
public async start() {
|
||||||
await this.smartdaemonRef.systemdManager.startService(this.name);
|
await this.smartdaemonRef.systemdManager.startService(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* stops a service
|
* stops a service
|
||||||
*/
|
*/
|
||||||
public async stop() {
|
public async stop() {
|
||||||
await this.smartdaemonRef.systemdManager.stopService(this.name);
|
await this.smartdaemonRef.systemdManager.stopService(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Save and Delete
|
// Save and Delete
|
||||||
public async save() {
|
public async save() {
|
||||||
await this.smartdaemonRef.systemdManager.saveService(this.name, this.smartdaemonRef.templateManager.generateServiceTemplate({
|
await this.smartdaemonRef.systemdManager.saveService(this);
|
||||||
command: this.command,
|
|
||||||
description: this.description,
|
|
||||||
pathWorkkingDir: this.workingDir,
|
|
||||||
serviceName: this.name,
|
|
||||||
serviceVersion: 'x.x.x'
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** */
|
/**
|
||||||
|
* deletes the service
|
||||||
|
*/
|
||||||
public async delete() {
|
public async delete() {
|
||||||
await this.smartdaemonRef.systemdManager.deleteService(this.name);
|
await this.smartdaemonRef.systemdManager.deleteService(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async reload() {
|
||||||
|
await this.smartdaemonRef.systemdManager.reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,15 @@
|
|||||||
import * as plugins from './smartdaemon.plugins';
|
import * as plugins from './smartdaemon.plugins';
|
||||||
import { SmartDaemonTemplateManager } from './smartdaemon.classes.templatemanager';
|
import { SmartDaemonTemplateManager } from './smartdaemon.classes.templatemanager';
|
||||||
import { SmartDaemonService, SmartDaemonServiceConstructorOptions } from './smartdaemon.classes.service';
|
import { SmartDaemonService, ISmartDaemonServiceConstructorOptions } from './smartdaemon.classes.service';
|
||||||
import { SmartDaemonSystemdManager } from './smartdaemon.classes.systemdmanager';
|
import { SmartDaemonSystemdManager } from './smartdaemon.classes.systemdmanager';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export class SmartDaemon {
|
export class SmartDaemon {
|
||||||
|
|
||||||
public serviceMap: plugins.lik.Objectmap<SmartDaemonService>;
|
|
||||||
public templateManager: SmartDaemonTemplateManager;
|
public templateManager: SmartDaemonTemplateManager;
|
||||||
public systemdManager: SmartDaemonSystemdManager;
|
public systemdManager: SmartDaemonSystemdManager;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.serviceMap = new plugins.lik.Objectmap<SmartDaemonService>();
|
|
||||||
this.templateManager = new SmartDaemonTemplateManager(this);
|
this.templateManager = new SmartDaemonTemplateManager(this);
|
||||||
this.systemdManager = new SmartDaemonSystemdManager(this);
|
this.systemdManager = new SmartDaemonSystemdManager(this);
|
||||||
}
|
}
|
||||||
@ -23,9 +20,10 @@ export class SmartDaemon {
|
|||||||
* @param commandArg
|
* @param commandArg
|
||||||
* @param workingDirectoryArg
|
* @param workingDirectoryArg
|
||||||
*/
|
*/
|
||||||
public async addService(optionsArg: SmartDaemonServiceConstructorOptions): Promise<SmartDaemonService> {
|
public async addService(optionsArg: ISmartDaemonServiceConstructorOptions): Promise<SmartDaemonService> {
|
||||||
let serviceToAdd: SmartDaemonService;
|
let serviceToAdd: SmartDaemonService;
|
||||||
const existingService = this.serviceMap.find(serviceArg => {
|
const existingServices = await this.systemdManager.getServices();
|
||||||
|
const existingService = existingServices.find(serviceArg => {
|
||||||
return serviceArg.name === optionsArg.name;
|
return serviceArg.name === optionsArg.name;
|
||||||
});
|
});
|
||||||
if (!existingService) {
|
if (!existingService) {
|
||||||
@ -37,8 +35,4 @@ export class SmartDaemon {
|
|||||||
await serviceToAdd.save();
|
await serviceToAdd.save();
|
||||||
return serviceToAdd;
|
return serviceToAdd;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async init() {
|
|
||||||
await this.systemdManager.init();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,26 @@
|
|||||||
import * as plugins from './smartdaemon.plugins';
|
import * as plugins from './smartdaemon.plugins';
|
||||||
import * as paths from './smartdaemon.paths';
|
import * as paths from './smartdaemon.paths';
|
||||||
import { SmartDaemon } from './smartdaemon.classes.smartdaemon';
|
import { SmartDaemon } from './smartdaemon.classes.smartdaemon';
|
||||||
|
import { ISmartDaemonServiceConstructorOptions, SmartDaemonService } from './smartdaemon.classes.service';
|
||||||
|
|
||||||
export class SmartDaemonSystemdManager {
|
export class SmartDaemonSystemdManager {
|
||||||
// STATIC
|
// STATIC
|
||||||
private static smartDaemonNamespace = 'smartdaemon_';
|
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(
|
return plugins.path.join(
|
||||||
paths.systemdDir,
|
paths.systemdDir,
|
||||||
SmartDaemonSystemdManager.createFileNameFromServiceName(serviceNameArg)
|
SmartDaemonSystemdManager.createFileNameFromServiceName(serviceNameArg)
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
public smartdaemonRef: SmartDaemon;
|
public smartdaemonRef: SmartDaemon;
|
||||||
@ -47,51 +53,86 @@ export class SmartDaemonSystemdManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets all services that are already present
|
||||||
|
*/
|
||||||
public async getServices() {
|
public async getServices() {
|
||||||
|
const existingServices: SmartDaemonService[] = [];
|
||||||
if (await this.checkElegibility()) {
|
if (await this.checkElegibility()) {
|
||||||
const availableServices = plugins.smartfile.fs.listAllItems(
|
const smartfmInstance = new plugins.smartfm.Smartfm({
|
||||||
|
fmType: 'yaml'
|
||||||
|
});
|
||||||
|
const availableServices = await plugins.smartfile.fs.fileTreeToObject(
|
||||||
paths.systemdDir,
|
paths.systemdDir,
|
||||||
new RegExp(`${SmartDaemonSystemdManager.smartDaemonNamespace}`)
|
'smartdaemon_*.service'
|
||||||
|
);
|
||||||
|
for (const serviceFile of availableServices) {
|
||||||
|
const data = smartfmInstance.parseFromComments('# ', serviceFile.contentBuffer.toString())
|
||||||
|
.data as ISmartDaemonServiceConstructorOptions;
|
||||||
|
const service = await SmartDaemonService.createFromOptions(this.smartdaemonRef, data);
|
||||||
|
service.alreadyExists = true;
|
||||||
|
existingServices.push(service);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return existingServices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async startService(serviceArg: SmartDaemonService) {
|
||||||
|
if (await this.checkElegibility()) {
|
||||||
|
await this.execute(
|
||||||
|
`systemctl start ${SmartDaemonSystemdManager.createServiceNameFromServiceName(serviceArg.name)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public async stopService(serviceArg: SmartDaemonService) {
|
||||||
|
if (await this.checkElegibility()) {
|
||||||
|
await this.execute(
|
||||||
|
`systemctl stop ${SmartDaemonSystemdManager.createServiceNameFromServiceName(serviceArg.name)}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async startService(serviceNameArg: string) {
|
public async saveService(serviceArg: SmartDaemonService) {
|
||||||
if (await this.checkElegibility()) {
|
|
||||||
await this.execute(`systemctl start ${SmartDaemonSystemdManager.createFilePathFromServiceName(serviceNameArg)}`);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
public async stopService(serviceNameArg: string) {
|
|
||||||
if (await this.checkElegibility()) {
|
|
||||||
await this.execute(`systemctl stop ${SmartDaemonSystemdManager.createFilePathFromServiceName(serviceNameArg)}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async saveService(serviceNameArg: string, serviceFileString: string) {
|
|
||||||
if (await this.checkElegibility()) {
|
if (await this.checkElegibility()) {
|
||||||
await plugins.smartfile.memory.toFs(
|
await plugins.smartfile.memory.toFs(
|
||||||
serviceFileString,
|
this.smartdaemonRef.templateManager.generateUnitFileForService(serviceArg),
|
||||||
SmartDaemonSystemdManager.createFilePathFromServiceName(serviceNameArg)
|
SmartDaemonSystemdManager.createFilePathFromServiceName(serviceArg.name)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async deleteService(serviceName: string) {
|
public async deleteService(serviceArg: SmartDaemonService) {
|
||||||
if (await this.checkElegibility()) {
|
if (await this.checkElegibility()) {
|
||||||
await plugins.smartfile.fs.remove(SmartDaemonSystemdManager.createFilePathFromServiceName(serviceName));
|
await plugins.smartfile.fs.remove(
|
||||||
|
SmartDaemonSystemdManager.createServiceNameFromServiceName(serviceArg.name)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async enableService(serviceName: string) {
|
public async enableService(serviceArg: SmartDaemonService) {
|
||||||
if (await this.checkElegibility()) {
|
if (await this.checkElegibility()) {
|
||||||
await this.execute(`systemctl enable ${SmartDaemonSystemdManager.createFileNameFromServiceName(serviceName)}`);
|
await this.saveService(serviceArg);
|
||||||
|
if (serviceArg.alreadyExists) {
|
||||||
|
await this.execute(`systemctl daemon-reload`);
|
||||||
|
}
|
||||||
|
await this.execute(
|
||||||
|
`systemctl enable ${SmartDaemonSystemdManager.createServiceNameFromServiceName(serviceArg.name)}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public async disableService(serviceName: string) {
|
public async disableService(serviceArg: SmartDaemonService) {
|
||||||
if (await this.checkElegibility()) {
|
if (await this.checkElegibility()) {
|
||||||
await this.execute(`systemctl disable ${SmartDaemonSystemdManager.createFileNameFromServiceName(serviceName)}`);
|
await this.execute(
|
||||||
|
`systemctl disable ${SmartDaemonSystemdManager.createServiceNameFromServiceName(serviceArg.name)}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async init() {}
|
public async reload() {
|
||||||
|
if (await this.checkElegibility()) {
|
||||||
|
await this.execute(
|
||||||
|
`systemctl daemon-reload`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import * as plugins from './smartdaemon.plugins';
|
import * as plugins from './smartdaemon.plugins';
|
||||||
import { SmartDaemon } from './smartdaemon.classes.smartdaemon';
|
import { SmartDaemon } from './smartdaemon.classes.smartdaemon';
|
||||||
|
import { SmartDaemonService } from './smartdaemon.classes.service';
|
||||||
|
|
||||||
export class SmartDaemonTemplateManager {
|
export class SmartDaemonTemplateManager {
|
||||||
public smartdaemonRef: SmartDaemon;
|
public smartdaemonRef: SmartDaemon;
|
||||||
@ -8,24 +9,23 @@ export class SmartDaemonTemplateManager {
|
|||||||
this.smartdaemonRef = smartdaemonRefArg;
|
this.smartdaemonRef = smartdaemonRefArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public generateServiceTemplate = (optionsArg: {
|
public generateUnitFileForService = (serviceArg: SmartDaemonService) => {
|
||||||
serviceName: string;
|
return `# ---
|
||||||
description: string;
|
# name: ${serviceArg.name}
|
||||||
serviceVersion: string;
|
# version: ${serviceArg.version}
|
||||||
command: string;
|
# description: ${serviceArg.description}
|
||||||
pathWorkkingDir;
|
# command: ${serviceArg.command}
|
||||||
}) => {
|
# workingDir: ${serviceArg.workingDir}
|
||||||
return `
|
# ---
|
||||||
# servicVersion: ${optionsArg.serviceVersion}
|
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=${optionsArg.description}
|
Description=${serviceArg.description}
|
||||||
Requires=network.target
|
Requires=network.target
|
||||||
After=network.target
|
After=network.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
ExecStart=/bin/bash -c "cd ${optionsArg.pathWorkkingDir} && ${optionsArg.command}"
|
ExecStart=/bin/bash -c "cd ${serviceArg.workingDir} && ${serviceArg.command}"
|
||||||
WorkingDirectory=${optionsArg.pathWorkkingDir}
|
WorkingDirectory=${serviceArg.workingDir}
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
LimitNOFILE=infinity
|
LimitNOFILE=infinity
|
||||||
LimitCORE=infinity
|
LimitCORE=infinity
|
||||||
|
@ -9,6 +9,7 @@ export {
|
|||||||
// @pushrocks scope
|
// @pushrocks scope
|
||||||
import * as lik from '@pushrocks/lik';
|
import * as lik from '@pushrocks/lik';
|
||||||
import * as smartfile from '@pushrocks/smartfile';
|
import * as smartfile from '@pushrocks/smartfile';
|
||||||
|
import * as smartfm from '@pushrocks/smartfm';
|
||||||
import * as smartlog from '@pushrocks/smartlog';
|
import * as smartlog from '@pushrocks/smartlog';
|
||||||
import * as smartlogDestinationLocal from '@pushrocks/smartlog-destination-local';
|
import * as smartlogDestinationLocal from '@pushrocks/smartlog-destination-local';
|
||||||
import * as smartshell from '@pushrocks/smartshell';
|
import * as smartshell from '@pushrocks/smartshell';
|
||||||
@ -17,6 +18,7 @@ import * as smartsystem from '@pushrocks/smartsystem';
|
|||||||
export {
|
export {
|
||||||
lik,
|
lik,
|
||||||
smartfile,
|
smartfile,
|
||||||
|
smartfm,
|
||||||
smartlog,
|
smartlog,
|
||||||
smartlogDestinationLocal,
|
smartlogDestinationLocal,
|
||||||
smartshell,
|
smartshell,
|
||||||
|
Reference in New Issue
Block a user