I'm developing/have developed a unit file for systemd

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/

ExecStartPre=/usr/sbin/radiusd $FREERADIUS_OPTIONS -Cxm -lstdout
ExecStart=/usr/sbin/radiusd $FREERADIUS_OPTIONS -fm


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)
  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's Type=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 the ExecStart= program to finish.

From my CentOS 7.1 machine:

[unixguy@infra01 system]$ pwd
[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
[unixguy@infra01 system]$ find ./ -type f | xargs grep 'Type=oneshot' | awk -F: '{print $1}' | head

As you can see the daemon services are using Type=forking and one time execution services/scripts are using Type=oneshot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.