Skip to content

Commit

Permalink
refactor startJson
Browse files Browse the repository at this point in the history
  • Loading branch information
Unitech committed Nov 18, 2014
1 parent dc59774 commit d56a919
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 66 deletions.
1 change: 0 additions & 1 deletion examples/child-pm2-v2.json → examples/child-echo.json
Expand Up @@ -5,7 +5,6 @@
"instances":3
},{
"script":"examples/echo.js",
"name":"API-io",
"instances":2
}],
"deploy" : {
Expand Down
73 changes: 15 additions & 58 deletions lib/CLI.js
Expand Up @@ -364,78 +364,35 @@ CLI.startJson = function(cmd, opts, jsonVia, cb) {

if (!Array.isArray(appConf)) appConf = [appConf]; //convert to array

(function ex(apps) {

if (apps.length == 0 || !apps) {
if (cb) return cb(null, apps);
else return speedList();
}

async.eachLimit(appConf, cst.CONCURRENT_ACTIONS, function(app, next) {
try {
if (opts.env) {
/**
* Merge specific environment variables
* `--env production` will merge `production_env` with the env
* -> for pm2-deploy
*/
apps[0].env = apps[0].env || {};
util._extend(apps[0].env, apps[0]['env_' + opts.env]);
app.env = app.env || {};
util._extend(app.env, app['env_' + opts.env]);
}

var appPaths = resolvePaths(apps[0]);
var app_paths = resolvePaths(app);
} catch(e) {
console.error(e.message, e.stack)
return cb ? cb({msg : 'Error'}) : exitCli(cst.ERROR_EXIT);
debug(e.stack || e);
return next();
}

// Set watch to true for app if argument passed to CLI
if (opts.watch)
appPaths.watch = true;

var rpcCall = 'findByScript';
var rpcArg = p.basename(appPaths.script);

//find script by port
if (appPaths.port) {
rpcCall = 'findByPort';
rpcArg = appPaths.port;
}
app_paths.watch = true;

Satan.executeRemote(rpcCall, rpcArg, function(err, exec) {

if (exec && !opts.force) {
printError('Script already launched, add -f option to force re execution');
nextApp();
return false;
} else {
launchApp(appPaths);
return false;
}
Satan.executeRemote('prepare', app_paths, function(err) {
printOut(cst.PREFIX_MSG + 'Process launched');
next();
});

/**
* Description
* @method launchApp
* @param {} appPaths
* @return
*/
function launchApp(appPaths){
Satan.executeRemote('prepare', appPaths, function(err) {
printOut('Process launched');
nextApp();
});
}

/**
* Description
* @method nextApp
* @return CallExpression
*/
function nextApp(){
apps.shift();
return ex(apps);
}

return false;
})(appConf);
}, function(err) {
return cb ? cb(err, appConf) : speedList();
});
};

/**
Expand Down
24 changes: 24 additions & 0 deletions lib/tmp
@@ -0,0 +1,24 @@


// var rpcCall = 'findByScript';
// var rpcArg = p.basename(appPaths.script);

// //find script by port
// if (appPaths.port) {
// rpcCall = 'findByPort';
// rpcArg = appPaths.port;
// }

// Satan.executeRemote(rpcCall, rpcArg, function(err, exec) {
// if (exec && !opts.force) {
// printError('Script already launched, add -f option to force re execution');
// nextApp();
// return false;
// } else {
// launchApp(appPaths);
// return false;
// }
// });

// return false;
// })(appConf);
2 changes: 1 addition & 1 deletion test/bash/log-reload.sh
Expand Up @@ -29,7 +29,7 @@ $pm2 kill

$pm2 start echo.js -o out-rel.log -e err-rel.log -x --merge-logs

sleep 0.5
sleep 1

grep "ok" out-rel.log
spec "Should have written te right stuff in out log in fork mode"
Expand Down
6 changes: 0 additions & 6 deletions test/fixtures/server-watch.js

This file was deleted.

0 comments on commit d56a919

Please sign in to comment.