A simple webhook handler written in Typescript that executes a command on receipt of a webhook. Inspired by Docker Hook.
Transpiled to a single javascript executable with zero dependencies.
Requires Node 16 for safe exiting when exception thrown (no use of make-promises-safe
).
Download
curl https://raw.githubusercontent.com/wworrall/hook-cmd/master/bin/hook-cmd > /usr/local/bin/hook-cmd;
Make executable
chmod +x /usr/local/bin/hook-cmd;
Create configuration as a JSON file:
// hookCmdConfig.json
{
"hookCmds": [
{
"hook": "top-secret-key", // Hook will be listened for at http://localhost:<port>/<hook>"
"cmd": "echo", // hello world
"args": ["hello world"] // [optional] array of arguments
}
],
"port": 5000 // [optional] defaults to 5000
}
Pass configuration filename in to hook-cmd
as the first argument.
hook-cmd hookCmdConfig.json
std log
and std err
of the commands are piped to std log
and std err
of the parent hook-cmd
process.
May only be accurate for Ubuntu
- Place the following in to a file named
/etc/systemd/system/hook-cmd.service
.
[Unit]
Description=Hook CMD
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=ubuntu
ExecStart=hook-cmd /path/to/hookCmdConfig.json
StandardOutput=journal+console
StandardError=journal+console
[Install]
WantedBy=multi-user.target
-
Remember to change
User=ubuntu
if required and change/path/to/hookCmdConfig.json
. -
Run:
service hook-cmd start
- To enable automatic start on system boot:
systemctl enable hook-cmd
- Tip: you can tail the logs of the service by running:
journalctl -u hook-cmd -b -f
If you have any suggestions please open up an issue.