Ubuntu 18.04和systemctl服务消失

我创建并启用了一个服务。
$ sudo systemctl enable /path/to/imaservice.service
Created symlink /etc/systemd/system/multi-user.target.wants/imaservice.service → /path/to/imaservice.service.
Created symlink /etc/systemd/system/imaservice.service → /path/to/imaservice.service.

它存在并持续存在于两者之中:
/etc/systemd/system/imaservice.service
/etc/systemd/system/multi-user.target.wants/imaservice.service

我现在可以愉快地启动/停止/查看它的状态。但是当我重新启动时,无法启动它。我会收到以下信息:
$sudo systemctl is-enabled imaservice
enabled

然而:
$sudo systemctl start imaservice
Failed to start imaservice.service: Unit imaservice.service not found.

每次我重新启动,都需要重新启用:
$sudo systemctl enable imaservice
$sudo systemctl daemon-reload

之后一切就恢复正常了。

我做错了什么?


你为什么将 imaservice.service 放在 /etc/systemd/service 之外? - muru
你可能在考虑另一条路径?/lib/systemd/system - dOA
啊,抱歉,我是指的/etc/systemd/system/lib/systemd/system是用于软件包的。/etc/systemd/system是系统管理员应该保存他们创建的单元的地方。 - muru
我们可以看一下服务吗? - TheWanderer
你没有使用叠加文件系统,对吗? - Ken Sharp
我对覆盖文件系统不太熟悉,所以我猜不是。 - dOA
我今晚可以分享服务本身。一个是用于Jira,一个是用于Confluence,非常基本的启动/停止功能。 - dOA
2个回答

我遇到了一个问题,我可以使用systemctl statussystemctl stop,但无法使用systemctl start来启动一个服务,尽管这个服务在引导过程中确实启动了哈哈。
问题原来是我在一个 .service 文件中打错了一个字母,我写成了After=network-online.service 应该写成After=network-online.target 尽管有这个错误,它仍然能够引导并启动。
然后,它和相关的依赖服务开始像正常的服务一样运行。天哪,我简直不敢相信 systemd 没有将这些拼写错误记录到 journalctl 中...

我遇到了同样的问题。 我找到的唯一解决办法是复制服务而不创建链接。
sudo cp /path/to/imaservice.service /etc/systemd/system/multi-user.target.wants/imaservice.service

这样它就能正常工作了。