覆盖 systemd drop-in 中的 ExecStartPre=

roo*_*099 1 debian nginx systemd

我想在 Debian (Buster) 下添加一个 systemd 插件nginx.service。包含的ExecStartPre=指令应在服务器启动之前从模板创建 Nginx 配置文件。

我面临的麻烦是/lib/systemd/system/nginx.service已经包含一个ExecStartPre=,它检查 Nginx 配置文件的有效性。由于它是在ExecStartPre=我的 drop-in 之前执行的,并且 Nginx 配置文件此时尚未完成,因此systemctl start nginx.service失败。

我如何指示 systemd 执行我的ExecStartPre=第一个(或忘记ExecStartPre=from /lib/systemd/system/nginx.service)?

UPDATE ExecCondition=看起来很有希望,但显然在我的 systemd 版本(241)中不可用。

Dan*_*l B 5

根据systemd.service 手册页ExecStart=(相同语法):

如果将此选项指定为空字符串,则要重置的命令列表将被重置,此选项之前的指定将无效。

因此,解决方案是ExecStartPre=在指定 之前添加到您的 drop-in 中ExecStartPre=whatever