@@ -13,6 +13,7 @@ var util = require('util');
1313var watch = require ( 'watch' ) ;
1414
1515const PREFIX_MSG = '\x1B[32m⌬ PM2 \x1B[39m' ;
16+ const PREFIX_MSG_ERR = '\x1B[31m⌬ PM2 [ERROR] \x1B[39m' ;
1617const SUCCESS_EXIT = 0 ;
1718const ERROR_EXIT = 1 ;
1819const SAMPLE_FILE_PATH = '../lib/sample.json' ;
@@ -33,7 +34,7 @@ commander.version(pkg.version)
3334//
3435// Start command
3536//
36- commander . command ( 'start <part >' )
37+ commander . command ( 'start <script >' )
3738 . description ( 'start specific part' )
3839 . action ( function ( cmd ) {
3940 if ( cmd . indexOf ( '.json' ) > 0 )
@@ -59,7 +60,7 @@ commander.command('stopAll')
5960commander . command ( 'stop <pm2_id>' )
6061 . description ( 'stop specific process pm2 id' )
6162 . action ( function ( pm2_id ) {
62- console . log ( PREFIX_MSG + 'Stopping process' + pm2_id ) ;
63+ console . log ( PREFIX_MSG + 'Stopping process ' + pm2_id ) ;
6364 UX . processing . start ( ) ;
6465 CLI . stopId ( pm2_id ) ;
6566 } ) ;
@@ -284,7 +285,7 @@ CLI.startFile = function(script) {
284285
285286 Satan . executeRemote ( 'findByScript' , { script : appConf . script } , function ( err , exec ) {
286287 if ( exec && ! commander . force ) {
287- console . log ( PREFIX_MSG + 'Script already launched, add -f option to force re execution' ) ;
288+ console . log ( PREFIX_MSG_ERR + 'Script already launched, add -f option to force re execution' ) ;
288289 process . exit ( ERROR_EXIT ) ;
289290 }
290291
@@ -445,11 +446,14 @@ CLI.web = function() {
445446CLI . restart = function ( pm2_id ) {
446447 Satan . executeRemote ( 'list' , { } , function ( err , list ) {
447448 list . forEach ( function ( l ) {
448- if ( l . pm_id == pm2_id ) {
449+ if ( l . pm_id == pm2_id && l . status != 'stopped' ) {
449450 try {
450451 process . kill ( l . pid ) ;
451452 } catch ( e ) { }
452453 }
454+ else if ( l . pm_id == pm2_id && l . status == 'stopped' ) {
455+ Satan . executeRemote ( 'startId' , { id : l . pm_id } , function ( err , list ) { } ) ;
456+ }
453457 } ) ;
454458 setTimeout ( function ( ) {
455459 console . log ( '\n' + PREFIX_MSG + 'Process ' + pm2_id + ' restarted' ) ;
@@ -486,7 +490,11 @@ CLI.stopId = function(pm2_id) {
486490 Satan . executeRemote ( 'stopId' , {
487491 id : pm2_id
488492 } , function ( err , list ) {
489- if ( err ) process . exit ( ERROR_EXIT ) ;
493+ if ( err ) {
494+ console . log ( '\n' + PREFIX_MSG_ERR + pm2_id + ' : pm2 id not found' ) ;
495+ process . exit ( ERROR_EXIT ) ;
496+ }
497+
490498 console . log ( '\n' ) ;
491499 console . log ( PREFIX_MSG + 'Process stopped' ) ;
492500 UX . processing . stop ( ) ;
@@ -606,7 +614,10 @@ function speedList() {
606614function resolvePaths ( app ) {
607615 app [ "pm_exec_path" ] = path . resolve ( process . cwd ( ) , app . script ) ;
608616
609- fs . existsSync ( app . pm_exec_path ) ;
617+ if ( fs . existsSync ( app . pm_exec_path ) == false ) {
618+ console . log ( PREFIX_MSG_ERR + 'script not found : ' + app . pm_exec_path ) ;
619+ process . exit ( ERROR_EXIT ) ;
620+ }
610621
611622 // Set current env
612623 util . _extend ( app , process . env ) ;
@@ -615,7 +626,7 @@ function resolvePaths(app) {
615626 app [ "pm_out_log_path" ] = path . resolve ( process . cwd ( ) , app . fileOutput ) ;
616627 else {
617628 if ( ! app . name ) {
618- console . log ( PREFIX_MSG + 'You havent specified log path, please specify at least a "name" field in the JSON' ) ;
629+ console . log ( PREFIX_MSG_ERR + 'You havent specified log path, please specify at least a "name" field in the JSON' ) ;
619630 process . exit ( ERROR_EXIT ) ;
620631 }
621632 app [ "pm_out_log_path" ] = path . resolve ( cst . DEFAULT_LOG_PATH , [ app . name , '-out.log' ] . join ( '' ) ) ;
@@ -636,8 +647,9 @@ function resolvePaths(app) {
636647 app . pidFile = app [ "pm_pid_path" ] ;
637648 }
638649
639- fs . existsSync ( app . pm_out_log_path ) ;
640- fs . existsSync ( app . pm_err_log_path ) ;
641-
650+ if ( ! fs . existsSync ( app . pm_out_log_path ) || ! fs . existsSync ( app . pm_err_log_path ) ) {
651+ console . log ( PREFIX_MSG_ERR + 'logs file not accessible : ' + app . pm_out_log_path + ' | ' + app . pm_err_log_path ) ;
652+ process . exit ( ERROR_EXIT ) ;
653+ }
642654 return app ;
643655}
0 commit comments