oneshot systemd 单元已启用并被“wantedby”,但尚未启动

oneshot systemd 单元已启用并被“wantedby”,但尚未启动

我编写了以下 systemd 单元,如下所示/etc/systemd/system/regen-ssh-keys.service

[Unit]
Description=OpenSSH Server Key Generation

# Do not run if keys already exist
ConditionPathExistsGlob=!/etc/ssh/ssh_host_*_key

# This service requires rng-tools to feed the random number generator,
# otherwise we may generate predictable keys without noticing it.
Requires=rng-tools.service
After=rng-tools.service

# sshd needs this service to be run and finished before starting
PartOf=sshd.service sshd.socket
Before=sshd.service sshd.socket

[Install]
# sshd needs this service to be run and finished before starting
WantedBy=sshd.service sshd.socket

[Service]
EnvironmentFile=-/etc/sysconfig/sshd
ExecStart=/usr/bin/ssh-keygen -A
Type=oneshot
RemainAfterExit=yes

并且我用 启用了它systemctl enable regen-ssh-keys

它不会在启动时或 ssh 启动时启动,尽管service regen-ssh-keys status它显示已加载并启用,但处于“非活动状态(已死)”。此外,它也没有被列出systemctl -a

但是,当我用 手动启动它时service regen-ssh-keys start,它会按预期启动。

我在编写单元时是否做错了什么?

答案1

这个错误只是我没有使用正确的 SSH 服务名称。用 替换 即可sshd.service sshd.socket解决ssh.service ssh.socket问题。

相关内容