Run LXD as service (installed from source)

I’m looking for the best practice regarding running LXD as a service after installing from source. I saw in the Arch repo that their packaged version of LXD comes with some systemd files (service and socket). I tried these on my Debian 11 slightly modified, but they didn’t work. Then I tried building my own unit files and had similar problems (service won’t start).

I’m sure there is just an issue with my env vars and I can troubleshoot it until it works, but I’m sure that would be reinventing the wheel at this point. Is there a readymade systemd unit file for Debian/Ubuntu system that install LXD from source? Or is there another alternative for running LXD reliably as a service?

What error do you get?

I was getting an error about the command ‘ip’ not being recognized, so I fixed the env variables and got it working with the below. This was mostly borrowed from the Arch unit file though. What are the best practices or configuration for running it as a service on Debian/Ubuntu systems?

lxd.service

[Unit]
Description=LXD Container Hypervisor
After=network-online.target lxcfs.service

[Service]
EnvironmentFile=/root/.env
ExecStart=/root/go/bin/lxd --group sudo
ExecStop=/root/go/bin/lxd shutdown
Restart=on-failure
LimitNOFILE=1048576
LimitNPROC=infinity
LimitCORE=infinity
TasksMax=infinity
Delegate=yes
KillMode=process

[Install]
WantedBy=multi-user.target

/root/.env

CGO_CFLAGS="-I/root/go/deps/raft/include/ -I/root/go/deps/dqlite/include/"
CGO_LDFLAGS="-L/root/go/deps/raft/.libs -L/root/go/deps/dqlite/.libs/"
LD_LIBRARY_PATH="/root/go/deps/raft/.libs/:/root/go/deps/dqlite/.libs/"
CGO_LDFLAGS_ALLOW="(-Wl,-wrap,pthread_create)|(-Wl,-z,now)"