简体   繁体   English

如何使用 XML 文件配置配置 systemd *.service

[英]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.对于 Windows,我有一个 XML 配置文件,其中包含服务名称、负载类型等。在 windows 上,程序在执行期间只需解析此文件并创建服务, 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.另一方面,Linux 有这个 *.service 配置文件,它不允许我使用我的 XML 配置,所以我必须在 *.service 中配置我的守护进程。 So the question is, how to make *.service use my XML config to load preferences for daemon?所以问题是,如何让 *.service 使用我的 XML 配置来加载守护进程的首选项? I know this is possible, but have no idea how to do this.我知道这是可能的,但不知道如何做到这一点。

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.我怀疑您使用众所周知的技术将 Windows 服务可执行文件注册为服务,当您将其作为常规进程运行时。 That is simply a matter of calling the right Service Control Manager API's.这只是调用正确的服务控制管理器 API 的问题。 You know you're not a service if StartServiceCtrlDispatcher fails.如果StartServiceCtrlDispatcher失败,您就知道您不是服务。

The same idea works for Linux.同样的想法适用于 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;这个程序当然不同于Windows; it involves you dynamically writing a *.service file and registering it.它涉及您动态编写*.service文件并注册它。

Not all API's in an OS need to be function calls, an API can also take the shape of a file format.并非操作系统中的所有 API 都需要 function 调用,API 也可以采用文件格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM