What is the best way to customize LXD snap systemd service configuration

(Fei) #1

Hi, in my setup I have raw file served as storage backend for LXD. The file is located on an NFS mount point. The problem is when NFS mount happens before LXD service starts everything goes well otherwise the system will fail to boot. It seems to me that the order of NFS mount and LXD service is random. I have come up an idea to make sure the NFS mount happens before LXD service.
The idea is that if I mount NFS through systemd instead of fstab, I can write the NFS mount as an required service for LXD service. However, when I open the LXD service configuration file, the first line says ‘Auto-generated, DO NOT EDIT’ . I am wondering if it means that the configuration will be overwritten at some point if the LXD snap get refreshed ? If that is the case, can I avoid it by disabling the snap autorefresh ? Or there is other good way to deal with this ?

Any suggestion would be appreciated !!!

(Stéphane Graber) #2

You may be able to do it the other way around by having either the mount unit for your NFS or a placeholder unit declare Before=snap.lxd.daemon.service so that it starts before LXD does.


the way to go is

sudo systemctl edit snap.lxd.daemon

this creates an override of the service without touching the system generated file.
To control what you have done

sudo systemctl cat snap.lxd.daemon

(Fei) #4

Hi stgraber, I have also tried this approach. The problem is that ubuntu 18.04 relies cloud-init to configure the network, which comes in the very end of the stage. I have set the NFS mount after cloud-init. But the cloud-init does not immediately bring the network up. So the NFS mount service may fail, and restart a couple of seconds later. If the I only set ‘Before=snap.lxd.daemon.service’, the LXD service will start anyway no matter if NFS mount is success or not. So I need strong dependency on NFS mount for LXD service.

(Fei) #5

So I followed gpatel-fr’s suggestion to add override.conf to lxd daemon service. The dependency is correctly set, so that the daemon service will not start before the mount is ready. However there is another issue. When NFS mount failed in the first attempt, the lxd daemon will not start and stayed for inactive. When NFS retries with success, the lxd daemon will not try to start again unless I manually start the lxd daemon. By looking into the lxd daemon configuration file ‘snap.lxd.daemon.service’ I can see the option ‘Restart=’ is set to ‘on-failure’, in which case I expect that the daemon service to restart itself. I am wondering if it is safe to override the value of ‘Restart=’ to ‘always’ ?


While I’m afraid that I’m going to talk entirely out of my personal experience, so YMMV, I’d say that you could search first to make the dependency on the mount, not on the service. From what I understand, it depends on mount being done by a systemd unit file and not a custom hand-made script. If you use a regular big distro, it’s probably being done for you as all big distros support systemd.