有没有办法使systemctl开始同步

我正在开发/开发FreeRADIUS项目的单元文件,以便与systemd集成。

[Unit] Description=FreeRADIUS multi-protocol policy server After=syslog.target network.target Documentation=man:radiusd(8) man:radiusd.conf(5) http://wiki.freeradius.org/ http://networkradius.com/doc/ [Service] EnvironmentFile=-/etc/sysconfig/radiusd ExecStartPre=/usr/sbin/radiusd $FREERADIUS_OPTIONS -Cxm -lstdout ExecStart=/usr/sbin/radiusd $FREERADIUS_OPTIONS -fm Restart=on-abnormal [Install] WantedBy=multi-user.target 

遇到一个问题,即调用systemctl radiusd start不会返回错误代码,即使/usr/sbin/radiusd -fm退出。

有没有办法使systemctl同步行事? 即在返回之前等待一段时间,并指示服务已成功/未成功启动。

我没有改变Type=forking或任何其他选项,如dbus(并编写代码与dbus集成),如果这意味着systemctl将退出一个错误,指示服务无法启动。

为了避免显而易见的问题,是的,在开始systemd之后,确实看到了单元失败。

 bash-4.2# systemctl status radiusd radiusd.service - FreeRADIUS multi-protocol policy server Loaded: loaded (/usr/lib/systemd/system/radiusd.service; enabled) Active: failed (Result: start-limit) since Wed 2015-08-12 12:26:18 EDT; 19s ago Docs: man:radiusd(8) man:radiusd.conf(5) http://wiki.freeradius.org/ http://networkradius.com/doc/ Process: 10610 ExecStart=/usr/sbin/radiusd $FREERADIUS_OPTIONS -fm (code=exited, status=1/FAILURE) Main PID: 10610 (code=exited, status=1/FAILURE) 

是的systemctl status radiusd确实返回一个非0退出代码。 只是恼人的将这与盐堆整合。 目前,在没有同步启动的情况下,绑定的saltstack pkg模块会在应用导致服务失败的configuration/代码更新后报告服务正在运行。

我想你已经回答了你自己的问题。

如果你想fork一个守护进程并且希望systemctl返回状态码, Type=forking就是要走的路。 还有Type=oneshot 。 只有当您期望您的脚本/程序退出时,才应该使用它,而不是作为后台进程运行。 systemctl实际上等待ExecStart=程序完成。

从我的CentOS 7.1机器:

 [unixguy@infra01 system]$ pwd /usr/lib/systemd/system [unixguy@infra01 system]$ find ./ -type f | xargs grep 'Type=' | awk -F: '{print $2}' | sort | uniq -c | sort -nr | head -5 64 Type=oneshot 37 Type=forking 11 Type=notify 6 Type=idle 6 Type=dbus [unixguy@infra01 system]$ find ./ -type f | xargs grep 'Type=forking' | awk -F: '{print $1}' | head ./rc-local.service ./rdisc.service ./tcsd.service ./plymouth-kexec.service ./plymouth-halt.service ./plymouth-poweroff.service ./plymouth-reboot.service ./plymouth-start.service ./rpc-statd.service ./systemd-cfengine-bootstrap.service [unixguy@infra01 system]$ find ./ -type f | xargs grep 'Type=oneshot' | awk -F: '{print $1}' | head ./systemd-kexec.service ./quotaon.service ./halt-local.service ./initrd-cleanup.service ./initrd-parse-etc.service ./initrd-switch-root.service ./initrd-udevadm-cleanup-db.service ./kmod-static-nodes.service ./systemd-binfmt.service ./[email protected] 

正如你所看到的守护进程服务正在使用Type=forking和一次执行服务/脚本正在使用Type=oneshot