smartnginx/ts/smartnginx.classes.nginxprocess.ts

75 lines
2.0 KiB
TypeScript
Raw Normal View History

2016-07-24 23:54:36 +00:00
import * as plugins from "./smartnginx.plugins";
import * as paths from "./smartnginx.paths";
import { NginxConfig } from "./smartnginx.classes.nginxconfig";
import { NginxHost } from "./smartnginx.classes.nginxhost";
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:NginxConfig;
nginxChildProcess: plugins.childProcess.ChildProcess;
constructor(nginxConfigArg) {
this.nginxConfig = nginxConfigArg;
};
/**
* start nginx
*/
start() {
let done = plugins.q.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.beautylog.info("started Nginx!");
done.resolve();
return done.promise;
};
/**
* reload config
*/
reloadConfig(){
let done = plugins.q.defer();
if(this.started == false){
this.start();
2016-07-24 23:54:36 +00:00
} else {
2016-07-25 01:21:28 +00:00
plugins.shelljs.exec("nginx -s reload");
2016-07-24 23:54:36 +00:00
};
plugins.beautylog.ok("NginxProcess has loaded the new config!")
done.resolve();
return done.promise;
};
/**
* stop the nginx instance
*/
stop() {
let done = plugins.q.defer();
if (typeof this.nginxChildProcess != "undefined") {
2016-07-25 01:21:28 +00:00
plugins.shelljs.exec("nginx -s quit");
this.started = false;
2016-07-24 23:54:36 +00:00
plugins.beautylog.info("stopped Nginx!");
} else {
plugins.beautylog.log("nginx already stopped!");
};
done.resolve();
return done.promise;
};
/**
* checks if nginx is in path
*/
check(): boolean {
return;
};
}