fix(core): update

This commit is contained in:
2019-01-09 12:15:28 +01:00
parent 1049920efd
commit ede884930e
12 changed files with 316 additions and 142 deletions

View File

@ -5,78 +5,65 @@ import { NginxHost } from './smartnginx.classes.nginxhost';
import { Smartshell } from '@pushrocks/smartshell';
import { ChildProcess } from 'child_process';
/**
* manages a nginxprocess for an NginxConfig
*/
export class NginxProcess {
started: boolean = false;
nginxConfig: SmartNginx;
nginxChildProcess: plugins.childProcess.ChildProcess;
smartshellInstance = new Smartshell({
public started: boolean = false;
public smartNginxRef: SmartNginx;
private nginxChildProcess: ChildProcess;
private smartshellInstance = new Smartshell({
executor: 'bash'
});
constructor(nginxConfigArg) {
this.nginxConfig = nginxConfigArg;
constructor(nginxRefArg: SmartNginx) {
this.smartNginxRef = nginxRefArg;
}
/**
* start nginx
*/
start() {
let done = plugins.smartpromise.defer();
if (typeof this.nginxChildProcess == 'undefined') {
this.nginxChildProcess = plugins.childProcess.exec(
`nginx -c ${paths.nginxConfFile}`,
function(error, stdout, stderr) {
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
if (error !== null) {
console.log(`exec error: ${error}`);
}
}
);
public async start() {
if (!this.nginxChildProcess) {
this.nginxChildProcess = (await this.smartshellInstance.execStreaming(
`nginx -c ${paths.nginxConfFile}`
)).childProcess;
}
this.started = true;
plugins.smartlog.defaultLogger.log('info', 'started Nginx!');
done.resolve();
return done.promise;
}
/**
* reload config
*/
reloadConfig() {
let done = plugins.smartpromise.defer();
if (this.started == false) {
public async reloadConfig() {
if (!this.started) {
this.start();
} else {
this.smartshellInstance.exec('nginx -s reload');
await this.smartshellInstance.exec('nginx -s reload');
}
plugins.smartlog.defaultLogger.log('info', 'NginxProcess has loaded the new config!');
done.resolve();
return done.promise;
this.smartNginxRef.logger.log('info', 'NginxProcess has loaded the new config!');
}
/**
* stop the nginx instance
*/
stop() {
let done = plugins.smartpromise.defer();
if (typeof this.nginxChildProcess != 'undefined') {
public async stop() {
if (this.nginxChildProcess) {
this.smartshellInstance.exec('nginx -s quit');
this.started = false;
plugins.smartlog.defaultLogger.log('info', 'stopped Nginx!');
this.smartNginxRef.logger.log('info', 'stopped Nginx!');
} else {
plugins.smartlog.defaultLogger.log('info', 'nginx already stopped!');
this.smartNginxRef.logger.log('info', 'nginx already stopped!');
}
done.resolve();
return done.promise;
}
/**
* checks if nginx is in path
*/
check(): boolean {
public check(): boolean {
return;
}
}