如何启用单元模板?

问题描述:

我已经写了我自己的单元模板:如何启用单元模板?

/etc/systemd/user/[email protected] 

这是一群服务我要拿出在启动的基础。我要创建的每个服务作为一个符号链接到模板是这样的:

$ cd /etc/systemd/user 
$ sudo ln -s [email protected] [email protected] 
$ sudo ln -s [email protected] [email protected] 
... 

但如果我现在尝试启用这些服务,我得到:

$ sudo systemctl enable [email protected] 
Failed to execute operation: Too many levels of symbolic links 

为了解决这一点,我复制的文件相反:

$ cd /etc/systemd/user 
$ sudo cp [email protected] [email protected] 
$ sudo cp [email protected] [email protected] 
... 

现在systemctl enable按预期工作。

但:当模板更改时,制作所有这些副本并保持它们的同步是非常尴尬的,并且这种做法有损于我认为的模板系统的目的。

我在这里错过了什么?可以在选手不复制模板被启用?

我使用Ubuntu 16.04和systemd = 229


顺便说一句:如果我启用服务后,用一个符号代替它,它仍然会为一些systemctl命令(daemon-reloadstart工作, stopstatus),而is-enabledenabledisable都将失败,并:

Failed to execute operation: Too many levels of symbolic links 

奇怪我想,我没有试图重新引导系统,看看是否能工程...

你不需要符号链接。只需使用

systemctl start/enable [email protected]。然后,systemd将直接使用您的模板。

有关说明符的更多信息(例如,你可以在里面使用变量模板)

如果您想了解更多,粘贴模板和预期结果见https://www.freedesktop.org/software/systemd/man/systemd.unit.html#Specifiers

+1

模板必须** **不置于'users'。当我将它移动到'/ etc/systemd/system'时,它立即生效! – UlfR