From f47f7d20b890da6ec3d2df072383100a897f542f Mon Sep 17 00:00:00 2001 From: tknew2 Date: Mon, 23 Jun 2014 15:10:18 +0200 Subject: [PATCH] fix deploy stuff --- README.md | 8 ++++-- lib/CLI.js | 72 +++++++++++++++++++++++++++---------------------- lib/sample.json | 10 ++++--- package.json | 2 +- 4 files changed, 54 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index e5ba9354..bd69ceaa 100644 --- a/README.md +++ b/README.md @@ -628,8 +628,10 @@ It contains this: "name" : "API", "script" : "app.js", "env": { - "NODE_ENV": "production", - "AWESOME_SERVICE_API_TOKEN": "xxx" + "COMMON_VARIABLE": "true" + }, + "env_production" : { + "NODE_ENV": "production" } },{ "name" : "WEB", @@ -639,12 +641,14 @@ It contains this: "production" : { "user" : "node", "host" : "212.83.163.1", + "ref" : "origin/master", "repo" : "git@github.com:repo.git", "path" : "/var/www/production" }, "dev" : { "user" : "node", "host" : "212.83.163.1", + "ref" : "origin/master", "repo" : "git@github.com:repo.git", "path" : "/var/www/development" } diff --git a/lib/CLI.js b/lib/CLI.js index 8ddfef89..ca2e7c42 100644 --- a/lib/CLI.js +++ b/lib/CLI.js @@ -717,13 +717,19 @@ CLI._reloadProcessName = function (process_name, reload_method, cb) { /** * Start or restart|reload|gracefulReload a JSON configuration file - * @param {string} action restart|reload + * @param {string} action restart|reload * @param {string} json_conf json file path - * @param {string} opts option like environment type and co + * @param {string} opts option like environment type and co * @callback cb optionnal */ CLI._jsonStartOrAction = function(action, json_conf, opts, cb) { - var data = fs.readFileSync(json_conf); + try { + var data = fs.readFileSync(json_conf); + } catch(e) { + printError('Configuration file %s is missing. Action canceled.', json_conf); + return cb ? cb(e) : exitCli(cst.ERROR_EXIT); + } + var appConf = JSON.parse(data); // v2 JSON declaration if (appConf.apps) appConf = appConf.apps; @@ -1004,15 +1010,16 @@ CLI._stopAll = function(cb) { * @param {} name * @return */ -CLI._stopProcessName = function(name, cb) { Satan.executeRemote('stopProcessName', name, function(err, list) { - if (err) { - printError(err); - return cb ? cb({msg:err}) : exitCli(cst.ERROR_EXIT); - } - printOut(cst.PREFIX_MSG + 'Stopping process by name ' + name); - return cb ? cb(null, list) : speedList(); -}); - }; +CLI._stopProcessName = function(name, cb) { + Satan.executeRemote('stopProcessName', name, function(err, list) { + if (err) { + printError(err); + return cb ? cb({msg:err}) : exitCli(cst.ERROR_EXIT); + } + printOut(cst.PREFIX_MSG + 'Stopping process by name ' + name); + return cb ? cb(null, list) : speedList(); + }); +}; /** * Description @@ -1020,15 +1027,16 @@ CLI._stopProcessName = function(name, cb) { Satan.executeRemote('stopProcessName * @param {} pm2_id * @return */ -CLI._stopId = function(pm2_id, cb) { Satan.executeRemote('stopProcessId', pm2_id, function(err, list) { - if (err) { - printError(err); - return cb ? cb({msg:err}) : exitCli(cst.ERROR_EXIT); - } - printOut(cst.PREFIX_MSG + ' Process stopped'); - return cb ? cb(null, list) : speedList(); -}); - }; +CLI._stopId = function(pm2_id, cb) { + Satan.executeRemote('stopProcessId', pm2_id, function(err, list) { + if (err) { + printError(err); + return cb ? cb({msg:err}) : exitCli(cst.ERROR_EXIT); + } + printOut(cst.PREFIX_MSG + ' Process stopped'); + return cb ? cb(null, list) : speedList(); + }); +}; /** * Description @@ -1038,12 +1046,11 @@ CLI._stopId = function(pm2_id, cb) { Satan.executeRemote('stopProcessId', pm2_id */ CLI.generateSample = function() { var sample = fs.readFileSync(path.join(__dirname, cst.SAMPLE_FILE_PATH)); - var dt = sample.toString(); + var dt = sample.toString(); var f_name = 'ecosystem.json'; fs.writeFileSync(path.join(process.env.PWD, f_name), dt); - printOut('Sample generated on current folder\n%s :\n', f_name); - printOut(dt); + printOut('File %s generated', path.join(process.env.PWD, f_name)); exitCli(cst.SUCCESS_EXIT); }; @@ -1052,14 +1059,15 @@ CLI.generateSample = function() { * @method list * @return */ -CLI.list = function(cb) { Satan.executeRemote('getMonitorData', {}, function(err, list) { - if (err) { - printError(err); - return cb ? cb({msg:err}) : exitCli(cst.ERROR_EXIT); - } - return cb ? cb(null, list) : speedList(); -}); - }; +CLI.list = function(cb) { + Satan.executeRemote('getMonitorData', {}, function(err, list) { + if (err) { + printError(err); + return cb ? cb({msg:err}) : exitCli(cst.ERROR_EXIT); + } + return cb ? cb(null, list) : speedList(); + }); +}; /** * Description diff --git a/lib/sample.json b/lib/sample.json index 02a34416..91cac4ae 100644 --- a/lib/sample.json +++ b/lib/sample.json @@ -3,10 +3,12 @@ "name" : "API", "script" : "app.js", "env": { - "NODE_ENV": "production", - "AWESOME_SERVICE_API_TOKEN": "xxx" + "COMMON_VARIABLE": "true" + }, + "env_production" : { + "NODE_ENV": "production" } - }, { + },{ "name" : "WEB", "script" : "web.js" }], @@ -14,12 +16,14 @@ "production" : { "user" : "node", "host" : "212.83.163.1", + "ref" : "origin/master", "repo" : "git@github.com:repo.git", "path" : "/var/www/production" }, "dev" : { "user" : "node", "host" : "212.83.163.1", + "ref" : "origin/master", "repo" : "git@github.com:repo.git", "path" : "/var/www/development" } diff --git a/package.json b/package.json index 0c8122d2..7d48543b 100644 --- a/package.json +++ b/package.json @@ -107,7 +107,7 @@ "pm2-multimeter": "~0.1.2", "pm2-interface": "~0.1.3", "pm2-axon-rpc": "~0.0.2", - "pm2-deploy" : "~0.0.3", + "pm2-deploy" : "~0.0.4", "axon": "~1.0.0", "cron": "~1.0.4", "colors": "~0.6.2",