Skip to content
Advertisement

How to configure systemd *.service using XML file configuration

I’m making a cross-platform background process. For Windows, I have a XML configuration file, which has a service name, load type etc. On windows, program during execution just parses this file and creates the service, easy. Linux, on other hand, has this *.service config file, which doesn’t allow me to use my XML config, so I have to configure my daemon inside *.service. So the question is, how to make *.service use my XML config to load preferences for daemon? I know this is possible, but have no idea how to do this.

Advertisement

Answer

I suspect you use the well-known technique of registering your Windows Service executable as a service, when you run it as a regular process. That is simply a matter of calling the right Service Control Manager API’s. You know you’re not a service if StartServiceCtrlDispatcher fails.

The same idea works for Linux. If you start your program normally, you register yourself as a service following the documented procedure. This procedure is of course different from Windows; it involves you dynamically writing a *.service file and registering it.

Not all API’s in an OS need to be function calls, an API can also take the shape of a file format.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement