smartnginx/ts/smartnginx.command.ts
2016-07-11 16:34:51 +02:00

59 lines
1.4 KiB
TypeScript

import * as plugins from "./smartnginx.plugins";
import {NginxConfig} from "./smartnginx.classes.nginxconfig";
import {NginxZone} from "./smartnginx.classes.nginxzone";
let nginxChildProcess = undefined; // points to the nginx child process
/**
* starts nginx
*/
export let start = (configArg:NginxConfig) => {
let done = plugins.q.defer();
if(typeof nginxChildProcess == "undefined"){
nginxChildProcess = plugins.childProcess.exec("nginx",function(error, stdout, stderr){
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
if (error !== null) {
console.log(`exec error: ${error}`);
}
});
};
plugins.beautylog.info("started Nginx!");
done.resolve();
return done.promise;
};
/**
* restarts nginx
*/
export let restart = (configArg:NginxConfig) => {
return stop().then(
() => {
return start(configArg);
}
);
}
/**
* stops nginx
*/
export let stop = () => {
let done = plugins.q.defer();
if(typeof nginxChildProcess != "undefined"){
nginxChildProcess.kill();
plugins.beautylog.info("stopped Nginx!");
} else {
plugins.beautylog.log("nginx already stopped!");
};
done.resolve();
return done.promise;
};
/**
* checks if nginx is in path
*/
export let check = ():boolean => {
return;
};