为什么在 systemd 覆盖中的另一个 ExecStart=/new/value 之前使用 ExecStart= (没有值)? [英] Why use ExecStart= (with no value) before another ExecStart=/new/value in a systemd override?

查看:19
本文介绍了为什么在 systemd 覆盖中的另一个 ExecStart=/new/value 之前使用 ExecStart= (没有值)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用systemd覆盖的方式让dockerd监听2376端口.所以我按照这个 instruction.

I would like to go the systemd override way to let dockerd to listen to port 2376. So I followed this instruction.

另一方面,我想深入了解 systemd 以了解幕后发生的事情.所以我试图通过这个命令检查 docker 的单元文件:systemctl cat docker.service

On the other hand, I would like to dig into systemd to know what's going on under the hood. So I tried to inspect the unit file of docker by this command: systemctl cat docker.service

根据命令的输出,涉及到两个文件.

According to the output of the command, two files are involved.

  1. /lib/systemd/system/docker.service
  2. /etc/systemd/system/docker.service.d/override.conf

我相信第一个是 docker 的默认单元文件,第二个是我创建的.

I believe the first one is default unit file for docker and the second one is the I created.

我的问题是:两个文件都包含句子 - ExecStart= 和第二个文件中的两次,如:

My problem is: Both files include sentances - ExecStart= and twice in the second file like:

ExecStart=
ExecStart=/usr/bin/dockerd -H fd://

在设置有意义的值ExecStart=/usr/bin/dockerd -H fd://之前是否需要给ExecStart=赋值?

Is it necessary to assign empty to ExecStart= before setting meaningful value ExecStart=/usr/bin/dockerd -H fd:// ?

我将这篇文章分为两个问题,另一个问题这里.

I have spilit this post into two questions and the other one here.

推荐答案

当您将条目添加到覆盖文件时,它们默认附加到任何现有条目.也就是说,如果您的服务 example.service 有:

When you add entries to an override file, they are by default appended to any existing entries. That is, if your service example.service has:

[Service]
EnvironmentFile=/etc/foo.env

然后你创建 /etc/systemd/system/example.service.d/override.conf与:

[Service]
EnvironmentFile=/etc/bar.env

那么有效的配置是:

[Service]
EnvironmentFile=/etc/foo.env
EnvironmentFile=/etc/bar.env

这对很多指令都没有问题,但一个服务只能有一个ExecStart(除非它是一个 Type-oneshot 服务),所以如果你尝试创建一个像这样的覆盖文件:

That's fine for many directives, but a service can have only one ExecStart (unless it's a Type-oneshot service), so if you try to create an override file like this:

[Service]
ExecStart=/new/command/line

这将失败并出现以下错误:

That will fail with an error along the lines of:

systemd: example.service has more than one ExecStart= setting, which is only allowed for Type=oneshot services. Refusing.

通过指定 empty ExecStart,您正在清除"全部以前的条目.所以如果你的 example.service 有:

By specifying an empty ExecStart, you are "clearing out" all previous entries. So if your example.service has:

[Service]
ExecStart=/bin/foo

然后你创建一个像这样的覆盖:

And you create an override like:

[Service]
ExecStart=
ExecStart=/bin/bar

有效配置为:

[Service]
ExecStart=/bin/bar

这篇关于为什么在 systemd 覆盖中的另一个 ExecStart=/new/value 之前使用 ExecStart= (没有值)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆