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

[Unit]
Description = webhook is a lightweight incoming webhook server to run shell commands
After = network.target

[Service]
ExecStart = /usr/local/bin/webhook -hooks /root/git/nicholaswilde/homelab/pve/webhook/hooks.yaml -verbose

[Install]
WantedBy = multi-user.target

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

task: Available tasks for this project:
* create-template:       Create template from existing .env file
* decrypt:               Decrypt sensitive configuration files using SOPS.
* default:               List all available tasks.
* enable:                Enable the application's systemd service.
* encrypt:               Encrypt sensitive configuration files using SOPS.
* export:                Export the task list to `task-list.txt`.
* follow:                Follow the logs
* init:                  Initialize the application's environment and configuration files.
* install-service:       Install the application's systemd service.
* mklinks:               Create symbolic links for configuration files.
* reload:                Reload the application's systemd service.
* restart:               Restart the application's systemd service.
* start:                 Start the application's systemd service.
* status:                Check the status of the application's systemd service.
* stop:                  Stop the application's systemd service.
* update:                Update the application or its running containers.
* upgrade:               Upgrade the application by pulling the latest changes and updating.
* watch:                 Watch the logs

🔗 References