I'm developing/have developed a unit file for 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
Experiencing an issue where calling systemctl radiusd start
does not return an error code, even if /usr/sbin/radiusd -fm
exits with one.
Is there a way to make systemctl act synchronously? i.e. waiting for a set period before returning and indicating the service was successfully/unsuccessfully started.
I'm fine with changing to Type=forking
or any of the other options, like dbus (and writing the code to integrate with dbus) if that means systemctl will exit with an error indicating that the service failed to start.
To pre-empt the obvious question, yes, after start systemd does see the unit as failed.
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)
and yes systemctl status radiusd
does return a non 0 exit code. Just annoying to integrate this with salt stack. Currently, without synchronous start, the bundled saltstack pkg
module reports the service as running, after applying config/code updates that cause service failures.
I think you have already answered your own question.
If you want to fork a daemon as well as want systemctl to return the status code,
Type=forking
is the way to go. There'sType=oneshot
as well. You should use this only when you expect your script/program to exit, as opposed to running as daemon. systemctl actually waits for theExecStart=
program to finish.From my CentOS 7.1 machine:
As you can see the daemon services are using
Type=forking
and one time execution services/scripts are usingType=oneshot