- Shell 100%
|
|
||
|---|---|---|
| .forgejo/workflows | ||
| .editorconfig | ||
| .gitignore | ||
| LICENSE | ||
| README.md | ||
| wakeup-on-logs-test.sh | ||
| wakeup-on-logs.sh | ||
wakeup-on-logs.sh
Runs tail -f /var/log/nginx/access.log looking for the .well-known/wakeup-on-logs/([a-zA-Z0-9_.-]+) pattern. When a match is found, the matching script found in /etc/wakeup-on-logs is run. For instance, /etc/wakeup-on-logs/myscript will run if .well-known/wakeup-on-logs/myscript is found in the logs.
When a script is added to /etc/wakeup-on-logs, the daemon must be notified with sudo systemctl restart wakeup-on-logs-watch.
How does it work?
The systemctl status wakeup-on-logs-watch daemon tail -f /var/log/nginx/access.log. If the .well-known/wakeup-on-logs/([a-zA-Z0-9_.-]+) pattern is found, it will touch the corresponding file in /var/lib/wakeup-on-logs, if it exists. It runs under an unprivileged user and will discard a pattern that occur more frequently than every five minutes.
The systemctl status wakeup-on-logs-run daemon runs as root and waits for file modifications in /var/lib/wakeup-on-logs. When it finds one file was modified, it runs the matching script found in /etc/wakeup-on-logs. It runs one script at a time and imposes a five minutes timeout for them to complete.
Install and upgrades
Requires a running nginx server.
sudo wget -O /usr/local/bin/wakeup-on-logs.sh https://code.forgejo.org/infrastructure/wakeup-on-logs/raw/branch/main/wakeup-on-logs.sh ; sudo chmod +x /usr/local/bin/wakeup-on-logs.sh
sudo wakeup-on-logs.sh install
Reset throttling
sudo systemctl restart wakeup-on-logs-watch
It will also read the last 10 lines (default of tail(1)) of the log. If they contain a pattern for a task, it will run it.
Trigger a task
sudo journalctl --follow --unit wakeup-on-logs-run --unit wakeup-on-logs-watch
curl -o /dev/null -sS http://0.0.0.0/.well-known/wakeup-on-logs/hello
Add a task to the watch list
( echo '#/bin/bash' ; echo echo hello ) | sudo tee /etc/wakeup-on-logs/hello ; sudo chmod +x /etc/wakeup-on-logs/hello
sudo systemctl restart wakeup-on-logs-watch
test $(curl -o /dev/null -w "%{http_code}" -sS http://0.0.0.0/.well-known/wakeup-on-logs/echo) = 404 && echo OK
sudo systemctl status wakeup-on-logs-run
Remove a task from the watch list
rm /etc/wakeup-on-logs/hello
sudo systemctl restart wakeup-on-logs-watch
Update a task already in the watch list
$EDITOR /etc/wakeup-on-logs/hello