@@ -576,16 +576,18 @@ CLI.updatePM2 = function(cb) {
576576 printOut ( 'Be sure to have the latest version by doing `npm install pm2@latest -g` before doing this procedure.' ) ;
577577
578578 // Dump PM2 processes
579+ Satan . executeRemote ( 'notifyKillPM2' , { } , function ( ) { } ) ;
579580 CLI . dump ( function ( err ) {
580581 debug ( 'Dumping successfull' , err ) ;
581582 CLI . killDaemon ( function ( ) {
582583 debug ( '------------------ Everything killed' , arguments ) ;
583584 Satan . launchDaemon ( function ( err , child ) {
584585 Satan . launchRPC ( function ( ) {
585- require ( './Modularizer.js' ) . launchAll ( ) ;
586586 CLI . resurrect ( function ( ) {
587587 printOut ( chalk . blue . bold ( '>>>>>>>>>> PM2 updated' ) ) ;
588- return cb ? cb ( null , { success :true } ) : speedList ( ) ;
588+ require ( './Modularizer.js' ) . launchAll ( function ( ) {
589+ return cb ? cb ( null , { success :true } ) : speedList ( ) ;
590+ } ) ;
589591 } ) ;
590592 } ) ;
591593 } ) ;
@@ -769,6 +771,9 @@ CLI._reloadProcessName = function(process_name, reload_method, cb) {
769771 } ) ;
770772} ;
771773
774+ /**
775+ * Execute command with locking system
776+ */
772777CLI . remote = function ( command , opts , cb ) {
773778 var proc_name = opts . name ;
774779
@@ -951,13 +956,16 @@ CLI._operate = function(action_name, process_name, envs, cb) {
951956 async . eachLimit ( ids , cst . CONCURRENT_ACTIONS , function ( id , next ) {
952957 var opts = id ;
953958 if ( action_name == 'restartProcessId' ) {
954- opts = { id : id , env : util . _extend ( process . env , envs ) } ;
959+ opts = {
960+ id : id ,
961+ env : process . env . PM2_PROGRAMMATIC === true ? { } : util . _extend ( process . env , envs )
962+ } ;
955963 }
956964
957965 Satan . executeRemote ( action_name , opts , function ( err , res ) {
958966 if ( err ) {
959967 printError ( cst . PREFIX_MSG_ERR + 'Process %s not found' , id ) ;
960- return next ( new Error ( 'Process not found' ) ) ;
968+ return next ( 'Process not found' ) ;
961969 }
962970
963971 if ( action_name == 'restartProcessId' ) {
@@ -1015,8 +1023,9 @@ CLI._operate = function(action_name, process_name, envs, cb) {
10151023 */
10161024 if ( full_detail && typeof ( ids [ 0 ] ) !== 'undefined' && full_detail [ ids [ 0 ] ] &&
10171025 full_detail [ ids [ 0 ] ] . pm2_env && full_detail [ ids [ 0 ] ] . pm2_env . pmx_module === true ) {
1018- var module_conf = Configuration . getAllSync ( ) ;
1019- util . _extend ( envs , module_conf ) ;
1026+
1027+ var additional_env = Modularizer . getAdditionalConf ( process_name ) ;
1028+ util . _extend ( envs , additional_env ) ;
10201029 }
10211030
10221031
@@ -1410,14 +1419,17 @@ CLI.ilogs = function() {
14101419CLI . killDaemon = function ( cb ) {
14111420 printOut ( cst . PREFIX_MSG + 'Stopping PM2...' ) ;
14121421
1413- CLI . _operate ( 'deleteProcessId' , 'all' , function ( err , list ) {
1414- printOut ( cst . PREFIX_MSG + 'All processes has been stopped and deleted' ) ;
1422+ Satan . executeRemote ( 'notifyKillPM2' , { } , function ( ) { } ) ;
1423+ CLI . killAllModules ( function ( ) {
1424+ CLI . _operate ( 'deleteProcessId' , 'all' , function ( err , list ) {
1425+ printOut ( cst . PREFIX_MSG + 'All processes has been stopped and deleted' ) ;
14151426
1416- InteractorDaemonizer . killDaemon ( function ( err , data ) {
1417- Satan . killDaemon ( function ( err , res ) {
1418- if ( err ) printError ( err ) ;
1419- printOut ( cst . PREFIX_MSG + 'PM2 stopped' ) ;
1420- return cb ? cb ( err , res ) : exitCli ( cst . SUCCESS_EXIT ) ;
1427+ InteractorDaemonizer . killDaemon ( function ( err , data ) {
1428+ Satan . killDaemon ( function ( err , res ) {
1429+ if ( err ) printError ( err ) ;
1430+ printOut ( cst . PREFIX_MSG + 'PM2 stopped' ) ;
1431+ return cb ? cb ( err , res ) : exitCli ( cst . SUCCESS_EXIT ) ;
1432+ } ) ;
14211433 } ) ;
14221434 } ) ;
14231435 } ) ;
@@ -1463,6 +1475,16 @@ CLI.publish = function(module_name, cb) {
14631475 } ) ;
14641476} ;
14651477
1478+ CLI . killAllModules = function ( cb ) {
1479+ Common . getAllModulesId ( function ( err , modules_id ) {
1480+ async . forEachLimit ( modules_id , 1 , function ( id , next ) {
1481+ CLI . _operate ( 'deleteProcessId' , id , next ) ;
1482+ } , function ( ) {
1483+ return cb ? cb ( ) : false ;
1484+ } ) ;
1485+ } ) ;
1486+ } ;
1487+
14661488CLI . deleteModule = function ( module_name , cb ) {
14671489 var found_proc = [ ] ;
14681490
@@ -1489,10 +1511,16 @@ CLI.deleteModule = function(module_name, cb) {
14891511 } ) ;
14901512} ;
14911513
1492- function displayConf ( cb ) {
1493- printOut ( '\nCurrent values available' ) ;
1514+ function displayConf ( target_app , cb ) {
1515+ if ( typeof ( target_app ) == 'function' ) {
1516+ cb = target_app ;
1517+ target_app = null ;
1518+ }
1519+
1520+ printOut ( '' ) ;
1521+
14941522 Configuration . getAll ( function ( err , data ) {
1495- UX . dispKeys ( data ) ;
1523+ UX . dispKeys ( data , target_app ) ;
14961524 return cb ( ) ;
14971525 } ) ;
14981526} ;
@@ -1503,7 +1531,28 @@ CLI.set = function(key, value, cb) {
15031531 return exitCli ( cst . ERROR_EXIT ) ;
15041532 }
15051533
1506- displayConf ( function ( ) {
1534+ var values = [ ] ;
1535+
1536+ if ( key . indexOf ( '.' ) > - 1 )
1537+ values = key . split ( '.' ) ;
1538+
1539+ if ( key . indexOf ( ':' ) > - 1 )
1540+ values = key . split ( ':' ) ;
1541+
1542+ if ( values && values . length > 1 ) {
1543+ // The first element is the app name (module_conf.json)
1544+ var app_name = values [ 0 ] ;
1545+
1546+ Common . printOut ( cst . PREFIX_MSG + 'Restarting module %s' , app_name ) ;
1547+ CLI . restart ( app_name , function ( err , data ) {
1548+ Common . printOut ( cst . PREFIX_MSG + 'Module %s restarted' , app_name ) ;
1549+ displayConf ( app_name , function ( ) {
1550+ return exitCli ( cst . SUCCESS_EXIT ) ;
1551+ } ) ;
1552+ } ) ;
1553+ return false ;
1554+ }
1555+ displayConf ( app_name , function ( ) {
15071556 return exitCli ( cst . SUCCESS_EXIT ) ;
15081557 } ) ;
15091558 } ) ;
0 commit comments