Skip to content

Commit 4d24960

Browse files
committed
Support globally installed scripts as post_start_hook
1 parent 605482f commit 4d24960

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

lib/God.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var Utility = require('./Utility');
2525
var cst = require('../constants.js');
2626
var timesLimit = require('async/timesLimit');
2727
var 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
}

0 commit comments

Comments
 (0)