smartdaemon/ts/smartdaemon.classes.templatemanager.ts

42 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-10-19 17:27:42 +00:00
import * as plugins from './smartdaemon.plugins.js';
import { SmartDaemon } from './smartdaemon.classes.smartdaemon.js';
import { SmartDaemonService } from './smartdaemon.classes.service.js';
2019-09-03 09:29:14 +00:00
export class SmartDaemonTemplateManager {
2019-09-03 13:21:30 +00:00
public smartdaemonRef: SmartDaemon;
constructor(smartdaemonRefArg: SmartDaemon) {
this.smartdaemonRef = smartdaemonRefArg;
}
2019-09-05 11:50:11 +00:00
public generateUnitFileForService = (serviceArg: SmartDaemonService) => {
2019-09-05 09:15:17 +00:00
return `# ---
2019-09-05 11:50:11 +00:00
# name: ${serviceArg.name}
# version: ${serviceArg.version}
# description: ${serviceArg.description}
# command: ${serviceArg.command}
# workingDir: ${serviceArg.workingDir}
2019-09-05 09:15:17 +00:00
# ---
2019-09-03 09:29:14 +00:00
[Unit]
2019-09-05 11:50:11 +00:00
Description=${serviceArg.description}
2019-09-03 09:29:14 +00:00
Requires=network.target
After=network.target
[Service]
Type=simple
2019-09-19 17:37:34 +00:00
Environment=NODE_OPTIONS="--max_old_space_size=100"
2019-09-05 11:50:11 +00:00
ExecStart=/bin/bash -c "cd ${serviceArg.workingDir} && ${serviceArg.command}"
WorkingDirectory=${serviceArg.workingDir}
2019-09-03 09:29:14 +00:00
Restart=on-failure
LimitNOFILE=infinity
LimitCORE=infinity
StandardInput=null
StandardOutput=syslog
StandardError=syslog
Restart=always
[Install]
WantedBy=multi-user.target
`;
2021-01-30 00:41:40 +00:00
};
2019-09-03 09:29:14 +00:00
}