Comments
You can use your Mastodon account to reply to this post.
A webhook is a an HTTP endpoint that triggers ‘some action’. The action will be specific for the application that provides the endpoint. In my case the action/endpoint will update my blog. Let’s ignore for a moment how exactly ‘updating the blog’ works, and just pretend I want to execute some arbitrary command on my server as soon as I call some very specific URL.
The Exec Module (for some reason caddy calls plugins ‘modules’) allows to bind a path to a command. So a config in the caddyfile like
|
|
would create an empty file on the server when someone calls example.com/createFile
. Instead of creating a file we could run any series of command line tools.
The final result and how my workflow looks is already sketched in this note. While I imagined it to be pretty straight forward, it took me several hours in the end to put it together. In case you are not familar with the term yak shaving I highly recommend to read Don’t Shave That Yak!. Spoiler ahead, I did shave that yak!
So what happened? Luckily, I took notes while implementing the solution. This is how they look
|
|
sudo systemctl start caddy
|
|
sudo systemctl reload caddy
apt
refresh_blog.sh
script
|
|
I struggled with installing the Exec module. Also I encountered some weird behaviour where I could run the script, but when caddy executed the same script, the cp
(copy) command produced some read only file-system
errors. Anyway, in the end it worked and now my Hugo-based blog updates in less than 1 seconds.
Happy Easter.