Most of the time, my development virtual machine guest would boot and run perfectly fine. Sometimes, though, the FastCGI service backing one of the websites would not be up and running. It had a ConditionPathExists
, and if the code to run the service wasn’t mounted, it wouldn’t start.
The intention was to allow colleagues to import a copy of this guest, then set up the mount to share the project from the host as they saw fit. On their first boot, with no sharing, ConditionPathExists
would prevent the FastCGI service from attempting to start, and therefore, systemd would not report that the system was degraded. Another point about this system is that the sharing mechanism is unspecified: colleagues are free to use NFS (as I do), Plan9 file sharing, or the hypervisor’s shared-files mechanism. The host paths are also unspecified, so there is no way I can set up the guest to expect specific sharing in advance.
In practice, sometimes NFS wasn’t ready in my guest before systemd was checking conditions for the FastCGI service. The obvious answer was to add After=remote-fs.target
to the FastCGI service. I quickly added a drop-in to add this directive to my own post-configuration scripts.
However, that’s a local solution to a global problem. My colleagues can’t benefit from that, and I should minimize the burden on them periodically setting up new guest images. The fewer things they must remember, the better.
It turns out the answer was even simpler: I could skip the drop-in and add the After=
line to the main service file. I added both remote-fs.target
and the hypervisor’s guest services to the line, which means:
- In production, there are no remote filesystems to mount, nor guest services; there is no latency introduced.
- When using NFS or similar, systemd waits for the remote filesystem before starting the FastCGI service.
- With the hypervisor’s file sharing, the guest services mount the shared files before starting the FastCGI service.
My guest doesn’t actually have the guest services installed, but the FastCGI service starts up as intended. Looking at systemctl list-units --all
output, the guest services are (now) listed as not-found and inactive, which is pretty much what I would expect from a dangling reference. systemd knows about it because I listed it in After, but since it’s not required by anything, the missing definition for it doesn’t cause any problems.