I'm trying to convert a SysV init script to systemd. The SysV configuration is spawning different process in such a way:
su -l $USER_A -c "$CMD_A &" usleep 600000 su -l $USER_B -c "$CMD_B &" usleep 100000 su -l $USER_C -c "$CMD_C &" usleep 300000
Because all spawn processes are using a different user, I've been creating a systemd service unit for each of them. In this service unit, I've specified the dependency (using Requires+After). E.g. of one of those service unit:
[Unit] Description=CMD_B Requires=CMD_A After=CMD_A [Service] User=USER_B Type=simple ExecStart=/FULLPATH/CMD_B [Install] WantedBy=multi-user.target
The problem is that the different processes are communication via POSIX queues and those queues are not instantly created, so they need some period of time between each launch because they are not robust enough to wait for the POSIX queues to be created, they just failed :-(
I can't change those processes so I'm stuck with adding this elapsed time between the launch of each service.
How can I "cleanly" tell systemd that it should consider specific time period between each service activation?
Note: Although systemd respect the "After" dependency, as I think it considers those commands as immediately active, they are spawn almost at the same time (within a few ms). If I try to add an
ExecStartPost=/usr/bin/usleep 600000 it seems that they are also all spawn with in a few ms, because the type of the service is simple, I guess that
ExecStartPost is never triggered. So I have tried
ExecStartPre=/usr/bin/usleep 600000 (for CMD_B, and I changed to 100000 for CMD_C) but it seems that the order is now no longer respected, CMD_A was first started, then CMD_C after 100ms and finally CMD_B after 600ms. So CMD_C failed because it was started before CMD_B. I have now use this
ExecStartPre= trick but I've chosen 600ms for CMD_B, 700ms for CMD_C, etc. It works but I found that terribly awful.