Skip to content

A simple webhook handler written in Typescript that executes a command on receipt of a webhook.

License

Notifications You must be signed in to change notification settings

wworrall/hook-cmd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hook CMD

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).

Usage

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.

Run as service (recommended)

May only be accurate for Ubuntu

  1. 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
  1. Remember to change User=ubuntu if required and change /path/to/hookCmdConfig.json.

  2. Run:

service hook-cmd start
  1. To enable automatic start on system boot:
systemctl enable hook-cmd
  1. Tip: you can tail the logs of the service by running:
journalctl -u hook-cmd -b -f

Contributing

If you have any suggestions please open up an issue.

License

MIT License

About

A simple webhook handler written in Typescript that executes a command on receipt of a webhook.

Resources

License

Stars

Watchers

Forks

Packages

No packages published