| Crates.io | patrolilo |
| lib.rs | patrolilo |
| version | 0.2.0 |
| created_at | 2024-12-22 12:27:44.086253+00 |
| updated_at | 2024-12-22 14:36:23.974713+00 |
| description | Job scheduler with integrated NTFY notifications |
| homepage | |
| repository | https://codeberg.org/dscottboggs/patrolilo |
| max_upload_size | |
| id | 1491903 |
| size | 95,846 |
This is probably the 4th attempt I've made at putting something together like this, and it seems like I've finally hit on a winner. Simple YAML definition of scheduled tasks with integrated mobile notifications of script failure through NTFY.
Using ntfy.sh or your self-hosted NTFY instance, configure a user with limited
access and an API key. Command-line directions are shown here for self-hosting
users.
$ # Add a user to publish notifications
$ ntfy user add patrolilo
$ # Don't allow that user's credentials to be used to do anything but publish to your desired channel
$ ntfy access patrolilo '*' deny
$ ntfy access patrolilo patrolilo write-only
$ # Generate an API token
$ ntfy token patrolilo
tk_zSuperSECRETtoken8jFW17GPoVTX
Save the API token to put into your config file.
Install the binary, either with cargo install or by downloading it from the
releases page.
Create a config file at $XDG_CONFIG_HOME/patrolilo/config.yml like this:
jobs:
- name: Test
script: |
if docker ps | grep -qv unhealthy
then
echo all services healthy
else
# print some diagnostic info about what's wrong for the notification
docker ps | grep unhealthy
exit 1
fi
# S M H D M DoW
when: 0 * * * * *
- name: Test fail
script: |
print("This is an example which uses a python script and always fails")
exit(1)
when: 0 */5 * * * *
shell: python
notifications:
server: ntfy.example.com
channel: patrolilo
auth key: tk_zSuperSECRETtoken8jFW17GPoVTX
By default all scripts are interpreted by the program at $SHELL, but a
different shell may be specified per-job using the shell option. Note that
the "when" field accepts an optional seconds field.
To get the tool to run at boot, create a systemd user service. The simplest way is to run these commands:
$ mkdir -p $HOME/.config/systemd/user
$ curl https://codeberg.org/dscottboggs/patrolilo/src/branch/main/patrolilo.service \
> $HOME/.config/systemd/user/patrolilo.service
$ systemctl --user enable --now patrolilo
The last command will immediately start the service and tell systemd to start
it again on reboot. Run systemctl --user status patrolilo to make sure it is
running well, and journalctl -xeu patrolilo to view the logs.
I'd like to give most of the credit for this to the tools that made this so simple to build, so let's take a peek under the hood.
Everything centers around the tokio-cron-scheduler
crate, which gives us a super simple interface to create a list of scripts and
tell them when to be run.
Of course, the NTFY notification service has been an
incredible tool for me, a real game changer. No more SMTP or bots, just a simple
reqwest.
If you have the time, I encourage you to take a look through main.rs, it's
less than 100 lines and very straightforward. It's worth taking the time to
appreciate all the wonderful tools this ecosystem has to offer.