app-containers/lxd: restore init files from 5763c7144b46

Wit commit 5763c7144b46, some of the older files were dropped that
are still needed. This commit restores them.

Fixes: 5763c7144b46
Signed-off-by: Brahmajit Das <brahmajit.xyz@gmail.com>
Closes: https://github.com/gentoo/gentoo/pull/36943
Signed-off-by: Joonas Niilola <juippis@gentoo.org>
This commit is contained in:
Brahmajit Das 2024-06-01 14:53:55 +05:30 committed by Joonas Niilola
parent 4a5d43a7ec
commit ed22701795
No known key found for this signature in database
GPG Key ID: 7383942B8DC06962
5 changed files with 133 additions and 0 deletions

View File

@ -0,0 +1,23 @@
# Group which owns the shared socket
LXD_OPTIONS+=" --group lxd"
# Enable cpu profiling into the specified file
#LXD_OPTIONS+=" --cpuprofile /tmp/lxc_cpu_profile"
# Enable memory profiling into the specified file
#LXD_OPTIONS+=" --memprofile /tmp/lxc_mem_profile"
# Enable debug mode
#LXD_OPTIONS+=" --debug"
# For debugging, print a complete stack trace every n seconds
#LXD_OPTIONS+=" --print-goroutines-every 5"
# Enable verbose mode
#LXD_OPTIONS+=" -v"
# Logfile to log to
#LXD_OPTIONS+=" --logfile /var/log/lxd/lxd.log"
# Enable syslog logging
#LXD_OPTIONS+=" --syslog"

View File

@ -0,0 +1,12 @@
[Unit]
Description=LXD - unix socket
Documentation=man:lxd(1)
[Socket]
ListenStream=/var/lib/lxd/unix.socket
SocketGroup=lxd
SocketMode=0660
Service=lxd.service
[Install]
WantedBy=sockets.target

View File

@ -0,0 +1,23 @@
[Unit]
Description=LXD - main daemon
After=network-online.target lxcfs.service lxd.socket
Requires=network-online.target lxcfs.service lxd.socket
Documentation=man:lxd(1)
[Service]
EnvironmentFile=-/etc/environment
ExecStart=/usr/sbin/lxd --group lxd --syslog
ExecStartPost=/usr/sbin/lxd waitready --timeout=600
ExecStartPre=/bin/mkdir -p /var/log/lxd
ExecStartPre=/bin/chown -R root:lxd /var/log/lxd
KillMode=process
PermissionsStartOnly=true
TimeoutStartSec=600s
TimeoutStopSec=30s
Restart=on-failure
LimitNOFILE=1048576
LimitNPROC=infinity
TasksMax=infinity
[Install]
Also=lxd-containers.service lxd.socket

View File

@ -0,0 +1,59 @@
#!/sbin/openrc-run
# Copyright 1999-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
DAEMON=/usr/sbin/lxd
PIDFILE=/run/lxd.pid
depend() {
need net
need lxcfs
}
start() {
ebegin "Starting lxd service"
modprobe -f loop > /dev/null 2>&1
# Fix permissions on /var/lib/lxd and make sure it exists.
# Create a log directory for lxd with correct permissions.
install -d /var/lib/lxd --group lxd --owner root --mode 0775
install -d /var/log/lxd --group lxd --owner root
start-stop-daemon --start \
--pidfile ${PIDFILE} \
--exec ${DAEMON} \
--background \
--make-pidfile \
-- \
${LXD_OPTIONS}
eend ${?}
# Create necessary systemd paths in order for systemd containers to work on openrc host.
# /etc/rc.conf should have following values:
# rc_cgroup_mode="hybrid"
if [ -d /sys/fs/cgroup/unified ] &&
[ ! -d /sys/fs/cgroup/systemd ]; then
install -d /sys/fs/cgroup/systemd --group lxd --owner root
mount -t cgroup -o none,name=systemd systemd /sys/fs/cgroup/systemd
fi
}
stop() {
if [ "${RC_CMD}" = restart ]; then
ebegin "Stopping lxd service (but not containers)"
# start-stop-daemon sends SIGTERM with a timeout of 5s by default.
# SIGTERM indicates to LXD that it will be stopped temporarily.
# Instances will keep running.
start-stop-daemon --stop --quiet -p "${PIDFILE}"
eend ${?}
else
ebegin "Stopping lxd service and containers, waiting 40s"
# SIGPWR indicates to LXD that the host is going down.
# LXD will do a clean shutdown of all instances.
# After 30s all remaining instances will be killed.
# We wait up to 40s for LXD.
start-stop-daemon --stop --quiet -R SIGPWR/40 -p "${PIDFILE}"
eend ${?}
fi
}

View File

@ -0,0 +1,16 @@
[Unit]
Description=LXD - container startup/shutdown
Documentation=man:lxd(1)
After=lxd.socket lxd.service
Requires=lxd.socket
[Service]
Type=oneshot
ExecStart=/usr/sbin/lxd activateifneeded
ExecStop=/usr/sbin/lxd shutdown
TimeoutStartSec=600s
TimeoutStopSec=600s
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target