Running commands (that depend on a process being started) in after.local

First off, have a look at this article by James on how to get after.local in systemd: systemd and using the after.local script in openSUSE 12.1 - Blogs - openSUSE Forums

While it works for some commands, other commands which rely on a daemon that hasn’t been started at this point will fail. The reason is that this after.local is in reality a “during local”, which gets executed simultaneously with other services in the multi-user.target. IMO the mutli-user.target is not the right place for an after-local servive. I tried other target - including, in my case, having to deal with the portmapper, the rpcbind.target and the remote-fs.target - but none of those worked. Adding a LSB header with the required facility (i.e $rpcbind or $portmap) in after.local didn’t help either.

  • see man systemd.special for a description of special targets.

Adding a delay of 4 seconds in after.local would solve the issue with rpcbind. A more elegant approach - although contrary to the sytemd philosophy - is provided by the following function, which waits for the required process to be started before running the command. I called it runafter.


function runafter {
proc=$1
shift
 -x $proc ] || return 1
while ( ! /sbin/checkproc $proc ) ; do
        sleep 1
done
$* >/dev/null
}

Usage:

runafter daemon command

Example:

runafter  /sbin/rpcbind "some command needing rpcbind"

I’m aware that it’s a hack (again) and that a separate after-local target would be a better solution… but I couldn’t find one and don’t know how to create a target in systemd (can we?). Anyway it’s working and allows me to finally boot in systemd.

Oh, I forgot to say that this function is to be written in your /etc/init.d/after.local … in case it wasn’t obvious.

On 2011-12-16 03:56, please try again wrote:
> I’m aware that it’s a hack (again) and that a separate after-local
> target would be a better solution… but I couldn’t find one and don’t
> know how to create a target in systemd (can we?). Anyway it’s working
> and allows me to finally boot in systemd.

Either a bugzilla class enhancement or a fate, requesting a new after.local
file for systemd that works. Something that runs when the runlevel is reached.

And then vote for it massively.


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)