LXD Service will not start on boot, but I can start it manually

I have read the earlier discussion of this or a similar issue, but it did not help me.

The LXD service will not start on boot:

$ systemctl status lxd.service
....Dependency failed for LXD - main daemon

$ systemctl status lxd.socket
...lxd.socket: Failed to listen on sockets: No such file or directory

However, after the system starts, I can start the service manually without error:

$ systemctl start lxd.service
$ systemctl status lxd.service
● lxd.service - LXD - main daemon
   Loaded: loaded (/lib/systemd/system/lxd.service; enabled; vendor preset: enabled)...

$ systemctl status lxd.socket
● lxd.socket - LXD - unix socket
   Loaded: loaded (/lib/systemd/system/lxd.socket; enabled; vendor preset: enabled)...

System information
Ubuntu 16.04.3 LTS
LXD 2.21

And what is showing on the logfiles?

On reboot, the log is not written to. When starting manually, the log shows normal startup.

Do you run the stock Linux kernel? What does uname -a show?

Also, can you check whether you run the lxd snap? Should show in snap list lxd.

I believe that this is the main issue.

Definitely stock kernel: Linux narnia 4.4.0-112-generic #135-Ubuntu SMP Fri Jan 19 11:48:36 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

I don’t run any snaps.

I believe the fact that lxd.socket is not loaded on startup is a symptom of the problem. The socket loads fine when I start it manually.

Is there something on your system which would explain /var/lib/lxd not existing early in the boot sequence but then existing later on? Is /var on a different partition for example?

Hi,

/var/lib/lxd is a sim link to another partition.

Therefore, you have to make sure that when the server boots, the partition is already mounted before LXD starts.

systemd has an option RequiresMountsFor, where you list what needs mounted before a service is started.

Note that LXD is known to have issues when /var/lib/lxd is a symlink, this isn’t a supported setup and you really should be switching to a bind-mount which would get you the same behavior but not confused the kernel (especially apparmor) quite as much.

Thanks. I had a bind mount, but eventually had a problem with that when lxd started creating files in the mount point folder before the partition was mounted.

I have solved this now by running sudo systemctl edit lxd.socket and adding:

[Unit]
ConditionPathIsMountPoint=/lxd

With this new condition, It’s probably safe to go back to the bind mount. What really irritates me is systemd starting all kinds of services before fstab is fully processed.

1 Like

Indeed, that’s weird, you’d think all local mounts would be processed before starting anything which depends on local mounts being setup…