Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start systemd service from C/C++ application or call a D-Bus service

I have a .service for a process that i don't want to start at boot-time, but to call it somehow from another already running application, at a given time.

The other option would be to put a D-Bus (i'm using glib dbus in my apps ) service file in /usr/share/dbus-1/services and somehow call it from my application. Also, i don't manage to do this either.

Let's say that my dbus service file from /usr/share/dbus-1/services is com.callThis.service and my main service file from /lib/systemd/system is com.startThis.service

If i run a simple introspect from command line:

/home/root # dbus-send --session --type=method_call --print-reply \
--dest=com.callThis  /com/callThis org.freedesktop.DBus.Introspectable.Introspect

the D-Bus service file will get called and it will start what is in the Exec ( com.starThis ). The problem is that i want to achieve this from C/C++ code using D-Bus glib.

like image 554
Cumatru Avatar asked Dec 12 '12 15:12

Cumatru


People also ask

How do I start systemd service manually?

To start a systemd service, executing instructions in the service's unit file, use the start command. If you are running as a non-root user, you will have to use sudo since this will affect the state of the operating system: sudo systemctl start application . service.

How start systemd service in Linux?

Simply type systemctl and add a space, then tap the Tab key twice. Bash displays all available subcommands.

What is ExecStop systemd?

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.


1 Answers

A combination of g_dbus_connection_send_message with g_dbus_message_new_method_call or g_dbus_message_new_signal should be what you are looking for.

like image 51
drahnr Avatar answered Oct 11 '22 00:10

drahnr