2019-09-03 09:29:14 +00:00
|
|
|
import * as plugins from './smartdaemon.plugins';
|
2019-09-03 13:21:30 +00:00
|
|
|
import { SmartDaemon } from './smartdaemon.classes.smartdaemon';
|
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-03 09:29:14 +00:00
|
|
|
public generateServiceTemplate = (optionsArg: {
|
2019-09-05 09:15:17 +00:00
|
|
|
name: string;
|
2019-09-03 09:29:14 +00:00
|
|
|
description: string;
|
2019-09-05 09:15:17 +00:00
|
|
|
version: string;
|
2019-09-03 13:21:30 +00:00
|
|
|
command: string;
|
2019-09-05 09:15:17 +00:00
|
|
|
workkingDir;
|
2019-09-03 09:29:14 +00:00
|
|
|
}) => {
|
2019-09-05 09:15:17 +00:00
|
|
|
return `# ---
|
|
|
|
# name: ${optionsArg.name}
|
|
|
|
# version: ${optionsArg.version}
|
|
|
|
# description: ${optionsArg.description}
|
|
|
|
# command: ${optionsArg.command}
|
|
|
|
# workingDir: ${optionsArg.workkingDir}
|
|
|
|
# ---
|
2019-09-03 09:29:14 +00:00
|
|
|
[Unit]
|
|
|
|
Description=${optionsArg.description}
|
|
|
|
Requires=network.target
|
|
|
|
After=network.target
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
Type=simple
|
2019-09-05 09:15:17 +00:00
|
|
|
ExecStart=/bin/bash -c "cd ${optionsArg.workkingDir} && ${optionsArg.command}"
|
|
|
|
WorkingDirectory=${optionsArg.workkingDir}
|
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
|
|
|
|
`;
|
2019-09-03 13:21:30 +00:00
|
|
|
}
|
2019-09-03 09:29:14 +00:00
|
|
|
}
|