smartnginx/ts/smartnginx.command.ts

59 lines
1.4 KiB
TypeScript
Raw Normal View History

2016-07-06 04:33:31 +00:00
import * as plugins from "./smartnginx.plugins";
2016-07-06 06:30:33 +00:00
import {NginxConfig} from "./smartnginx.classes.nginxconfig";
import {NginxZone} from "./smartnginx.classes.nginxzone";
2016-07-06 04:33:31 +00:00
2016-07-11 14:34:51 +00:00
let nginxChildProcess = undefined; // points to the nginx child process
2016-07-06 04:33:31 +00:00
/**
* starts nginx
*/
export let start = (configArg:NginxConfig) => {
2016-07-11 14:34:51 +00:00
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;
2016-07-06 04:33:31 +00:00
};
2016-07-11 14:34:51 +00:00
/**
* restarts nginx
*/
2016-07-06 04:33:31 +00:00
export let restart = (configArg:NginxConfig) => {
2016-07-11 14:34:51 +00:00
return stop().then(
() => {
return start(configArg);
}
);
2016-07-06 04:33:31 +00:00
}
/**
* stops nginx
*/
export let stop = () => {
2016-07-11 14:34:51 +00:00
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;
2016-07-06 04:33:31 +00:00
};
/**
* checks if nginx is in path
*/
export let check = ():boolean => {
return;
};