79 lines
4.6 KiB
JavaScript
79 lines
4.6 KiB
JavaScript
"use strict";
|
|
const plugins = require("./smartnginx.plugins");
|
|
const paths = require("./smartnginx.paths");
|
|
/**
|
|
* manages a nginxprocess for an NginxConfig
|
|
*/
|
|
class NginxProcess {
|
|
constructor(nginxConfigArg) {
|
|
this.started = false;
|
|
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();
|
|
}
|
|
else {
|
|
plugins.shelljs.exec("nginx -s reload");
|
|
}
|
|
;
|
|
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") {
|
|
plugins.shelljs.exec("nginx -s quit");
|
|
this.started = false;
|
|
plugins.beautylog.info("stopped Nginx!");
|
|
}
|
|
else {
|
|
plugins.beautylog.log("nginx already stopped!");
|
|
}
|
|
;
|
|
done.resolve();
|
|
return done.promise;
|
|
}
|
|
;
|
|
/**
|
|
* checks if nginx is in path
|
|
*/
|
|
check() {
|
|
return;
|
|
}
|
|
;
|
|
}
|
|
exports.NginxProcess = NginxProcess;
|
|
//#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