smartnginx/ts/smartnginx.classes.nginxprocess.ts

83 lines
2.1 KiB
TypeScript
Raw Normal View History

import * as plugins from './smartnginx.plugins';
import * as paths from './smartnginx.paths';
import { SmartNginx } from './smartnginx.classes.smartnginx';
import { NginxHost } from './smartnginx.classes.nginxhost';
import { Smartshell } from '@pushrocks/smartshell';
2016-07-24 23:54:36 +00:00
/**
* manages a nginxprocess for an NginxConfig
*/
2016-07-24 23:54:36 +00:00
export class NginxProcess {
started: boolean = false;
nginxConfig: SmartNginx;
nginxChildProcess: plugins.childProcess.ChildProcess;
smartshellInstance = new Smartshell({
executor: 'bash'
});
constructor(nginxConfigArg) {
this.nginxConfig = nginxConfigArg;
}
2016-07-24 23:54:36 +00:00
/**
* 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}`);
}
}
);
}
this.started = true;
plugins.smartlog.defaultLogger.info('started Nginx!');
done.resolve();
return done.promise;
}
2016-07-24 23:54:36 +00:00
/**
* reload config
*/
reloadConfig() {
let done = plugins.smartpromise.defer();
if (this.started == false) {
this.start();
} else {
this.smartshellInstance.exec('nginx -s reload');
}
plugins.smartlog.defaultLogger.info('NginxProcess has loaded the new config!');
done.resolve();
return done.promise;
}
2016-07-24 23:54:36 +00:00
/**
* stop the nginx instance
*/
stop() {
let done = plugins.smartpromise.defer();
if (typeof this.nginxChildProcess != 'undefined') {
this.smartshellInstance.exec('nginx -s quit');
this.started = false;
plugins.smartlog.defaultLogger.info('stopped Nginx!');
} else {
plugins.smartlog.defaultLogger.info('nginx already stopped!');
}
done.resolve();
return done.promise;
}
2016-07-24 23:54:36 +00:00
/**
* checks if nginx is in path
*/
check(): boolean {
return;
}
2016-07-24 23:54:36 +00:00
}