@push.rocks/smartdaemon 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ /**
2
+ * autocreated commitinfo by @pushrocks/commitinfo
3
+ */
4
+ export declare const commitinfo: {
5
+ name: string;
6
+ version: string;
7
+ description: string;
8
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * autocreated commitinfo by @pushrocks/commitinfo
3
+ */
4
+ export const commitinfo = {
5
+ name: '@pushrocks/smartdaemon',
6
+ version: '2.0.3',
7
+ description: 'start scripts as long running daemons and manage them'
8
+ };
9
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSx3QkFBd0I7SUFDOUIsT0FBTyxFQUFFLE9BQU87SUFDaEIsV0FBVyxFQUFFLHVEQUF1RDtDQUNyRSxDQUFBIn0=
@@ -0,0 +1 @@
1
+ export * from './smartdaemon.classes.smartdaemon.js';
@@ -0,0 +1,2 @@
1
+ export * from './smartdaemon.classes.smartdaemon.js';
2
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLHNDQUFzQyxDQUFDIn0=
@@ -0,0 +1,45 @@
1
+ import { SmartDaemon } from './smartdaemon.classes.smartdaemon.js';
2
+ export interface ISmartDaemonServiceConstructorOptions {
3
+ name: string;
4
+ description: string;
5
+ command: string;
6
+ workingDir: string;
7
+ version: string;
8
+ }
9
+ /**
10
+ * represents a service that is being spawned by SmartDaemon
11
+ */
12
+ export declare class SmartDaemonService implements ISmartDaemonServiceConstructorOptions {
13
+ static createFromOptions(smartdaemonRef: SmartDaemon, optionsArg: ISmartDaemonServiceConstructorOptions): Promise<SmartDaemonService>;
14
+ options: ISmartDaemonServiceConstructorOptions;
15
+ alreadyExists: boolean;
16
+ name: string;
17
+ version: string;
18
+ command: string;
19
+ workingDir: string;
20
+ description: string;
21
+ smartdaemonRef: SmartDaemon;
22
+ constructor(smartdaemonRegfArg: SmartDaemon);
23
+ /**
24
+ * enables the service
25
+ */
26
+ enable(): Promise<void>;
27
+ /**
28
+ * disables the service
29
+ */
30
+ disable(): Promise<void>;
31
+ /**
32
+ * starts a service
33
+ */
34
+ start(): Promise<void>;
35
+ /**
36
+ * stops a service
37
+ */
38
+ stop(): Promise<void>;
39
+ save(): Promise<void>;
40
+ /**
41
+ * deletes the service
42
+ */
43
+ delete(): Promise<void>;
44
+ reload(): Promise<void>;
45
+ }
@@ -0,0 +1,57 @@
1
+ import './smartdaemon.plugins.js';
2
+ import './smartdaemon.paths.js';
3
+ import './smartdaemon.classes.smartdaemon.js';
4
+ /**
5
+ * represents a service that is being spawned by SmartDaemon
6
+ */
7
+ export class SmartDaemonService {
8
+ constructor(smartdaemonRegfArg) {
9
+ this.alreadyExists = false;
10
+ this.smartdaemonRef = smartdaemonRegfArg;
11
+ }
12
+ static async createFromOptions(smartdaemonRef, optionsArg) {
13
+ const service = new SmartDaemonService(smartdaemonRef);
14
+ for (const key of Object.keys(optionsArg)) {
15
+ service[key] = optionsArg[key];
16
+ }
17
+ return service;
18
+ }
19
+ /**
20
+ * enables the service
21
+ */
22
+ async enable() {
23
+ await this.smartdaemonRef.systemdManager.enableService(this);
24
+ }
25
+ /**
26
+ * disables the service
27
+ */
28
+ async disable() {
29
+ await this.smartdaemonRef.systemdManager.disableService(this);
30
+ }
31
+ /**
32
+ * starts a service
33
+ */
34
+ async start() {
35
+ await this.smartdaemonRef.systemdManager.startService(this);
36
+ }
37
+ /**
38
+ * stops a service
39
+ */
40
+ async stop() {
41
+ await this.smartdaemonRef.systemdManager.stopService(this);
42
+ }
43
+ // Save and Delete
44
+ async save() {
45
+ await this.smartdaemonRef.systemdManager.saveService(this);
46
+ }
47
+ /**
48
+ * deletes the service
49
+ */
50
+ async delete() {
51
+ await this.smartdaemonRef.systemdManager.deleteService(this);
52
+ }
53
+ async reload() {
54
+ await this.smartdaemonRef.systemdManager.reload();
55
+ }
56
+ }
57
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYWVtb24uY2xhc3Nlcy5zZXJ2aWNlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRkYWVtb24uY2xhc3Nlcy5zZXJ2aWNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQXlCLDBCQUEwQixDQUFDO0FBQ3BELE9BQXVCLHdCQUF3QixDQUFDO0FBQ2hELE9BQTRCLHNDQUFzQyxDQUFDO0FBVW5FOztHQUVHO0FBQ0gsTUFBTSxPQUFPLGtCQUFrQjtJQXVCN0IsWUFBWSxrQkFBK0I7UUFWcEMsa0JBQWEsR0FBRyxLQUFLLENBQUM7UUFXM0IsSUFBSSxDQUFDLGNBQWMsR0FBRyxrQkFBa0IsQ0FBQztJQUMzQyxDQUFDO0lBeEJNLE1BQU0sQ0FBQyxLQUFLLENBQUMsaUJBQWlCLENBQ25DLGNBQTJCLEVBQzNCLFVBQWlEO1FBRWpELE1BQU0sT0FBTyxHQUFHLElBQUksa0JBQWtCLENBQUMsY0FBYyxDQUFDLENBQUM7UUFDdkQsS0FBSyxNQUFNLEdBQUcsSUFBSSxNQUFNLENBQUMsSUFBSSxDQUFDLFVBQVUsQ0FBQyxFQUFFO1lBQ3pDLE9BQU8sQ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BQyxNQUFNLEVBQUUsQ0FBQztJQUNwRCxDQUFDO0NBQ0YifQ==
@@ -0,0 +1,15 @@
1
+ import { SmartDaemonTemplateManager } from './smartdaemon.classes.templatemanager.js';
2
+ import { SmartDaemonService, ISmartDaemonServiceConstructorOptions } from './smartdaemon.classes.service.js';
3
+ import { SmartDaemonSystemdManager } from './smartdaemon.classes.systemdmanager.js';
4
+ export declare class SmartDaemon {
5
+ templateManager: SmartDaemonTemplateManager;
6
+ systemdManager: SmartDaemonSystemdManager;
7
+ constructor();
8
+ /**
9
+ * adds a service
10
+ * @param nameArg
11
+ * @param commandArg
12
+ * @param workingDirectoryArg
13
+ */
14
+ addService(optionsArg: ISmartDaemonServiceConstructorOptions): Promise<SmartDaemonService>;
15
+ }
@@ -0,0 +1,33 @@
1
+ import './smartdaemon.plugins.js';
2
+ import { SmartDaemonTemplateManager } from './smartdaemon.classes.templatemanager.js';
3
+ import { SmartDaemonService, } from './smartdaemon.classes.service.js';
4
+ import { SmartDaemonSystemdManager } from './smartdaemon.classes.systemdmanager.js';
5
+ export class SmartDaemon {
6
+ constructor() {
7
+ this.templateManager = new SmartDaemonTemplateManager(this);
8
+ this.systemdManager = new SmartDaemonSystemdManager(this);
9
+ }
10
+ /**
11
+ * adds a service
12
+ * @param nameArg
13
+ * @param commandArg
14
+ * @param workingDirectoryArg
15
+ */
16
+ async addService(optionsArg) {
17
+ let serviceToAdd;
18
+ const existingServices = await this.systemdManager.getServices();
19
+ const existingService = existingServices.find((serviceArg) => {
20
+ return serviceArg.name === optionsArg.name;
21
+ });
22
+ if (!existingService) {
23
+ serviceToAdd = await SmartDaemonService.createFromOptions(this, optionsArg);
24
+ }
25
+ else {
26
+ serviceToAdd = existingService;
27
+ Object.assign(serviceToAdd, optionsArg);
28
+ }
29
+ await serviceToAdd.save();
30
+ return serviceToAdd;
31
+ }
32
+ }
33
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYWVtb24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0FBQztTQUM3RTthQUFNO1lBQ0wsWUFBWSxHQUFHLGVBQWUsQ0FBQztZQUMvQixNQUFNLENBQUMsTUFBTSxDQUFDLFlBQVksRUFBRSxVQUFVLENBQUMsQ0FBQztTQUN6QztRQUNELE1BQU0sWUFBWSxDQUFDLElBQUksRUFBRSxDQUFDO1FBQzFCLE9BQU8sWUFBWSxDQUFDO0lBQ3RCLENBQUM7Q0FDRiJ9
@@ -0,0 +1,27 @@
1
+ import * as plugins from './smartdaemon.plugins.js';
2
+ import { SmartDaemon } from './smartdaemon.classes.smartdaemon.js';
3
+ import { SmartDaemonService } from './smartdaemon.classes.service.js';
4
+ export declare class SmartDaemonSystemdManager {
5
+ private static smartDaemonNamespace;
6
+ static createServiceNameFromServiceName(serviceNameArg: string): string;
7
+ static createFileNameFromServiceName(serviceNameArg: string): string;
8
+ static createFilePathFromServiceName(serviceNameArg: string): string;
9
+ smartdaemonRef: SmartDaemon;
10
+ smartshellInstance: plugins.smartshell.Smartshell;
11
+ smartsystem: plugins.smartsystem.Smartsystem;
12
+ shouldExecute: boolean;
13
+ constructor(smartdaemonRefArg: SmartDaemon);
14
+ checkElegibility(): Promise<boolean>;
15
+ execute(commandArg: string): Promise<void>;
16
+ /**
17
+ * gets all services that are already present
18
+ */
19
+ getServices(): Promise<SmartDaemonService[]>;
20
+ startService(serviceArg: SmartDaemonService): Promise<void>;
21
+ stopService(serviceArg: SmartDaemonService): Promise<void>;
22
+ saveService(serviceArg: SmartDaemonService): Promise<void>;
23
+ deleteService(serviceArg: SmartDaemonService): Promise<void>;
24
+ enableService(serviceArg: SmartDaemonService): Promise<void>;
25
+ disableService(serviceArg: SmartDaemonService): Promise<void>;
26
+ reload(): Promise<void>;
27
+ }
@@ -0,0 +1,100 @@
1
+ import * as plugins from './smartdaemon.plugins.js';
2
+ import * as paths from './smartdaemon.paths.js';
3
+ import './smartdaemon.classes.smartdaemon.js';
4
+ import { SmartDaemonService, } from './smartdaemon.classes.service.js';
5
+ export class SmartDaemonSystemdManager {
6
+ constructor(smartdaemonRefArg) {
7
+ this.shouldExecute = false;
8
+ this.smartdaemonRef = smartdaemonRefArg;
9
+ this.smartshellInstance = new plugins.smartshell.Smartshell({
10
+ executor: 'bash',
11
+ });
12
+ this.smartsystem = new plugins.smartsystem.Smartsystem();
13
+ }
14
+ // STATIC
15
+ static { this.smartDaemonNamespace = 'smartdaemon'; }
16
+ static createServiceNameFromServiceName(serviceNameArg) {
17
+ return `${SmartDaemonSystemdManager.smartDaemonNamespace}_${serviceNameArg}`;
18
+ }
19
+ static createFileNameFromServiceName(serviceNameArg) {
20
+ return `${SmartDaemonSystemdManager.createServiceNameFromServiceName(serviceNameArg)}.service`;
21
+ }
22
+ static createFilePathFromServiceName(serviceNameArg) {
23
+ return plugins.path.join(paths.systemdDir, SmartDaemonSystemdManager.createFileNameFromServiceName(serviceNameArg));
24
+ }
25
+ async checkElegibility() {
26
+ if (await this.smartsystem.env.isLinuxAsync()) {
27
+ this.shouldExecute = true;
28
+ }
29
+ else {
30
+ console.log('Smartdaemon can only be used on Linux systems! Refusing to set up a service.');
31
+ this.shouldExecute = false;
32
+ }
33
+ return this.shouldExecute;
34
+ }
35
+ async execute(commandArg) {
36
+ if (await this.checkElegibility()) {
37
+ await this.smartshellInstance.exec(commandArg);
38
+ }
39
+ }
40
+ /**
41
+ * gets all services that are already present
42
+ */
43
+ async getServices() {
44
+ const existingServices = [];
45
+ if (await this.checkElegibility()) {
46
+ const smartfmInstance = new plugins.smartfm.Smartfm({
47
+ fmType: 'yaml',
48
+ });
49
+ const availableServices = await plugins.smartfile.fs.fileTreeToObject(paths.systemdDir, 'smartdaemon_*.service');
50
+ for (const serviceFile of availableServices) {
51
+ const data = smartfmInstance.parseFromComments('# ', serviceFile.contentBuffer.toString())
52
+ .data;
53
+ const service = await SmartDaemonService.createFromOptions(this.smartdaemonRef, data);
54
+ service.alreadyExists = true;
55
+ existingServices.push(service);
56
+ }
57
+ }
58
+ return existingServices;
59
+ }
60
+ async startService(serviceArg) {
61
+ if (await this.checkElegibility()) {
62
+ await this.execute(`systemctl start ${SmartDaemonSystemdManager.createServiceNameFromServiceName(serviceArg.name)}`);
63
+ }
64
+ }
65
+ async stopService(serviceArg) {
66
+ if (await this.checkElegibility()) {
67
+ await this.execute(`systemctl stop ${SmartDaemonSystemdManager.createServiceNameFromServiceName(serviceArg.name)}`);
68
+ }
69
+ }
70
+ async saveService(serviceArg) {
71
+ if (await this.checkElegibility()) {
72
+ await plugins.smartfile.memory.toFs(this.smartdaemonRef.templateManager.generateUnitFileForService(serviceArg), SmartDaemonSystemdManager.createFilePathFromServiceName(serviceArg.name));
73
+ }
74
+ }
75
+ async deleteService(serviceArg) {
76
+ if (await this.checkElegibility()) {
77
+ await plugins.smartfile.fs.remove(SmartDaemonSystemdManager.createServiceNameFromServiceName(serviceArg.name));
78
+ }
79
+ }
80
+ async enableService(serviceArg) {
81
+ if (await this.checkElegibility()) {
82
+ await this.saveService(serviceArg);
83
+ if (serviceArg.alreadyExists) {
84
+ await this.execute(`systemctl daemon-reload`);
85
+ }
86
+ await this.execute(`systemctl enable ${SmartDaemonSystemdManager.createServiceNameFromServiceName(serviceArg.name)}`);
87
+ }
88
+ }
89
+ async disableService(serviceArg) {
90
+ if (await this.checkElegibility()) {
91
+ await this.execute(`systemctl disable ${SmartDaemonSystemdManager.createServiceNameFromServiceName(serviceArg.name)}`);
92
+ }
93
+ }
94
+ async reload() {
95
+ if (await this.checkElegibility()) {
96
+ await this.execute(`systemctl daemon-reload`);
97
+ }
98
+ }
99
+ }
100
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYWVtb24uY2xhc3Nlcy5zeXN0ZW1kbWFuYWdlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0ZGFlbW9uLmNsYXNzZXMuc3lzdGVtZG1hbmFnZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5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BQUksQ0FBQyxPQUFPLENBQ2hCLHFCQUFxQix5QkFBeUIsQ0FBQyxnQ0FBZ0MsQ0FDN0UsVUFBVSxDQUFDLElBQUksQ0FDaEIsRUFBRSxDQUNKLENBQUM7U0FDSDtJQUNILENBQUM7SUFFTSxLQUFLLENBQUMsTUFBTTtRQUNqQixJQUFJLE1BQU0sSUFBSSxDQUFDLGdCQUFnQixFQUFFLEVBQUU7WUFDakMsTUFBTSxJQUFJLENBQUMsT0FBTyxDQUFDLHlCQUF5QixDQUFDLENBQUM7U0FDL0M7SUFDSCxDQUFDIn0=
@@ -0,0 +1,7 @@
1
+ import { SmartDaemon } from './smartdaemon.classes.smartdaemon.js';
2
+ import { SmartDaemonService } from './smartdaemon.classes.service.js';
3
+ export declare class SmartDaemonTemplateManager {
4
+ smartdaemonRef: SmartDaemon;
5
+ constructor(smartdaemonRefArg: SmartDaemon);
6
+ generateUnitFileForService: (serviceArg: SmartDaemonService) => string;
7
+ }
@@ -0,0 +1,38 @@
1
+ import './smartdaemon.plugins.js';
2
+ import './smartdaemon.classes.smartdaemon.js';
3
+ import './smartdaemon.classes.service.js';
4
+ export class SmartDaemonTemplateManager {
5
+ constructor(smartdaemonRefArg) {
6
+ this.generateUnitFileForService = (serviceArg) => {
7
+ return `# ---
8
+ # name: ${serviceArg.name}
9
+ # version: ${serviceArg.version}
10
+ # description: ${serviceArg.description}
11
+ # command: ${serviceArg.command}
12
+ # workingDir: ${serviceArg.workingDir}
13
+ # ---
14
+ [Unit]
15
+ Description=${serviceArg.description}
16
+ Requires=network.target
17
+ After=network.target
18
+
19
+ [Service]
20
+ Type=simple
21
+ Environment=NODE_OPTIONS="--max_old_space_size=100"
22
+ ExecStart=/bin/bash -c "cd ${serviceArg.workingDir} && ${serviceArg.command}"
23
+ WorkingDirectory=${serviceArg.workingDir}
24
+ Restart=on-failure
25
+ LimitNOFILE=infinity
26
+ LimitCORE=infinity
27
+ StandardInput=null
28
+ StandardOutput=syslog
29
+ StandardError=syslog
30
+ Restart=always
31
+ [Install]
32
+ WantedBy=multi-user.target
33
+ `;
34
+ };
35
+ this.smartdaemonRef = smartdaemonRefArg;
36
+ }
37
+ }
38
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYWVtb24uY2xhc3Nlcy50ZW1wbGF0ZW1hbmFnZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGRhZW1vbi5jbGFzc2VzLnRlbXBsYXRlbWFuYWdlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUF5QiwwQkFBMEIsQ0FBQztBQUNwRCxPQUE0QixzQ0FBc0MsQ0FBQztBQUNuRSxPQUFtQyxrQ0FBa0MsQ0FBQztBQUV0RSxNQUFNLE9BQU8sMEJBQTBCO0lBR3JDLFlBQVksaUJBQThCO1FBSW5DLCtCQUEwQixHQUFHLENBQUMsVUFBOEIsRUFBRSxFQUFFO1lBQ3JFLE9BQU87VUFDRCxVQUFVLENBQUMsSUFBSTthQUNaLFVBQVUsQ0FBQyxPQUFPO2lCQUNkLFVBQVUsQ0FBQyxXQUFXO2FBQzFCLFVBQVUsQ0FBQyxPQUFPO2dCQUNmLFVBQVUsQ0FBQyxVQUFVOzs7Y0FHdkIsVUFBVSxDQUFDLFdBQVc7Ozs7Ozs7NkJBT1AsVUFBVSxDQUFDLFVBQVUsT0FBTyxVQUFVLENBQUMsT0FBTzttQkFDeEQsVUFBVSxDQUFDLFVBQVU7Ozs7Ozs7Ozs7Q0FVdkMsQ0FBQztRQUNBLENBQUMsQ0FBQztRQS9CQSxJQUFJLENBQUMsY0FBYyxHQUFHLGlCQUFpQixDQUFDO0lBQzFDLENBQUM7Q0ErQkYifQ==
@@ -0,0 +1,2 @@
1
+ export declare const packageDir: string;
2
+ export declare const systemdDir: string;
@@ -0,0 +1,4 @@
1
+ import * as plugins from './smartdaemon.plugins.js';
2
+ export const packageDir = plugins.path.join(plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url), '../');
3
+ export const systemdDir = plugins.path.join('/lib/systemd/system/');
4
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYWVtb24ucGF0aHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGRhZW1vbi5wYXRocy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssT0FBTyxNQUFNLDBCQUEwQixDQUFDO0FBRXBELE1BQU0sQ0FBQyxNQUFNLFVBQVUsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyx3QkFBd0IsQ0FBQyxNQUFNLENBQUMsSUFBSSxDQUFDLEdBQUcsQ0FBQyxFQUFFLEtBQUssQ0FBQyxDQUFDO0FBQ3BILE1BQU0sQ0FBQyxNQUFNLFVBQVUsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxzQkFBc0IsQ0FBQyxDQUFDIn0=
@@ -0,0 +1,11 @@
1
+ import * as path from 'path';
2
+ export { path };
3
+ import * as lik from '@pushrocks/lik';
4
+ import * as smartfile from '@pushrocks/smartfile';
5
+ import * as smartfm from '@pushrocks/smartfm';
6
+ import * as smartlog from '@pushrocks/smartlog';
7
+ import * as smartlogDestinationLocal from '@pushrocks/smartlog-destination-local';
8
+ import * as smartpath from '@pushrocks/smartpath';
9
+ import * as smartshell from '@pushrocks/smartshell';
10
+ import * as smartsystem from '@pushrocks/smartsystem';
11
+ export { lik, smartfile, smartfm, smartlog, smartlogDestinationLocal, smartpath, smartshell, smartsystem };
@@ -0,0 +1,15 @@
1
+ // node native scope
2
+ import * as path from 'path';
3
+ export { path };
4
+ // @pushrocks scope
5
+ import * as lik from '@pushrocks/lik';
6
+ import * as smartfile from '@pushrocks/smartfile';
7
+ import * as smartfm from '@pushrocks/smartfm';
8
+ import * as smartlog from '@pushrocks/smartlog';
9
+ import * as smartlogDestinationLocal from '@pushrocks/smartlog-destination-local';
10
+ import * as smartpath from '@pushrocks/smartpath';
11
+ import * as smartshell from '@pushrocks/smartshell';
12
+ import * as smartsystem from '@pushrocks/smartsystem';
13
+ export { lik, smartfile, smartfm, smartlog, smartlogDestinationLocal, smartpath, smartshell, smartsystem };
14
+ // third party
15
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYWVtb24ucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0ZGFlbW9uLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsb0JBQW9CO0FBQ3BCLE9BQU8sS0FBSyxJQUFJLE1BQU0sTUFBTSxDQUFDO0FBRTdCLE9BQU8sRUFBRSxJQUFJLEVBQUUsQ0FBQztBQUVoQixtQkFBbUI7QUFDbkIsT0FBTyxLQUFLLEdBQUcsTUFBTSxnQkFBZ0IsQ0FBQztBQUN0QyxPQUFPLEtBQUssU0FBUyxNQUFNLHNCQUFzQixDQUFDO0FBQ2xELE9BQU8sS0FBSyxPQUFPLE1BQU0sb0JBQW9CLENBQUM7QUFDOUMsT0FBTyxLQUFLLFFBQVEsTUFBTSxxQkFBcUIsQ0FBQztBQUNoRCxPQUFPLEtBQUssd0JBQXdCLE1BQU0sdUNBQXVDLENBQUM7QUFDbEYsT0FBTyxLQUFLLFNBQVMsTUFBTSxzQkFBc0IsQ0FBQztBQUNsRCxPQUFPLEtBQUssVUFBVSxNQUFNLHVCQUF1QixDQUFDO0FBQ3BELE9BQU8sS0FBSyxXQUFXLE1BQU0sd0JBQXdCLENBQUM7QUFFdEQsT0FBTyxFQUFFLEdBQUcsRUFBRSxTQUFTLEVBQUUsT0FBTyxFQUFFLFFBQVEsRUFBRSx3QkFBd0IsRUFBRSxTQUFTLEVBQUUsVUFBVSxFQUFFLFdBQVcsRUFBRSxDQUFDO0FBRTNHLGNBQWMifQ==
@@ -0,0 +1,2 @@
1
+ import * as plugins from './smartdaemon.plugins.js';
2
+ export declare const logger: plugins.smartlog.Smartlog;
@@ -0,0 +1,14 @@
1
+ import * as plugins from './smartdaemon.plugins.js';
2
+ export const logger = new plugins.smartlog.Smartlog({
3
+ logContext: {
4
+ company: 'Some Company',
5
+ companyunit: 'Some CompanyUnit',
6
+ containerName: 'Some Containername',
7
+ environment: 'local',
8
+ runtime: 'node',
9
+ zone: 'gitzone',
10
+ },
11
+ minimumLogLevel: 'silly',
12
+ });
13
+ logger.addLogDestination(new plugins.smartlogDestinationLocal.DestinationLocal());
14
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYW1vbi5sb2dnaW5nLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRkYW1vbi5sb2dnaW5nLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxPQUFPLE1BQU0sMEJBQTBCLENBQUM7QUFFcEQsTUFBTSxDQUFDLE1BQU0sTUFBTSxHQUFHLElBQUksT0FBTyxDQUFDLFFBQVEsQ0FBQyxRQUFRLENBQUM7SUFDbEQsVUFBVSxFQUFFO1FBQ1YsT0FBTyxFQUFFLGNBQWM7UUFDdkIsV0FBVyxFQUFFLGtCQUFrQjtRQUMvQixhQUFhLEVBQUUsb0JBQW9CO1FBQ25DLFdBQVcsRUFBRSxPQUFPO1FBQ3BCLE9BQU8sRUFBRSxNQUFNO1FBQ2YsSUFBSSxFQUFFLFNBQVM7S0FDaEI7SUFDRCxlQUFlLEVBQUUsT0FBTztDQUN6QixDQUFDLENBQUM7QUFFSCxNQUFNLENBQUMsaUJBQWlCLENBQUMsSUFBSSxPQUFPLENBQUMsd0JBQXdCLENBQUMsZ0JBQWdCLEVBQUUsQ0FBQyxDQUFDIn0=
package/license ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2019 Lossless GmbH (hello@lossless.com)
2
+ Copyright (c) 2017-2019, braces lab
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
package/npmextra.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "gitzone": {
3
+ "projectType": "npm",
4
+ "module": {
5
+ "githost": "gitlab.com",
6
+ "gitscope": "pushrocks",
7
+ "gitrepo": "smartdaemon",
8
+ "description": "start scripts as long running daemons and manage them",
9
+ "npmPackagename": "@pushrocks/smartdaemon",
10
+ "license": "MIT",
11
+ "projectDomain": "push.rocks"
12
+ }
13
+ },
14
+ "npmci": {
15
+ "npmGlobalTools": [],
16
+ "npmAccessLevel": "public"
17
+ }
18
+ }
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@push.rocks/smartdaemon",
3
+ "version": "2.0.3",
4
+ "private": false,
5
+ "description": "start scripts as long running daemons and manage them",
6
+ "main": "dist_ts/index.js",
7
+ "typings": "dist_ts/index.d.ts",
8
+ "author": "Lossless GmbH",
9
+ "license": "MIT",
10
+ "scripts": {
11
+ "test": "(tstest test/ --web)",
12
+ "build": "(tsbuild --web --allowimplicitany)",
13
+ "buildDocs": "tsdoc"
14
+ },
15
+ "devDependencies": {
16
+ "@gitzone/tsbuild": "^2.1.25",
17
+ "@gitzone/tsrun": "^1.2.38",
18
+ "@gitzone/tstest": "^1.0.52",
19
+ "@pushrocks/tapbundle": "^5.0.4",
20
+ "@types/node": "^18.11.2"
21
+ },
22
+ "dependencies": {
23
+ "@pushrocks/lik": "^6.0.0",
24
+ "@pushrocks/smartfile": "^10.0.5",
25
+ "@pushrocks/smartfm": "^2.0.4",
26
+ "@pushrocks/smartlog": "^3.0.1",
27
+ "@pushrocks/smartlog-destination-local": "^8.0.8",
28
+ "@pushrocks/smartpath": "^5.0.5",
29
+ "@pushrocks/smartshell": "^2.0.26",
30
+ "@pushrocks/smartsystem": "^3.0.1"
31
+ },
32
+ "files": [
33
+ "ts/**/*",
34
+ "ts_web/**/*",
35
+ "dist/**/*",
36
+ "dist_*/**/*",
37
+ "dist_ts/**/*",
38
+ "dist_ts_web/**/*",
39
+ "assets/**/*",
40
+ "cli.js",
41
+ "npmextra.json",
42
+ "readme.md"
43
+ ],
44
+ "browserslist": [
45
+ "last 1 chrome versions"
46
+ ],
47
+ "type": "module"
48
+ }
package/readme.md ADDED
@@ -0,0 +1,41 @@
1
+ # @pushrocks/smartdaemon
2
+ start scripts as long running daemons and manage them
3
+
4
+ ## Availabililty and Links
5
+ * [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartdaemon)
6
+ * [gitlab.com (source)](https://gitlab.com/pushrocks/smartdaemon)
7
+ * [github.com (source mirror)](https://github.com/pushrocks/smartdaemon)
8
+ * [docs (typedoc)](https://pushrocks.gitlab.io/smartdaemon/)
9
+
10
+ ## Status for master
11
+
12
+ Status Category | Status Badge
13
+ -- | --
14
+ GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartdaemon/badges/master/pipeline.svg)](https://lossless.cloud)
15
+ GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartdaemon/badges/master/coverage.svg)](https://lossless.cloud)
16
+ npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartdaemon)](https://lossless.cloud)
17
+ Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartdaemon)](https://lossless.cloud)
18
+ TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
19
+ node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
20
+ Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
21
+ PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartdaemon)](https://lossless.cloud)
22
+ PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartdaemon)](https://lossless.cloud)
23
+ BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartdaemon)](https://lossless.cloud)
24
+ Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
25
+
26
+ ## Usage
27
+
28
+ ## Contribution
29
+
30
+ We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
31
+
32
+ ## Contribution
33
+
34
+ We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
35
+
36
+ For further information read the linked docs at the top of this readme.
37
+
38
+ > MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh)
39
+ | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
40
+
41
+ [![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)
@@ -0,0 +1,8 @@
1
+ /**
2
+ * autocreated commitinfo by @pushrocks/commitinfo
3
+ */
4
+ export const commitinfo = {
5
+ name: '@pushrocks/smartdaemon',
6
+ version: '2.0.3',
7
+ description: 'start scripts as long running daemons and manage them'
8
+ }
package/ts/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './smartdaemon.classes.smartdaemon.js';
@@ -0,0 +1,86 @@
1
+ import * as plugins from './smartdaemon.plugins.js';
2
+ import * as paths from './smartdaemon.paths.js';
3
+ import { SmartDaemon } from './smartdaemon.classes.smartdaemon.js';
4
+
5
+ export interface ISmartDaemonServiceConstructorOptions {
6
+ name: string;
7
+ description: string;
8
+ command: string;
9
+ workingDir: string;
10
+ version: string;
11
+ }
12
+
13
+ /**
14
+ * represents a service that is being spawned by SmartDaemon
15
+ */
16
+ export class SmartDaemonService implements ISmartDaemonServiceConstructorOptions {
17
+ public static async createFromOptions(
18
+ smartdaemonRef: SmartDaemon,
19
+ optionsArg: ISmartDaemonServiceConstructorOptions
20
+ ) {
21
+ const service = new SmartDaemonService(smartdaemonRef);
22
+ for (const key of Object.keys(optionsArg)) {
23
+ service[key] = optionsArg[key];
24
+ }
25
+ return service;
26
+ }
27
+
28
+ public options: ISmartDaemonServiceConstructorOptions;
29
+ public alreadyExists = false;
30
+
31
+ public name: string;
32
+ public version: string;
33
+ public command: string;
34
+ public workingDir: string;
35
+ public description: string;
36
+
37
+ public smartdaemonRef: SmartDaemon;
38
+
39
+ constructor(smartdaemonRegfArg: SmartDaemon) {
40
+ this.smartdaemonRef = smartdaemonRegfArg;
41
+ }
42
+
43
+ /**
44
+ * enables the service
45
+ */
46
+ public async enable() {
47
+ await this.smartdaemonRef.systemdManager.enableService(this);
48
+ }
49
+
50
+ /**
51
+ * disables the service
52
+ */
53
+ public async disable() {
54
+ await this.smartdaemonRef.systemdManager.disableService(this);
55
+ }
56
+
57
+ /**
58
+ * starts a service
59
+ */
60
+ public async start() {
61
+ await this.smartdaemonRef.systemdManager.startService(this);
62
+ }
63
+
64
+ /**
65
+ * stops a service
66
+ */
67
+ public async stop() {
68
+ await this.smartdaemonRef.systemdManager.stopService(this);
69
+ }
70
+
71
+ // Save and Delete
72
+ public async save() {
73
+ await this.smartdaemonRef.systemdManager.saveService(this);
74
+ }
75
+
76
+ /**
77
+ * deletes the service
78
+ */
79
+ public async delete() {
80
+ await this.smartdaemonRef.systemdManager.deleteService(this);
81
+ }
82
+
83
+ public async reload() {
84
+ await this.smartdaemonRef.systemdManager.reload();
85
+ }
86
+ }
@@ -0,0 +1,41 @@
1
+ import * as plugins from './smartdaemon.plugins.js';
2
+ import { SmartDaemonTemplateManager } from './smartdaemon.classes.templatemanager.js';
3
+ import {
4
+ SmartDaemonService,
5
+ ISmartDaemonServiceConstructorOptions,
6
+ } from './smartdaemon.classes.service.js';
7
+ import { SmartDaemonSystemdManager } from './smartdaemon.classes.systemdmanager.js';
8
+
9
+ export class SmartDaemon {
10
+ public templateManager: SmartDaemonTemplateManager;
11
+ public systemdManager: SmartDaemonSystemdManager;
12
+
13
+ constructor() {
14
+ this.templateManager = new SmartDaemonTemplateManager(this);
15
+ this.systemdManager = new SmartDaemonSystemdManager(this);
16
+ }
17
+
18
+ /**
19
+ * adds a service
20
+ * @param nameArg
21
+ * @param commandArg
22
+ * @param workingDirectoryArg
23
+ */
24
+ public async addService(
25
+ optionsArg: ISmartDaemonServiceConstructorOptions
26
+ ): Promise<SmartDaemonService> {
27
+ let serviceToAdd: SmartDaemonService;
28
+ const existingServices = await this.systemdManager.getServices();
29
+ const existingService = existingServices.find((serviceArg) => {
30
+ return serviceArg.name === optionsArg.name;
31
+ });
32
+ if (!existingService) {
33
+ serviceToAdd = await SmartDaemonService.createFromOptions(this, optionsArg);
34
+ } else {
35
+ serviceToAdd = existingService;
36
+ Object.assign(serviceToAdd, optionsArg);
37
+ }
38
+ await serviceToAdd.save();
39
+ return serviceToAdd;
40
+ }
41
+ }
@@ -0,0 +1,147 @@
1
+ import * as plugins from './smartdaemon.plugins.js';
2
+ import * as paths from './smartdaemon.paths.js';
3
+ import { SmartDaemon } from './smartdaemon.classes.smartdaemon.js';
4
+ import {
5
+ ISmartDaemonServiceConstructorOptions,
6
+ SmartDaemonService,
7
+ } from './smartdaemon.classes.service.js';
8
+
9
+ export class SmartDaemonSystemdManager {
10
+ // STATIC
11
+ private static smartDaemonNamespace = 'smartdaemon';
12
+
13
+ public static createServiceNameFromServiceName(serviceNameArg: string) {
14
+ return `${SmartDaemonSystemdManager.smartDaemonNamespace}_${serviceNameArg}`;
15
+ }
16
+
17
+ public static createFileNameFromServiceName(serviceNameArg: string) {
18
+ return `${SmartDaemonSystemdManager.createServiceNameFromServiceName(serviceNameArg)}.service`;
19
+ }
20
+
21
+ public static createFilePathFromServiceName(serviceNameArg: string) {
22
+ return plugins.path.join(
23
+ paths.systemdDir,
24
+ SmartDaemonSystemdManager.createFileNameFromServiceName(serviceNameArg)
25
+ );
26
+ }
27
+
28
+ // INSTANCE
29
+ public smartdaemonRef: SmartDaemon;
30
+ public smartshellInstance: plugins.smartshell.Smartshell;
31
+ public smartsystem: plugins.smartsystem.Smartsystem;
32
+
33
+ public shouldExecute: boolean = false;
34
+
35
+ constructor(smartdaemonRefArg: SmartDaemon) {
36
+ this.smartdaemonRef = smartdaemonRefArg;
37
+ this.smartshellInstance = new plugins.smartshell.Smartshell({
38
+ executor: 'bash',
39
+ });
40
+ this.smartsystem = new plugins.smartsystem.Smartsystem();
41
+ }
42
+
43
+ public async checkElegibility() {
44
+ if (await this.smartsystem.env.isLinuxAsync()) {
45
+ this.shouldExecute = true;
46
+ } else {
47
+ console.log('Smartdaemon can only be used on Linux systems! Refusing to set up a service.');
48
+ this.shouldExecute = false;
49
+ }
50
+ return this.shouldExecute;
51
+ }
52
+
53
+ public async execute(commandArg: string) {
54
+ if (await this.checkElegibility()) {
55
+ await this.smartshellInstance.exec(commandArg);
56
+ }
57
+ }
58
+
59
+ /**
60
+ * gets all services that are already present
61
+ */
62
+ public async getServices() {
63
+ const existingServices: SmartDaemonService[] = [];
64
+ if (await this.checkElegibility()) {
65
+ const smartfmInstance = new plugins.smartfm.Smartfm({
66
+ fmType: 'yaml',
67
+ });
68
+ const availableServices = await plugins.smartfile.fs.fileTreeToObject(
69
+ paths.systemdDir,
70
+ 'smartdaemon_*.service'
71
+ );
72
+ for (const serviceFile of availableServices) {
73
+ const data = smartfmInstance.parseFromComments('# ', serviceFile.contentBuffer.toString())
74
+ .data as ISmartDaemonServiceConstructorOptions;
75
+ const service = await SmartDaemonService.createFromOptions(this.smartdaemonRef, data);
76
+ service.alreadyExists = true;
77
+ existingServices.push(service);
78
+ }
79
+ }
80
+ return existingServices;
81
+ }
82
+
83
+ public async startService(serviceArg: SmartDaemonService) {
84
+ if (await this.checkElegibility()) {
85
+ await this.execute(
86
+ `systemctl start ${SmartDaemonSystemdManager.createServiceNameFromServiceName(
87
+ serviceArg.name
88
+ )}`
89
+ );
90
+ }
91
+ }
92
+ public async stopService(serviceArg: SmartDaemonService) {
93
+ if (await this.checkElegibility()) {
94
+ await this.execute(
95
+ `systemctl stop ${SmartDaemonSystemdManager.createServiceNameFromServiceName(
96
+ serviceArg.name
97
+ )}`
98
+ );
99
+ }
100
+ }
101
+
102
+ public async saveService(serviceArg: SmartDaemonService) {
103
+ if (await this.checkElegibility()) {
104
+ await plugins.smartfile.memory.toFs(
105
+ this.smartdaemonRef.templateManager.generateUnitFileForService(serviceArg),
106
+ SmartDaemonSystemdManager.createFilePathFromServiceName(serviceArg.name)
107
+ );
108
+ }
109
+ }
110
+
111
+ public async deleteService(serviceArg: SmartDaemonService) {
112
+ if (await this.checkElegibility()) {
113
+ await plugins.smartfile.fs.remove(
114
+ SmartDaemonSystemdManager.createServiceNameFromServiceName(serviceArg.name)
115
+ );
116
+ }
117
+ }
118
+
119
+ public async enableService(serviceArg: SmartDaemonService) {
120
+ if (await this.checkElegibility()) {
121
+ await this.saveService(serviceArg);
122
+ if (serviceArg.alreadyExists) {
123
+ await this.execute(`systemctl daemon-reload`);
124
+ }
125
+ await this.execute(
126
+ `systemctl enable ${SmartDaemonSystemdManager.createServiceNameFromServiceName(
127
+ serviceArg.name
128
+ )}`
129
+ );
130
+ }
131
+ }
132
+ public async disableService(serviceArg: SmartDaemonService) {
133
+ if (await this.checkElegibility()) {
134
+ await this.execute(
135
+ `systemctl disable ${SmartDaemonSystemdManager.createServiceNameFromServiceName(
136
+ serviceArg.name
137
+ )}`
138
+ );
139
+ }
140
+ }
141
+
142
+ public async reload() {
143
+ if (await this.checkElegibility()) {
144
+ await this.execute(`systemctl daemon-reload`);
145
+ }
146
+ }
147
+ }
@@ -0,0 +1,41 @@
1
+ import * as plugins from './smartdaemon.plugins.js';
2
+ import { SmartDaemon } from './smartdaemon.classes.smartdaemon.js';
3
+ import { SmartDaemonService } from './smartdaemon.classes.service.js';
4
+
5
+ export class SmartDaemonTemplateManager {
6
+ public smartdaemonRef: SmartDaemon;
7
+
8
+ constructor(smartdaemonRefArg: SmartDaemon) {
9
+ this.smartdaemonRef = smartdaemonRefArg;
10
+ }
11
+
12
+ public generateUnitFileForService = (serviceArg: SmartDaemonService) => {
13
+ return `# ---
14
+ # name: ${serviceArg.name}
15
+ # version: ${serviceArg.version}
16
+ # description: ${serviceArg.description}
17
+ # command: ${serviceArg.command}
18
+ # workingDir: ${serviceArg.workingDir}
19
+ # ---
20
+ [Unit]
21
+ Description=${serviceArg.description}
22
+ Requires=network.target
23
+ After=network.target
24
+
25
+ [Service]
26
+ Type=simple
27
+ Environment=NODE_OPTIONS="--max_old_space_size=100"
28
+ ExecStart=/bin/bash -c "cd ${serviceArg.workingDir} && ${serviceArg.command}"
29
+ WorkingDirectory=${serviceArg.workingDir}
30
+ Restart=on-failure
31
+ LimitNOFILE=infinity
32
+ LimitCORE=infinity
33
+ StandardInput=null
34
+ StandardOutput=syslog
35
+ StandardError=syslog
36
+ Restart=always
37
+ [Install]
38
+ WantedBy=multi-user.target
39
+ `;
40
+ };
41
+ }
@@ -0,0 +1,4 @@
1
+ import * as plugins from './smartdaemon.plugins.js';
2
+
3
+ export const packageDir = plugins.path.join(plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url), '../');
4
+ export const systemdDir = plugins.path.join('/lib/systemd/system/');
@@ -0,0 +1,18 @@
1
+ // node native scope
2
+ import * as path from 'path';
3
+
4
+ export { path };
5
+
6
+ // @pushrocks scope
7
+ import * as lik from '@pushrocks/lik';
8
+ import * as smartfile from '@pushrocks/smartfile';
9
+ import * as smartfm from '@pushrocks/smartfm';
10
+ import * as smartlog from '@pushrocks/smartlog';
11
+ import * as smartlogDestinationLocal from '@pushrocks/smartlog-destination-local';
12
+ import * as smartpath from '@pushrocks/smartpath';
13
+ import * as smartshell from '@pushrocks/smartshell';
14
+ import * as smartsystem from '@pushrocks/smartsystem';
15
+
16
+ export { lik, smartfile, smartfm, smartlog, smartlogDestinationLocal, smartpath, smartshell, smartsystem };
17
+
18
+ // third party
@@ -0,0 +1,15 @@
1
+ import * as plugins from './smartdaemon.plugins.js';
2
+
3
+ export const logger = new plugins.smartlog.Smartlog({
4
+ logContext: {
5
+ company: 'Some Company',
6
+ companyunit: 'Some CompanyUnit',
7
+ containerName: 'Some Containername',
8
+ environment: 'local',
9
+ runtime: 'node',
10
+ zone: 'gitzone',
11
+ },
12
+ minimumLogLevel: 'silly',
13
+ });
14
+
15
+ logger.addLogDestination(new plugins.smartlogDestinationLocal.DestinationLocal());