now working as intended

This commit is contained in:
Philipp Kunz 2016-07-25 01:54:36 +02:00
parent effe9210fc
commit ca2ff3481e
21 changed files with 258 additions and 207 deletions

View File

@ -4,6 +4,9 @@ stages:
- test
- release
before_script:
- "apt-get update && apt-get install nginx -y"
testLEGACY:
stage: test
script:
@ -28,6 +31,7 @@ testSTABLE:
release:
stage: release
environment: npmjs-com_registry
script:
- npmci publish
only:

3
dist/index.d.ts vendored
View File

@ -1,4 +1,3 @@
import * as CommandModule from "./smartnginx.command";
export { NginxConfig } from "./smartnginx.classes.nginxconfig";
export { NginxProcess } from "./smartnginx.classes.nginxprocess";
export { NginxZone, zoneTypes } from "./smartnginx.classes.nginxzone";
export declare let command: typeof CommandModule;

7
dist/index.js vendored
View File

@ -1,11 +1,10 @@
"use strict";
const CommandModule = require("./smartnginx.command");
// classes
var smartnginx_classes_nginxconfig_1 = require("./smartnginx.classes.nginxconfig");
exports.NginxConfig = smartnginx_classes_nginxconfig_1.NginxConfig;
var smartnginx_classes_nginxprocess_1 = require("./smartnginx.classes.nginxprocess");
exports.NginxProcess = smartnginx_classes_nginxprocess_1.NginxProcess;
var smartnginx_classes_nginxzone_1 = require("./smartnginx.classes.nginxzone");
exports.NginxZone = smartnginx_classes_nginxzone_1.NginxZone;
exports.zoneTypes = smartnginx_classes_nginxzone_1.zoneTypes;
// exports
exports.command = CommandModule;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQ0EsTUFBWSxhQUFhLFdBQU0sc0JBQXNCLENBQUMsQ0FBQTtBQUV0RCxVQUFVO0FBQ1YsK0NBQTBCLGtDQUFrQyxDQUFDO0FBQXJELG1FQUFxRDtBQUM3RCw2Q0FBa0MsZ0NBQWdDLENBQUM7QUFBM0QsNkRBQVM7QUFBQyw2REFBaUQ7QUFFbkUsVUFBVTtBQUNDLGVBQU8sR0FBRyxhQUFhLENBQUMifQ==
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBRUEsVUFBVTtBQUNWLCtDQUEwQixrQ0FBa0MsQ0FBQztBQUFyRCxtRUFBcUQ7QUFDN0QsZ0RBQTJCLG1DQUFtQyxDQUFDO0FBQXZELHNFQUF1RDtBQUMvRCw2Q0FBa0MsZ0NBQWdDLENBQUM7QUFBM0QsNkRBQVM7QUFBQyw2REFBaUQifQ==

View File

@ -1,14 +1,16 @@
/// <reference types="q" />
import * as plugins from "./smartnginx.plugins";
import { NginxZone } from "./smartnginx.classes.nginxzone";
import { NginxProcess } from "./smartnginx.classes.nginxprocess";
export declare class NginxConfig {
zones: NginxZone[];
cert: plugins.cert.Cert;
nginxProcess: NginxProcess;
isDeployed: boolean;
constructor(optionsArg: plugins.cert.ICertConstructorOptions);
addZone(zoneArg: NginxZone): void;
listZones(): NginxZone[];
removeZones(zoneArg: NginxZone): void;
clean(): void;
deploy(nginxRestartArg?: boolean): plugins.q.Promise<{}>;
deploy(): plugins.q.Promise<{}>;
}

View File

@ -1,12 +1,13 @@
"use strict";
const plugins = require("./smartnginx.plugins");
const paths = require("./smartnginx.paths");
const command = require("./smartnginx.command");
const snippets = require("./smartnginx.snippets");
const smartnginx_classes_nginxprocess_1 = require("./smartnginx.classes.nginxprocess");
let allConfigs = [];
class NginxConfig {
constructor(optionsArg) {
this.zones = [];
this.nginxProcess = new smartnginx_classes_nginxprocess_1.NginxProcess(this);
this.isDeployed = false;
this.cert = new plugins.cert.Cert({
cfEmail: optionsArg.cfEmail,
@ -31,9 +32,8 @@ class NginxConfig {
this.zones = [];
}
// handle deployment of zones
deploy(nginxRestartArg = false) {
deploy() {
let done = plugins.q.defer();
plugins.smartfile.fs.removeSync(paths.nginxConfigBase);
plugins.smartfile.fs.ensureDirSync(paths.nginxConfigBase);
plugins.smartfile.fs.ensureDirSync(paths.nginxZoneBase);
plugins.smartfile.fs.ensureDirSync(paths.nginxCertBase);
@ -43,20 +43,20 @@ class NginxConfig {
;
this.isDeployed = true;
// write base config
plugins.smartfile.memory.toFsSync(snippets.getBaseConfigString(), plugins.path.join(paths.nginxConfigBase, "nginx.conf"));
plugins.smartfile.memory.toFsSync(snippets.getBaseConfigString(), paths.nginxConfFile);
// deploy zones
let promiseArray = [];
for (let zone of this.zones) {
promiseArray.push(zone.deploy(this.cert));
let zoneDeployedPromise = zone.deploy(this.cert);
zoneDeployedPromise.then(() => {
plugins.beautylog.info(`Zone ${zone.zoneName} deployed!`);
this.nginxProcess.reloadConfig();
});
promiseArray.push(zoneDeployedPromise);
}
;
plugins.q.all(promiseArray)
.then(() => {
// restart nginx
if (nginxRestartArg) {
command.restart(this);
}
;
done.resolve();
});
return done.promise;
@ -65,4 +65,4 @@ class NginxConfig {
}
exports.NginxConfig = NginxConfig;
;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jbGFzc2VzLm5naW54Y29uZmlnLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRuZ2lueC5jbGFzc2VzLm5naW54Y29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxNQUFZLE9BQU8sV0FBTSxzQkFBc0IsQ0FBQyxDQUFBO0FBQ2hELE1BQVksS0FBSyxXQUFNLG9CQUFvQixDQUFDLENBQUE7QUFDNUMsTUFBWSxPQUFPLFdBQU0sc0JBQXNCLENBQUMsQ0FBQTtBQUNoRCxNQUFZLFFBQVEsV0FBTSx1QkFDMUIsQ0FBQyxDQURnRDtBQUVqRCxJQUFJLFVBQVUsR0FBaUIsRUFBRSxDQUFDO0FBRWx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SxDQUFDO1FBQ3ZCLG9CQUFvQjtRQUNwQixPQUFPLENBQUMsU0FBUyxDQUFDLE1BQU0sQ0FBQyxRQUFRLENBQzdCLFFBQVEsQ0FBQyxtQkFBbUIsRUFBRSxFQUM5QixLQUFLLENBQUMsYUFBYSxDQUN0QixDQUFDO1FBQ0YsZUFBZTtRQUNmLElBQUksWUFBWSxHQUFHLEVBQUUsQ0FBQztRQUN0QixHQUFHLENBQUMsQ0FBQyxJQUFJLElBQUksSUFBSSxJQUFJLENBQUMsS0FBSyxDQUFDLENBQUMsQ0FBQztZQUMxQixJQUFJLG1CQUFtQixHQUFHLElBQUksQ0FBQyxNQUFNLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxDQUFDO1lBQ2pELG1CQUFtQixDQUFDLElBQUksQ0FBQztnQkFDckIsT0FBTyxDQUFDLFNBQVMsQ0FBQyxJQUFJLENBQUMsUUFBUSxJQUFJLENBQUMsUUFBUSxZQUFZLENBQUMsQ0FBQztnQkFDMUQsSUFBSSxDQUFDLFlBQVksQ0FBQyxZQUFZLEVBQUUsQ0FBQztZQUNyQyxDQUFDLENBQUMsQ0FBQztZQUNILFlBQVksQ0FBQyxJQUFJLENBQUMsbUJBQW1CLENBQUMsQ0FBQztRQUMzQyxDQUFDO1FBQUEsQ0FBQztRQUNGLE9BQU8sQ0FBQyxDQUFDLENBQUMsR0FBRyxDQUFDLFlBQVksQ0FBQzthQUN0QixJQUFJLENBQUM7WUFDRixJQUFJLENBQUMsT0FBTyxFQUFFLENBQUM7UUFDbkIsQ0FBQyxDQUFDLENBQUM7UUFFUCxNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQztJQUN4QixDQUFDOztBQUNMLENBQUM7QUE1RFksbUJBQVcsY0E0RHZCLENBQUE7QUFBQSxDQUFDIn0=

View File

@ -0,0 +1,26 @@
/// <reference types="node" />
/// <reference types="q" />
import * as plugins from "./smartnginx.plugins";
import { NginxConfig } from "./smartnginx.classes.nginxconfig";
export declare class NginxProcess {
started: boolean;
nginxConfig: NginxConfig;
nginxChildProcess: plugins.childProcess.ChildProcess;
constructor(nginxConfigArg: any);
/**
* start nginx
*/
start(): plugins.q.Promise<{}>;
/**
* reload config
*/
reloadConfig(): plugins.q.Promise<{}>;
/**
* stop the nginx instance
*/
stop(): plugins.q.Promise<{}>;
/**
* checks if nginx is in path
*/
check(): boolean;
}

75
dist/smartnginx.classes.nginxprocess.js vendored Normal file
View File

@ -0,0 +1,75 @@
"use strict";
const plugins = require("./smartnginx.plugins");
const paths = require("./smartnginx.paths");
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 {
this.nginxChildProcess.kill("SIGHUP");
}
;
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") {
this.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
*/
check() {
return;
}
;
}
exports.NginxProcess = NginxProcess;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5jbGFzc2VzLm5naW54cHJvY2Vzcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3Nt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UFXO1FBQ1gsZUFBZSxDQUFDLGFBQWEsQ0FBQyxJQUFJLENBQUMsUUFBUSxDQUFDO2FBQ3ZDLElBQUksQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLENBQUM7UUFDeEIsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUM7SUFDeEIsQ0FBQzs7QUFDTCxDQUFDO0FBekJZLGlCQUFTLFlBeUJyQixDQUFBO0FBQUEsQ0FBQyJ9

View File

@ -1,19 +0,0 @@
/// <reference types="q" />
import * as plugins from "./smartnginx.plugins";
import { NginxConfig } from "./smartnginx.classes.nginxconfig";
/**
* starts nginx
*/
export declare let start: (configArg: NginxConfig) => plugins.q.Promise<{}>;
/**
* restarts nginx
*/
export declare let restart: (configArg: NginxConfig) => plugins.q.Promise<{}>;
/**
* stops nginx
*/
export declare let stop: () => plugins.q.Promise<{}>;
/**
* checks if nginx is in path
*/
export declare let check: () => boolean;

View File

@ -1,53 +0,0 @@
"use strict";
const plugins = require("./smartnginx.plugins");
let nginxChildProcess = undefined; // points to the nginx child process
/**
* starts nginx
*/
exports.start = (configArg) => {
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
*/
exports.restart = (configArg) => {
return exports.stop().then(() => {
return exports.start(configArg);
});
};
/**
* stops nginx
*/
exports.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
*/
exports.check = () => {
return;
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlI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UFDLElBQUksQ0FBQyxPQUFPLENBQUM7QUFDeEIsQ0FBQyxDQUFDO0FBRUY7O0dBRUc7QUFDUSxlQUFPLEdBQUcsQ0FBQyxTQUFxQjtJQUN2QyxNQUFNLENBQUMsWUFBSSxFQUFFLENBQUMsSUFBSSxDQUNkO1FBQ0ksTUFBTSxDQUFDLGFBQUssQ0FBQyxTQUFTLENBQUMsQ0FBQztJQUM1QixDQUFDLENBQ0osQ0FBQztBQUNOLENBQUMsQ0FBQTtBQUVEOztHQUVHO0FBQ1EsWUFBSSxHQUFHO0lBQ2QsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUM3QixFQUFFLENBQUEsQ0FBQyxPQUFPLGlCQUFpQixJQUFJLFdBQVcsQ0FBQyxDQUFBLENBQUM7UUFDeEMsaUJBQWlCLENBQUMsSUFBSSxFQUFFLENBQUM7UUFDekIsT0FBTyxDQUFDLFNBQVMsQ0FBQyxJQUFJLENBQUMsZ0JBQWdCLENBQUMsQ0FBQztJQUM3QyxDQUFDO0lBQUMsSUFBSSxDQUFDLENBQUM7UUFDSixPQUFPLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyx3QkFBd0IsQ0FBQyxDQUFDO0lBQ3BELENBQUM7SUFBQSxDQUFDO0lBQ0YsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFDO0lBQ2YsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUM7QUFDeEIsQ0FBQyxDQUFDO0FBRUY7O0dBRUc7QUFDUSxhQUFLLEdBQUc7SUFDZixNQUFNLENBQUM7QUFDWCxDQUFDLENBQUMifQ==

View File

@ -2,3 +2,4 @@ export declare let packageBase: string;
export declare let nginxConfigBase: string;
export declare let nginxZoneBase: string;
export declare let nginxCertBase: string;
export declare let nginxConfFile: string;

View File

@ -1,7 +1,10 @@
"use strict";
const plugins = require("./smartnginx.plugins");
// directories
exports.packageBase = plugins.path.join(__dirname, "../");
exports.nginxConfigBase = plugins.path.join(exports.packageBase, "nginxconfig");
exports.nginxZoneBase = plugins.path.join(exports.nginxConfigBase, "zones");
exports.nginxCertBase = plugins.path.join(exports.nginxConfigBase, "cert");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5wYXRocy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bmdpbngucGF0aHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHNCQUV6QixDQUFDLENBRjhDO0FBRXBDLG1CQUFXLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsU0FBUyxFQUFDLEtBQUssQ0FBQyxDQUFDO0FBQ2pELHVCQUFlLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsbUJBQVcsRUFBQyxhQUFhLENBQUMsQ0FBQztBQUMvRCxxQkFBYSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLHVCQUFlLEVBQUMsT0FBTyxDQUFDLENBQUM7QUFDM0QscUJBQWEsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyx1QkFBZSxFQUFDLE1BQU0sQ0FBQyxDQUFDIn0=
// files
exports.nginxConfFile = plugins.path.join(exports.nginxConfigBase, "nginx.conf");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRuZ2lueC5wYXRocy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bmdpbngucGF0aHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHNCQUd6QixDQUFDLENBSDhDO0FBRS9DLGNBQWM7QUFDSCxtQkFBVyxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLFNBQVMsRUFBQyxLQUFLLENBQUMsQ0FBQztBQUNqRCx1QkFBZSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLG1CQUFXLEVBQUMsYUFBYSxDQUFDLENBQUM7QUFDL0QscUJBQWEsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyx1QkFBZSxFQUFDLE9BQU8sQ0FBQyxDQUFDO0FBQzNELHFCQUFhLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsdUJBQWUsRUFBQyxNQUFNLENBQUMsQ0FBQztBQUVyRSxRQUFRO0FBQ0cscUJBQWEsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyx1QkFBZSxFQUFDLFlBQVksQ0FBQyxDQUFDIn0=

View File

@ -24,10 +24,10 @@
"dependencies": {
"@types/q": "^0.0.27",
"@types/shelljs": "^0.3.27",
"beautylog": "^5.0.14",
"cert": "0.0.17",
"beautylog": "^5.0.18",
"cert": "1.0.6",
"q": "^1.4.1",
"shelljs": "^0.7.0",
"shelljs": "^0.7.1",
"smartfile": "^4.0.12",
"smartstring": "^2.0.15"
},

View File

@ -27,6 +27,7 @@ describe("smartnginx", function () {
});
});
describe("NginxConfig", function () {
this.timeout(10000);
it(`"new NginxConfig()" should produce an instance of NginxConfig`, function () {
testNginxConfig = new smartnginx.NginxConfig({
cfEmail: process.env.CF_EMAIL,
@ -42,7 +43,7 @@ describe("smartnginx", function () {
});
});
describe(".deploy()", function () {
this.timeout(240000);
this.timeout(600000);
it("should deploy a config from an instance", function (done) {
testNginxConfig.deploy()
.then(() => {
@ -52,4 +53,4 @@ describe("smartnginx", function () {
});
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2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QyxDQUFDO2dCQUN6QyxlQUFlLENBQUMsT0FBTyxDQUFDLGVBQWUsQ0FBQyxDQUFDO1lBQzdDLENBQUMsQ0FBQyxDQUFBO1FBQ04sQ0FBQyxDQUFDLENBQUM7UUFDSCxRQUFRLENBQUMsV0FBVyxFQUFDO1lBQ2pCLElBQUksQ0FBQyxPQUFPLENBQUMsTUFBTSxDQUFDLENBQUM7WUFDckIsRUFBRSxDQUFDLHlDQUF5QyxFQUFDLFVBQVMsSUFBSTtnQkFDdEQsZUFBZSxDQUFDLE1BQU0sRUFBRTtxQkFDbkIsSUFBSSxDQUFDO29CQUNGLElBQUksRUFBRSxDQUFDO2dCQUNYLENBQUMsQ0FBQyxDQUFDO1lBQ1gsQ0FBQyxDQUFDLENBQUE7UUFDTixDQUFDLENBQUMsQ0FBQztJQUNQLENBQUMsQ0FBQyxDQUFDO0FBQ1AsQ0FBQyxDQUFDLENBQUMifQ==

View File

@ -27,6 +27,7 @@ describe("smartnginx",function(){
});
});
describe("NginxConfig",function(){
this.timeout(10000);
it(`"new NginxConfig()" should produce an instance of NginxConfig`,function(){
testNginxConfig = new smartnginx.NginxConfig({
cfEmail: process.env.CF_EMAIL,
@ -42,7 +43,7 @@ describe("smartnginx",function(){
})
});
describe(".deploy()",function(){
this.timeout(240000);
this.timeout(600000);
it("should deploy a config from an instance",function(done){
testNginxConfig.deploy()
.then(() => {

View File

@ -1,9 +1,6 @@
import * as plugins from "./smartnginx.plugins";
import * as CommandModule from "./smartnginx.command";
// classes
export {NginxConfig} from "./smartnginx.classes.nginxconfig";
export {NginxZone,zoneTypes} from "./smartnginx.classes.nginxzone";
// exports
export let command = CommandModule;
export {NginxProcess} from "./smartnginx.classes.nginxprocess";
export {NginxZone,zoneTypes} from "./smartnginx.classes.nginxzone";

View File

@ -1,67 +1,68 @@
import * as plugins from "./smartnginx.plugins";
import * as paths from "./smartnginx.paths";
import * as command from "./smartnginx.command";
import * as snippets from "./smartnginx.snippets"
import {NginxZone} from "./smartnginx.classes.nginxzone";
let allConfigs:NginxConfig[] = [];
import * as snippets from "./smartnginx.snippets";
import { NginxZone } from "./smartnginx.classes.nginxzone";
import { NginxProcess } from "./smartnginx.classes.nginxprocess";
let allConfigs: NginxConfig[] = [];
export class NginxConfig {
zones:NginxZone[] = [];
cert:plugins.cert.Cert; // the Cert Instance from which the config gets its certificates
isDeployed:boolean = false;
constructor(optionsArg:plugins.cert.ICertConstructorOptions){
zones: NginxZone[] = [];
cert: plugins.cert.Cert; // the Cert Instance from which the config gets its certificates
nginxProcess: NginxProcess = new NginxProcess(this);
isDeployed: boolean = false;
constructor(optionsArg: plugins.cert.ICertConstructorOptions) {
this.cert = new plugins.cert.Cert({
cfEmail:optionsArg.cfEmail,
cfKey:optionsArg.cfKey,
sslDir:paths.nginxCertBase,
gitOriginRepo:optionsArg.gitOriginRepo,
testMode:optionsArg.testMode
cfEmail: optionsArg.cfEmail,
cfKey: optionsArg.cfKey,
sslDir: paths.nginxCertBase,
gitOriginRepo: optionsArg.gitOriginRepo,
testMode: optionsArg.testMode
});
};
// interact with Zones
addZone(zoneArg:NginxZone){
addZone(zoneArg: NginxZone){
this.zones.push(zoneArg);
}
listZones():NginxZone[] {
listZones(): NginxZone[]{
return this.zones;
};
removeZones(zoneArg:NginxZone){
removeZones(zoneArg: NginxZone) {
}
clean(){
clean() {
this.zones = [];
}
// handle deployment of zones
deploy(nginxRestartArg:boolean = false){
deploy() {
let done = plugins.q.defer();
plugins.smartfile.fs.removeSync(paths.nginxConfigBase);
plugins.smartfile.fs.ensureDirSync(paths.nginxConfigBase);
plugins.smartfile.fs.ensureDirSync(paths.nginxZoneBase);
plugins.smartfile.fs.ensureDirSync(paths.nginxCertBase);
for(let config of allConfigs){
for (let config of allConfigs) {
config.isDeployed = false;
};
this.isDeployed = true;
// write base config
plugins.smartfile.memory.toFsSync(
snippets.getBaseConfigString(),
plugins.path.join(paths.nginxConfigBase,"nginx.conf")
paths.nginxConfFile
);
// deploy zones
let promiseArray = [];
for(let zone of this.zones){
promiseArray.push(zone.deploy(this.cert));
for (let zone of this.zones) {
let zoneDeployedPromise = zone.deploy(this.cert);
zoneDeployedPromise.then(() => {
plugins.beautylog.info(`Zone ${zone.zoneName} deployed!`);
this.nginxProcess.reloadConfig();
});
promiseArray.push(zoneDeployedPromise);
};
plugins.q.all(promiseArray)
.then(() => {
// restart nginx
if(nginxRestartArg){
command.restart(this);
};
done.resolve();
});
return done.promise;
};
};

View File

@ -0,0 +1,70 @@
import * as plugins from "./smartnginx.plugins";
import * as paths from "./smartnginx.paths";
import { NginxConfig } from "./smartnginx.classes.nginxconfig";
import { NginxZone } from "./smartnginx.classes.nginxzone";
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()
} else {
this.nginxChildProcess.kill("SIGHUP");
};
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") {
this.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
*/
check(): boolean {
return;
};
}

View File

@ -1,32 +1,31 @@
import * as plugins from "./smartnginx.plugins";
import * as paths from "./smartnginx.paths";
import * as command from "./smartnginx.command";
import * as snippets from "./smartnginx.snippets"
export enum zoneTypes {
reverseProxy,
static
reverseProxy,
static
}
export class NginxZone {
zoneName:string; // the zone name e.g. domain name
type:zoneTypes;
destination:string;
configString:string; // the actual zone config file as string
constructor(optionsArg:{
zoneName:string,
type:zoneTypes,
destination:string
}){
zoneName: string; // the zone name e.g. domain name
type: zoneTypes;
destination: string;
configString: string; // the actual zone config file as string
constructor(optionsArg: {
zoneName: string,
type: zoneTypes,
destination: string
}) {
this.zoneName = optionsArg.zoneName;
this.type = optionsArg.type;
this.destination = optionsArg.destination;
this.configString = snippets.getZoneConfigString(optionsArg.zoneName,optionsArg.destination);
this.configString = snippets.getZoneConfigString(optionsArg.zoneName, optionsArg.destination);
};
deploy(certInstanceArg:plugins.cert.Cert){
deploy(certInstanceArg: plugins.cert.Cert) {
let done = plugins.q.defer();
let filePath = plugins.path.join(paths.nginxZoneBase,this.zoneName + ".conf");
let filePath = plugins.path.join(paths.nginxZoneBase, this.zoneName + ".conf");
// writeConfig
plugins.smartfile.memory.toFsSync(this.configString,filePath);
plugins.smartfile.memory.toFsSync(this.configString, filePath);
// get cert
certInstanceArg.getDomainCert(this.zoneName)
.then(done.resolve);

View File

@ -1,59 +0,0 @@
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;
};

View File

@ -1,6 +1,10 @@
import * as plugins from "./smartnginx.plugins"
// directories
export let packageBase = plugins.path.join(__dirname,"../");
export let nginxConfigBase = plugins.path.join(packageBase,"nginxconfig");
export let nginxZoneBase = plugins.path.join(nginxConfigBase,"zones");
export let nginxCertBase = plugins.path.join(nginxConfigBase,"cert");
export let nginxCertBase = plugins.path.join(nginxConfigBase,"cert");
// files
export let nginxConfFile = plugins.path.join(nginxConfigBase,"nginx.conf");