In this case, use ExecStartPost and netcat:
ExecStart= ExecStartPost=/bin/sleep 1s ExecStartPost=/usr/bin/nc -z host port
Where host port is the mongodb port and address.
systemd will wait for all commands to execute before running dependent services.
If the start time can "float" will help:
until [[ $(nc -z <host> <port>) -eq 1 ]]; do sleep 1s; done
until will sleep until netcat returns -1.
ExecStartPre and ExecStartPost part of the startup life cycle of unita
ExecStartPre =, ExecStartPost =
Additional commands that are executed before or after the command in ExecStart =, respectively. It is a syntax for serial code.
It is considered that it has failed.
ExecStart = commands are only run after all ExecStartPre = commands that were not prefixed with a "-" exit successfully.
If you haven’t been successful, you’ll be able to get it. = forking, "READY = 1" is sent for Type = notify, or the BusName = has been taken for Type = dbus).
Note: ExecStartPre = may not be used to start long-running processes. All processes forked off by processes invoked via ExecStartPre = will be killed.
ExecStartPre =, ExecStart =, or ExecStartPost = (see above) or ExecStartPrePreader = , the commands in ExecStop = are skipped.
If between units the dependency is Before or After Systemd postpones the start of the dependent service until another starts:
Before =, After =
A space-separated list of unit names. Configures ordering dependencies between units. If you’re not ready, you’ll have started, you’ll have it, It requires that as it is not approved. It is configured with these options. This option may have been created more than once. If you have been configured, you must always be able to. The order of the order is applied. If you are shut down. If there is a need for a unit, it should be noted that it has been ordered before the start-up. It doesn't matter if the ordering dependency is After = or Before =. It also doesn’t matter. The shutdown is ordered before the start-up in all cases. If two units have no ordering dependencies, it takes no ordering.
Type
nothing is said, and ideally, of course, it would be to useType=notify
when the service itself sends a notification that it is ready. But again I did not find confirmation that Mong sends some notifications to systemd. - Vladimir Gamalyan