File: incus-base.incus.init

package info (click to toggle)
incus 6.0.4-2%2Bdeb13u1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 24,292 kB
  • sloc: sh: 16,018; ansic: 3,121; python: 456; makefile: 321; ruby: 51; sql: 50; lisp: 6
file content (105 lines) | stat: -rwxr-xr-x 3,279 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/dash -ue

### BEGIN INIT INFO
# Short-Description:    System container and VM manager
# Description:          System container and VM manager
# Provides:             incus
# Required-Start:       $remote_fs $network lxcfs
# Required-Stop:        $remote_fs $network lxcfs
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
### END INIT INFO

# WARNING:
# This script has not been tested on hosts with cgroup v1.
# The host system must have a cgroup v2 hierarchy mounted.

DAEMON=/usr/libexec/incus/incusd
NAME=incus
DESC="System container and VM manager"
PIDFILE=/run/incus.pid

# Import log_* functions.
. /lib/lsb/init-functions

# Load environment vars.
[ -e /etc/environment ] && . /etc/environment

# Load default config.
[ -e /etc/default/incus ] && . /etc/default/incus

# Just exit if incusd does not exist or is not excutable.
[ -x "${DAEMON}" ] || exit 0

do_start() {
    /usr/libexec/incus/incus-apparmor-load

    # shellcheck disable=SC3045
    # LimitNOFILE=1048576
    ulimit -n 1048576
    # ulimit of dash does not support -u,
    # so try to use prlimit provided by util-linux.
    # LimitNPROC=infinity
    ulimit -u unlimited > /dev/null 2>&1 || [ -x /usr/bin/prlimit ] && /usr/bin/prlimit --nproc=unlimited --pid="$$"

    if [ "${USE_SYSLOG:-no}" = 'no' ]; then
        [ -d /var/log/incus ] || mkdir -p /var/log/incus && chown -R root:incus-admin /var/log/incus
        start-stop-daemon -m --start --quiet --pidfile "${PIDFILE}" \
        --exec "${DAEMON}" --background -- --group=incus-admin --logfile=/var/log/incus/incus.log > /dev/null 2>&1
    else
        start-stop-daemon -m --start --quiet --pidfile "${PIDFILE}" \
        --exec "${DAEMON}" --background -- --group=incus-admin --syslog > /dev/null 2>&1
    fi
}

case "${1:-}" in
    start)
        printf '%s' "Starting ${DESC}: ${NAME}"

        if do_start; then
            log_success_msg
            # Wait for the daemon to get ready.
            [ -x /usr/libexec/incus/incusd ] && /usr/libexec/incus/incusd waitready --timeout=600
        else
            if start-stop-daemon --test -m --start --quiet --pidfile "${PIDFILE}" \
                --exec "${DAEMON}" --background > /dev/null 2>&1; then
                log_failure_msg
                exit 1
            else
                log_failure_msg " already running"
                exit 0
            fi
        fi

        exit 0
        ;;
    stop)
        log_daemon_msg "Stopping ${DESC}" "${NAME}"
        if start-stop-daemon --stop --quiet --pidfile "${PIDFILE}" \
            --exec "${DAEMON}" --retry 10 > /dev/null 2>&1; then
                log_success_msg
        else
            if start-stop-daemon --test -m --start --quiet --pidfile "${PIDFILE}" \
                --exec "${DAEMON}" --background > /dev/null 2>&1; then
                log_failure_msg " not running"
                exit 0
            else
                log_failure_msg
                exit 1
            fi
        fi

        exit 0
        ;;
    status)
        status_of_proc -p "${PIDFILE}" "${DAEMON}" incus
        ;;
    restart|force-reload)
        "$0" stop
        exec "$0" start
        ;;
    *)
        printf '%s\n' "Usage: $0 {start|stop|status|restart|force-reload}" 1>&2
        exit 1
        ;;
esac