From d29893aea13aa220eb8feba084ca5274fef13614 Mon Sep 17 00:00:00 2001 From: Muthu Kumar Date: Fri, 3 Nov 2017 13:23:00 +0530 Subject: [PATCH] Bug that disallowed nginx reload has been squashed. --- actions/createProxyServer.js | 4 +++- actions/createStaticServer.js | 4 +++- index.js | 15 ++------------- package-lock.json | 2 +- util/nginxReload.js | 14 ++++++++++++++ 5 files changed, 23 insertions(+), 16 deletions(-) create mode 100644 util/nginxReload.js diff --git a/actions/createProxyServer.js b/actions/createProxyServer.js index 0e44040..0776aa0 100644 --- a/actions/createProxyServer.js +++ b/actions/createProxyServer.js @@ -2,6 +2,7 @@ var fs = require('fs-extra'); var shell = require('shelljs'); var npath = require('../util/nginxPath'); var conf = require('../util/nginxConf'); +var nginxReload = require('../util/nginxReload'); var { EOL } = require('os'); // \n if used on Linux, \r\n if used on Windows. @@ -26,7 +27,8 @@ function createProxyServer(domain, inPort, outPort) { ) shell.mkdir('-p', npath.enabledSites()); // Creates directory if doesn't exist shell.ln('-sf', conf(npath.availableSites(), domain), conf(npath.enabledSites(), domain)); // Symlink the conf file from sites-available to sites-enabled - exec("service nginx reload"); + + nginxReload(); }; module.exports = createProxyServer; \ No newline at end of file diff --git a/actions/createStaticServer.js b/actions/createStaticServer.js index 4fdf58c..c1a07c4 100644 --- a/actions/createStaticServer.js +++ b/actions/createStaticServer.js @@ -3,6 +3,7 @@ var shell = require('shelljs'); var npath = require('../util/nginxPath'); var conf = require('../util/nginxConf'); var path = require('path'); +var nginxReload = require('../util/nginxReload'); var currentPath = path.normalize(process.cwd()); var { EOL } = require('os'); // \n if used on Linux, \r\n if used on Windows. @@ -27,7 +28,8 @@ function createStaticServer(domain, outPort = 80) { shell.rm('-rf', npath.webRoot() + domain); // Removes domain from webroot if exists shell.mkdir('-p', npath.webRoot()); // Creating the nginx www path if it doesn't exist so symlink doesn't fail shell.ln('-sf', currentPath, npath.webRoot() + domain); // Symlink current directory to nginx's web root - exec("service nginx reload"); + + nginxReload(); }; module.exports = createStaticServer; \ No newline at end of file diff --git a/index.js b/index.js index 80078ec..4c5e626 100644 --- a/index.js +++ b/index.js @@ -5,9 +5,6 @@ var program = require('commander'); var shell = require('shelljs'); var fs = require('fs-extra'); var chalk = require('chalk'); -var { exec } = require('child_process'); - -var nginxReload = exec("nginx -t && service reload nginx"); // Requiring utils var validate = require('./util/validate'); @@ -18,7 +15,7 @@ var createProxyServer = require('./actions/createProxyServer'); var createStaticServer = require('./actions/createStaticServer'); // Check for requirements such as OS version and nginx install. Throw and exit if requirements not found. #Roadmap: Add ability to satisfy any possible requirements. -// requirements(); // Comment in development and uncomment this line in production. This should check whether the OS is compatible with this version of `up` +requirements(); // Comment in development and uncomment this line in production. This should check whether the OS is compatible with this version of `up` program .version('0.1.2') @@ -75,12 +72,4 @@ program.on('--help', function () { }); // Parses commands passed to `up` and chooses one of the above commands. -program.parse(process.argv); - -try { - nginxReload(); -} - -catch (e) { - console.log("nginx configuration failed! Unable to reload nginx. Check configuration manually!") -} \ No newline at end of file +program.parse(process.argv); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index ede61b0..0b002a6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "up-serve", - "version": "0.0.1", + "version": "0.1.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/util/nginxReload.js b/util/nginxReload.js new file mode 100644 index 0000000..e4ad7a1 --- /dev/null +++ b/util/nginxReload.js @@ -0,0 +1,14 @@ +var { exec } = require('child_process'); + +function nginxReload() { + exec('service nginx reload', (error, stdout, stderr) => { + if (error) { + console.error(`exec error: ${error}`); + return; + } + console.log(`stdout: ${stdout}`); + console.log(`stderr: ${stderr}`); + }); +} + +module.exports = nginxReload; \ No newline at end of file