| 1 | #!/sbin/openrc-run |
| 2 | |
| 3 | command="/usr/sbin/incusd" |
| 4 | command_args="${INCUSD_OPTIONS}" |
| 5 | command_background="true" |
| 6 | pidfile="/run/incus/${RC_SVCNAME}.pid" |
| 7 | retry="${INCUSD_STOP_TIMEOUT:-60}" |
| 8 | extra_started_commands="quit" |
| 9 | description_quit="Daemon quits and leaves the instances running" |
| 10 | |
| 11 | : ${INCUSD_FORCE_STOP:="no"} |
| 12 | |
| 13 | depend() { |
| 14 | need net cgroups dbus |
| 15 | use lxcfs |
| 16 | after firewall |
| 17 | } |
| 18 | |
| 19 | start_pre() { |
| 20 | checkpath --directory "${pidfile%/*}" --mode 0750 |
| 21 | # Required for running systemd containers |
| 22 | if [ -d /sys/fs/cgroup/unified ] && ! [ -d /sys/fs/cgroup/systemd ]; then |
| 23 | checkpath --directory --owner root:incus /sys/fs/cgroup/systemd |
| 24 | mount -t cgroup \ |
| 25 | -o rw,nosuid,nodev,noexec,relatime,none,name=systemd \ |
| 26 | cgroup /sys/fs/cgroup/systemd |
| 27 | fi |
| 28 | } |
| 29 | |
| 30 | stop() { |
| 31 | ebegin "Stopping ${RC_SVCNAME}" |
| 32 | if [ "$INCUSD_FORCE_STOP" = "no" ]; then |
| 33 | $command shutdown --timeout ${INCUSD_STOP_TIMEOUT:-60} |
| 34 | elif [ "$INCUSD_FORCE_STOP" = "yes" ]; then |
| 35 | $command shutdown --force |
| 36 | fi |
| 37 | } |
| 38 | |
| 39 | quit() { |
| 40 | ebegin "Quitting ${RC_SVCNAME}" |
| 41 | start-stop-daemon --signal SIGQUIT --pidfile $pidfile --quiet |
| 42 | rm /run/openrc/started/incusd |
| 43 | } |