description "LXD - main daemon"
author "Stéphane Graber <stgraber@ubuntu.com>"

start on runlevel [2345]
stop on starting rc RUNLEVEL=[016]
limit nofile 65536 65536
kill timeout 60

respawn

pre-start script
    /usr/lib/x86_64-linux-gnu/lxc/lxc-apparmor-load

    /usr/lib/lxd/lxd-bridge.start
end script

script
    [ -e /etc/environment ] && . /etc/environment
    exec /usr/bin/lxd --group lxd --logfile=/var/log/lxd/lxd.log
end script

post-start script
    # Wait for the unix socket
    for i in $(seq 30); do
        lxc finger --force-local >/dev/null 2>&1 && break
        sleep 1
    done

    /usr/lib/lxd/profile-config
    /usr/bin/lxd waitready
end script

pre-stop script
    [ -n "${UPSTART_STOP_EVENTS:-}" ] && exec /usr/bin/lxd shutdown
end script

post-stop exec /usr/lib/lxd/lxd-bridge stop
