I'd like to write C/C++ applications and provide an API for them to communicate directly with systemd
-managed services. Effectively, I'd like my applications to be able to do the equivalent of systemctl start service_name@unit_number.service
without using system()
, popen()
, or exec()
calls (hard requirement).
Is there a simple C/C++ API for communicating with systemd
, assuming systemd
version 219 (i.e. CentOS v7.4, also a hard requirement)?
systemd
-managed services in C/C++ and found the odd discussion on the topic, but haven't found any good examples.systemctl
version 219 from source, but then I potentially run afoul of GPL licensing.libsystemd
just for an application-specific benefit, and I'm apparently not the first person to raise this concern. systemd
v219.system()
/popen()
/exec()
calls to the systemctl
CLI utility.Is there a simpler API that I could use on CentOS v7.4 (even if I have to supply the shared library myself) that can be used to communicate with systemd
in a simple, reliable manner directly via C/C++ code? If the existing libdbus-1.so
API is complicated but still reliable, and I can create a reliable/stable wrapper library around it, I'm open to exploring that option. Also, if it's possible to manually build and deploy the SD-BUS components independent of systemd
and use them without having to modify/upgrade the systemd
library/daemon already on the system, I could potentially go that route too.
Thank you.
RestartSec= Configures the time to sleep before restarting a service (as configured with Restart= ). Takes a unit-less value in seconds, or a time span value such as "5min 20s". Defaults to 100ms.
The ExecStop setting is optional and is used to communicate with the service for a clean termination. The process specified by ExecStop will run in case the service crashes.
ExecStart. The commands and arguments executed when the service starts. ExecStartPre, ExecStartPost. Additional commands that are executed before or after the command in ExecStart . ExecReload.
As you already figured out, you should only interact with systemd using a dbus library, there is no other supported way to do so. Even if you lifted the requirement of no execution of binaries, it will remain frowned upon, as the *ctl tools are command line user interfaces not intended or designed to be called from other programs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With