Leaving incrond for systemd.path

I’ve been having problems with incrond for months; after trying to upgrade from version 0.5.10, incrond would not trigger after a specified event occurred in the monitored path.

After upgrading to version 0.5.12-9 (I couldn’t use 0.5.10 because of security policies), incrond has started behaving in a completely random way: sometimes it was triggered as expected but some other times (way too many), nothing was happening.

This was the entry in incrontab:

/home/elena/upload IN_CLOSE_WRITE /bin/find $@ -type f -exec /bin/chmod g+rw {} \+

Writing a script and adding it to crontab was out of question; here is where systemd came in handy, with path units.

A .path unit (systemd.path) monitors a file or directory and it calls a .service unit (systemd.service), usually with the same name, when something happens to the monitored file or directory.Continue reading

Nagios plugin: monitor a systemd service

Here’s a tiny plugin to check if a systemd service is running:

#!/bin/bash
#
# машины
# 
# Check a if a systemd service is running
# 
# Usage: $0 
#
#Nagios exit codes
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=3

SERVICE=$1

# Check service status

systemctl -q is-active $SERVICE
if [[ $? -ne 0 ]]; then
    echo "ERROR: service $SERVICE is not running"
    exit $CRITICAL
fi

echo "OK: service $SERVICE is running"
exit $OK