Skip to content

webhook

webhook is a lightweight incoming webhook server to run shell commands. It is used to trigger scripts automatically, for example, to update the reprepro repository when a new package is available.

🛠 Installation

The webhook binary can be downloaded directly from the project's GitHub releases.

Install

# Download the latest binary for your architecture. This example is for amd64.
curl -LO https://github.com/adnanh/webhook/releases/download/2.8.0/webhook-linux-amd64.tar.gz
tar -xvzf webhook-linux-amd64.tar.gz
sudo mv webhook-linux-amd64/webhook /usr/local/bin/

⚙ Config

webhook is configured using a hooks.yaml file that defines the webhooks and the commands they execute. It is typically run as a systemd service to ensure it's always available.

🤝 Service

Install service

task install-service
sudo cp ./webhook.service /etc/systemd/system/"

/etc/systemd/system/webhook.service

--8<-- "webhook/webhook.service"

Enable service

(
  task enable && \
  task start && \
  task status
)
( 
 sudo systemctl enable webhook.service && \
 sudo systemctl start webhook.service && \
 sudo systemctl status webhook.service
)

🚀 Hooks

The hooks file defines the endpoints and the commands to be executed. This example shows a hook that triggers the reprepro update script.

homelab/pve/webhook/hooks.yaml
--8<-- "webhook/hooks.yaml"    

📝 Usage

Trigger

To trigger a hook, send an HTTP request to the webhook URL from any machine on your network.

Trigger hook

# The hook ID from hooks.yaml is specified in the URL
curl http://<webhook-server-ip>:9000/hooks/redeploy-webhook

📜 Logs

Logs for the webhook service and the scripts it executes are available through journalctl. It's helpful to distinguish between the logs from the webhook server itself and the output from the scripts it triggers.

Webhook Service Logs

These logs show the activity of the webhook server, such as incoming HTTP requests and hook matching. They are useful for debugging triggering issues.

View Service Status and Recent Logs

task status
systemctl status webhook.service

Follow Service Logs

journalctl -u webhook.service -f

Script Execution Logs

Thanks to the logger command in the hook configuration, the output of the update-reprepro-service.sh script is sent to the journal with a specific tag.

Follow Script Logs

task follow
journalctl -f -t reprepro-updater

Task List

--8<-- "webhook/task-list.txt"

🔗 References