在执行 rpm 安装并启动服务“homemade-auth-svc”之后,它似乎启动得很顺利,但随后失败并不断重启。
journalctl -ex u homemade-auth-svc.service:
Jan 14 21:01:51 UI systemd[1]: Starting A service for homemade authentication....
-- Subject: Unit homemade-auth-svc.service has begun with start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit homemade-auth-svc.service has begun starting up.
Jan 14 21:01:51 UI homemade-auth-svc[1709]: homemade-auth: starting...
Jan 14 21:01:51 UI systemd[1]: Started A service for homemade authentication..
-- Subject: Unit homemade-auth-svc.service has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit homemade-auth-svc.service has finished starting up.
--
-- The start-up result is done.
Jan 14 21:01:51 UI systemd[1]: homemade-auth-svc.service holdoff time over, scheduling restart.
Jan 14 21:01:51 UI systemd[1]: Stopping A service for homemade authentication....
-- Subject: Unit homemade-auth-svc.service has begun shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit homemade-auth-svc.service has begun shutting down.
Jan 14 21:01:51 UI systemd[1]: Starting A service for homemade authentication....
-- Subject: Unit homemade-auth-svc.service has begun with start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
....
systemctl status homemade-auth-svc:
homemade-auth-svc.service - A service for homemade authentication.
Loaded: loaded (/usr/lib/systemd/system/homemade-auth-svc.service; enabled)
Active: failed (Result: start-limit) since Thu 2016-01-14 21:01:52 PST; 20min ago
Process: 1725 ExecStart=/usr/bin/HomemadeAuthSvc (code=exited, status=0/SUCCESS)
Main PID: 1725 (code=exited, status=0/SUCCESS)
CGroup: /system.slice/homemade-auth-svc.service
Jan 14 21:01:52 UI systemd[1]: homemade-auth-svc.service holdoff time over, scheduling restart.
Jan 14 21:01:52 UI systemd[1]: Stopping A service for homemade authentication....
Jan 14 21:01:52 UI systemd[1]: Starting A service for homemade authentication....
Jan 14 21:01:52 UI systemd[1]: homemade-auth-svc.service start request repeated too quickly, refusing to start.
Jan 14 21:01:52 UI systemd[1]: Failed to start A service for homemade authentication..
Jan 14 21:01:52 UI systemd[1]: Unit homemade-auth-svc.service entered failed state.
自制-auth-svc.服务:
[Unit]
Description=A service for homemade authentication.
After=network.target
[Service]
Type=notify
NotifyAccess=all
ExecStart=/usr/bin/HomemadeAuthSvc
StandardOutput=null
Restart=always
[Install]
WantedBy=multi-user.target
Alias=homemade-auth-svc.service
我们在子守护进程中调用 sd_notify(0, "READY=1");,但是,如果我们在等待 10 秒后成功退出,然后在父进程中执行此操作,这似乎无关紧要。然后 systemd 会等待这么长时间,然后给出相同的结果。就好像它等待 sd_notify(),声明成功,然后立即重新启动服务。现在,rpm 修改 lightdm.service(登录服务)以依赖于我们(安装一个文件,内容如下:
[Unit]
Wants=homemade-auth-svc.service
进入: /etc/systemd/system/lightdm.service.d/ )
但由于 lightdm 已经在运行,所以我认为这不应该是个问题。
Systemd 是运行在 Fedora 20 上的 208 版本。
答案1
根据 Michael Hampton 和对 systemd-devel 邮件列表的一些半确认性浏览,似乎您无法将 sd_notify (& Type=notify) 与传统的 fork() 守护进程一起使用。因此,我让服务成为老式的 Type=forking,并让子服务通过共享管道通知父服务何时准备就绪,然后父服务退出,这反过来又让 systemd 知道服务已准备就绪。
值得一提的是,我们尝试暂停依赖服务(登录管理器)几秒钟,但失败了,systemd 等待的时间不到 1 秒就启动了它。