@chronicom (Fei) posted a new topic, subject "What is the best way to customize LXD snap systemd service configuration". It read:

   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 !!!

Then @stgraber (Stéphane Graber) said

    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.

Then @gpatel-fr said

    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

To which @chronicom (Fei) replied

    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.

So @chronicom (Fei) replied

    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' ?

So @gpatel-fr replied

    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.


{'source': 'discourse', 'url': 'https://discuss.linuxcontainers.org/t/what-is-the-best-way-to-customize-lxd-snap-systemd-service-configuration/4699', 'title': 'What is the best way to customize LXD snap systemd service configuration', 'views': 1402, 'has_accepted_answer': False, 'word_count': 549, 'like_count': 0, 'reply_count': 2, 'participant_count': 3, 'posts': 6, 'tags': '', 'author': '@chronicom (Fei)', 'participants': '@chronicom (Fei), @stgraber (Stéphane Graber), @gpatel-fr', 'image_url': [None], 'created_at': '2019-05-02T23:54:23.634Z', 'last_posted_at': '2019-05-05T09:15:28.204Z'}