如果没有守护进程重新加载,符号链接的 systemd 脚本不会在启动时启动

如果没有守护进程重新加载,符号链接的 systemd 脚本不会在启动时启动

我在 CentOS 7 中有一个自定义 systemd 服务,其启动脚本位于以下版本控制之下/srv/etc/systemd/website.service

[Unit]
Description=website
After=syslog.target network.target

[Service]
Type=forking
User=website
ExecStart=/opt/perl5/perls/perl-5.20.2/bin/hypnotoad /var/www/domains/<domain>/script/site.pl
ExecStop=/opt/perl5/perls/perl-5.20.2/bin/hypnotoad --stop /var/www/domains/<domain>/script/site.pl

[Install]
WantedBy=multi-user.target

如果我运行systemctl enable /srv/etc/systemd/website.service它会很好地创建符号链接,我可以运行systemctl start website并且服务会启动,但它会抱怨缺少 [Install] 部分,这显然是不正确的:

$ sudo systemctl enable /srv/etc/systemd/website.service 
Created symlink from /etc/systemd/system/website.service to /srv/etc/systemd/website.service.
The unit files have no [Install] section. They are not meant to be enabled
using systemctl.
Possible reasons for having this kind of units are:
1) A unit may be statically enabled by being symlinked from another unit's
   .wants/ or .requires/ directory.
2) A unit's purpose may be to act as a helper for some other unit which has
   a requirement dependency on it.
3) A unit may be started when needed via activation (socket, path, timer,
   D-Bus, udev, scripted systemctl call, ...).

重新启动后,该服务未启动,并systemctl start website返回Failed to start website.service: Unit not found。如果我运行systemctl daemon-reload,该start命令将再次起作用。

然而,如果我复制将文件放入 /etc/systemd/system 并运行systemctl enable website,一切按预期工作,并且服务在重新启动后立即启动。

是否真的可以做我想做的事情,或者我只需要记住在进行任何更改时从我的 Git 存储库手动复制 systemd 脚本?

答案1

您应该检查符号链接所引用的驱动器是否在服务启动时已安装。

相关内容