PM2 module to listen webhooks from github, bitbucket, gitlab, jenkins and droneci. When a webhook is received you can run a script, pull your project, restart pm2, etc.
This project is highly inspired by vmarchaud/pm2-githook.
Features (changelog):
Wanted features, to be done during Mach/2017:
Possible features, as I need to think about it:
git pull on the folder, and make a prePull and postPull available commands (same approach as vmarchaud/pm2-githook)To install it simply run:
$ pm2 install pm2-hooks
Warning: This library currently (2017 feb 26) is in ALPHA state. This means some things:
pm2 install pm2-hooks. If for some reason the version on npm is outdated you always will be capable of run pm2 install desaroger/pm2-hooks to be sure to install the last version directly from the repository.By default pm2-hooks doesn't do anything. You need to set the key env_hook inside the config of a given app, inside the ecosystem file.
If env_hook isn't defined or is falsy then is disabled.
Example of an ecosystem file:
{
apps: [
{
name: 'api-1',
script: 'server.js'
},
{
name: 'api-2',
script: 'server.js',
env_hook: {
command: 'git pull && npm i && npm test && pm2 restart api-2',
cwd: '/home/desaroger'
}
}
]
}
Where api-1 has hook disabled and api-2 is enabled and when the hook is called, the command is executed.
spawn. (optional, but if not set this is not going to do nothing ¯\(ツ)/¯)spawn. Defaults to a blank object, and later we add the cwd.If you didn't install before, install it. If you installed it, then you will need to restart it. For that, run pm2 restart pm2-hooks.
Now you have a server on port 9000 by default. You can make a call to http://localhost:9000/api-2 to see the response.
If everything went fine, you will see:
{
status: 'success',
message: 'Route "api-2" was found'
code: 0
}
And the command had been executed.
Everything will be logged in the pm2 logs. For see them, run:
$ pm2 logs pm2-hooks
And for see the entire log:
$ cat ~/.pm2/logs/pm2-hooks-out-0.log
You can set the port (where the default port is 9000) setting it in the config of the pm2 module. For doing that, run:
$ pm2 set pm2-hooks:port 3000
You can uninstall this module running:
$ pm2 uninstall pm2-hooks
These are some projects I found similar to mine. Please let me know if you know anoher.
Copyright 2017 Roger Fos Soler
Licensed under the MIT License.
$ claude mcp add pm2-hooks \
-- python -m otcore.mcp_server <graph>