The systemd APIs that contain information about the start or stop of service units are:
The systemd journal. You can listen to it by executing journalctl or forwarding it via network to your program or watching for changes to the files on disk. E.g.: execute
journalctl --follow -o json-pretty _PID=1(you can add various filters like
UNIT=gdm.serviceto only get those for one service) and then parse
stdoutaccording to the systemd journal json output format to get the journal messages of systemd. Use the
MESSAGE_IDto match what the event means and watch for unknown messages to know when an existing message got replaced with a new one. While this might work robustly enough, log messages are not primarily intended as an API. As such I would recommend to use the below options.
systemd units via their dependencies (like