File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ var Utility = require('./Utility');
2525var cst = require ( '../constants.js' ) ;
2626var timesLimit = require ( 'async/timesLimit' ) ;
2727var Configuration = require ( './Configuration.js' ) ;
28+ var which = require ( './tools/which' ) ;
2829
2930/**
3031 * Override cluster module configuration
@@ -215,8 +216,24 @@ God.executeApp = function executeApp(env, cb) {
215216 var appRunningCb = function ( clu ) {
216217 var post_start_hook = env_copy [ 'post_start_hook' ] ;
217218 if ( post_start_hook ) {
219+ // Full path script resolution
220+ var hook_path = path . resolve ( clu . pm2_env . cwd , post_start_hook ) ;
221+
222+ // If script does not exist after resolution
223+ if ( ! fs . existsSync ( hook_path ) ) {
224+ var ckd ;
225+ // Try resolve command available in $PATH
226+ if ( ( ckd = which ( post_start_hook ) ) ) {
227+ if ( typeof ( ckd ) !== 'string' )
228+ ckd = ckd . toString ( ) ;
229+ hook_path = ckd ;
230+ }
231+ else
232+ // Throw critical error
233+ return new Error ( `post_start_hook not found: ${ post_start_hook } ` ) ;
234+ }
218235 try {
219- var hookFn = require ( post_start_hook ) ;
236+ var hookFn = require ( hook_path ) ;
220237 if ( typeof hookFn !== 'function' ) {
221238 throw new Error ( 'post_start_hook module.exports must be a function' ) ;
222239 }
You can’t perform that action at this time.
0 commit comments