Replacing incron with adhocify and systemd
Introduction
In one of our businesses, we process a lot of inbound EDI and EDI-like data. We like to process those inbound data in real-time and to do so we use Linux’s inotify facilities and have primarily done so via incron . However, incron appears to be abandonware and we keep stumbling upon irritating bugs with it. And so, in September of 2023, I tried to find a solid replacement for incron that did not change the paradigm that we have in place and that we like.
I honestly expected to find a modern incron replacement, but it appears that no such thing exists. I evaluated many solutions posed by a number of people that Google turned up, but I didn’t like any of them. And so, I designed a solution that works well for us and that solution is described in this article.
In brief, we replaced the entries within our /etc/incron.d/* files with systemd service units that utilize adhocify .
An Example Incron Configuration
This is an example of the type of entries that we have had incron manage that we replaced with adhocify within systemd service units:
$ cat /etc/incron.d/example
/home/customer/events_from_vendor IN_CLOSE_WRITE,recursive=false,loopable=true /usr/local/bin/process_customer_events_from_vendor.sh $@/$#
Adhocify Replacement Configuration
This is a systemd service unit config file to replace the entry shown above:
$ cat /etc/systemd/system/adhocify-customer_events_from_vendor.service
[Unit]
Description=Adhocify-led Processing of Customer Events from Vendor
After=network.target
[Service]
ExecStart=/usr/local/bin/adhocify --mask IN_CLOSE_WRITE --path /home/customer/events_from_vendor /usr/local/bin/process_customer_events_from_vendor.sh {}
KillMode=control-group
Restart=always
RestartSec=10s
Type=simple
[Install]
WantedBy=multi-user.target
Notes / Wrap-up
- Be sure to remove /etc/incron.d/<foo> entries and restart incron prior to enabling the adhocify+systemd unit replacement.
- The adhocify-customer_events_from_vendor.service will need to be enabled and started via systemctl, which is outside the scope of this article.
- One nice side effect of this solution is that standard output from all
of the processing is logged to the systemd unit, and so,
“systemctl status <service>" will show the status and most recent logs and“journalctl –no-pager -u <service>" will show all of the logs. - I built adhocify v1.1 myself, by simply running make in the source tree, and then I copied the binary into /usr/local/bin/.
- I do not know if this solution can replace all incron use cases, but it nicely covers ours.
Postscript
Not long after implementing the solution described in this article, I discovered the official GNU project named direvent, which seems like a great and cross-platform incron replacement that would work well for our use cases. Had I found direvent first, this blog post likely would have not ever been written. https://www.gnu.org.ua/software/direvent/