Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
119f20915e | |||
ce1fa6640b | |||
8957e03445 | |||
3df86bee10 | |||
65326710ab | |||
2e174c9f55 | |||
9e42910456 | |||
ff85cee528 | |||
2a9fff0185 | |||
67689d79bd |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartdaemon",
|
"name": "@pushrocks/smartdaemon",
|
||||||
"version": "1.0.13",
|
"version": "1.0.18",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartdaemon",
|
"name": "@pushrocks/smartdaemon",
|
||||||
"version": "1.0.13",
|
"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",
|
||||||
|
@ -77,4 +77,8 @@ export class SmartDaemonService implements ISmartDaemonServiceConstructorOptions
|
|||||||
public async delete() {
|
public async delete() {
|
||||||
await this.smartdaemonRef.systemdManager.deleteService(this);
|
await this.smartdaemonRef.systemdManager.deleteService(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async reload() {
|
||||||
|
await this.smartdaemonRef.systemdManager.reload();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,8 +35,4 @@ export class SmartDaemon {
|
|||||||
await serviceToAdd.save();
|
await serviceToAdd.save();
|
||||||
return serviceToAdd;
|
return serviceToAdd;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async init() {
|
|
||||||
await this.systemdManager.init();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -6,16 +6,21 @@ import { ISmartDaemonServiceConstructorOptions, SmartDaemonService } from './sma
|
|||||||
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;
|
||||||
@ -75,23 +80,20 @@ export class SmartDaemonSystemdManager {
|
|||||||
public async startService(serviceArg: SmartDaemonService) {
|
public async startService(serviceArg: SmartDaemonService) {
|
||||||
if (await this.checkElegibility()) {
|
if (await this.checkElegibility()) {
|
||||||
await this.execute(
|
await this.execute(
|
||||||
`systemctl start ${SmartDaemonSystemdManager.createFilePathFromServiceName(serviceArg.name)}`
|
`systemctl start ${SmartDaemonSystemdManager.createServiceNameFromServiceName(serviceArg.name)}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public async stopService(serviceArg: SmartDaemonService) {
|
public async stopService(serviceArg: SmartDaemonService) {
|
||||||
if (await this.checkElegibility()) {
|
if (await this.checkElegibility()) {
|
||||||
await this.execute(
|
await this.execute(
|
||||||
`systemctl stop ${SmartDaemonSystemdManager.createFilePathFromServiceName(serviceArg.name)}`
|
`systemctl stop ${SmartDaemonSystemdManager.createServiceNameFromServiceName(serviceArg.name)}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async saveService(serviceArg: SmartDaemonService) {
|
public async saveService(serviceArg: SmartDaemonService) {
|
||||||
if (await this.checkElegibility()) {
|
if (await this.checkElegibility()) {
|
||||||
if (serviceArg.alreadyExists) {
|
|
||||||
this.stopService(serviceArg);
|
|
||||||
}
|
|
||||||
await plugins.smartfile.memory.toFs(
|
await plugins.smartfile.memory.toFs(
|
||||||
this.smartdaemonRef.templateManager.generateUnitFileForService(serviceArg),
|
this.smartdaemonRef.templateManager.generateUnitFileForService(serviceArg),
|
||||||
SmartDaemonSystemdManager.createFilePathFromServiceName(serviceArg.name)
|
SmartDaemonSystemdManager.createFilePathFromServiceName(serviceArg.name)
|
||||||
@ -102,7 +104,7 @@ export class SmartDaemonSystemdManager {
|
|||||||
public async deleteService(serviceArg: SmartDaemonService) {
|
public async deleteService(serviceArg: SmartDaemonService) {
|
||||||
if (await this.checkElegibility()) {
|
if (await this.checkElegibility()) {
|
||||||
await plugins.smartfile.fs.remove(
|
await plugins.smartfile.fs.remove(
|
||||||
SmartDaemonSystemdManager.createFilePathFromServiceName(serviceArg.name)
|
SmartDaemonSystemdManager.createServiceNameFromServiceName(serviceArg.name)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -110,18 +112,27 @@ export class SmartDaemonSystemdManager {
|
|||||||
public async enableService(serviceArg: SmartDaemonService) {
|
public async enableService(serviceArg: SmartDaemonService) {
|
||||||
if (await this.checkElegibility()) {
|
if (await this.checkElegibility()) {
|
||||||
await this.saveService(serviceArg);
|
await this.saveService(serviceArg);
|
||||||
|
if (serviceArg.alreadyExists) {
|
||||||
|
await this.execute(`systemctl daemon-reload`);
|
||||||
|
}
|
||||||
await this.execute(
|
await this.execute(
|
||||||
`systemctl enable ${SmartDaemonSystemdManager.createFileNameFromServiceName(serviceArg.name)}`
|
`systemctl enable ${SmartDaemonSystemdManager.createServiceNameFromServiceName(serviceArg.name)}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public async disableService(serviceArg: SmartDaemonService) {
|
public async disableService(serviceArg: SmartDaemonService) {
|
||||||
if (await this.checkElegibility()) {
|
if (await this.checkElegibility()) {
|
||||||
await this.execute(
|
await this.execute(
|
||||||
`systemctl disable ${SmartDaemonSystemdManager.createFileNameFromServiceName(serviceArg.name)}`
|
`systemctl disable ${SmartDaemonSystemdManager.createServiceNameFromServiceName(serviceArg.name)}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async init() {}
|
public async reload() {
|
||||||
|
if (await this.checkElegibility()) {
|
||||||
|
await this.execute(
|
||||||
|
`systemctl daemon-reload`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user