#!/bin/sh /etc/rc.common
START=1
start() {
# Procd mounts non-hierarchical cgroupfs so unmount first before cgroupfs-mount
echo "Mounting cgroupfs hierarchy"
if mountpoint -q /sys/fs/cgroup; then
umount /sys/fs/cgroup/
fi
/usr/sbin/cgroupfs-mount
}
stop() {
echo "Unmounting cgroupfs hierarchy"
/usr/sbin/cgroupfs-umount
}
boot () {
start
}
root@NAS:~#
---8<---
→ /usr/sbin/cgroupfs-mount
root@NAS:~# cat cgroupfs-mount
#!/bin/sh
# Copyright 2011 Canonical, Inc
# 2014 Tianon Gravi
# Author: Serge Hallyn <serge.hallyn@canonical.com>
# Tianon Gravi <admwiggin@gmail.com>
set -e
# for simplicity this script provides no flexibility
# if cgroup is mounted by fstab, don't run
# don't get too smart - bail on any uncommented entry with 'cgroup' in it
if grep -v '^#' /etc/fstab | grep -q cgroup; then
echo 'cgroups mounted from fstab, not mounting /sys/fs/cgroup'
exit 0
fi
# kernel provides cgroups?
if [ ! -e /proc/cgroups ]; then
exit 0
fi
# if we don't even have the directory we need, something else must be wrong
if [ ! -d /sys/fs/cgroup ]; then
exit 0
fi
# mount /sys/fs/cgroup if not already done
if ! mountpoint -q /sys/fs/cgroup; then
mount -t tmpfs -o uid=0,gid=0,mode=0755 cgroup /sys/fs/cgroup
fi
cd /sys/fs/cgroup
# get/mount list of enabled cgroup controllers
for sys in $(awk '!/^#/ { if ($4 == 1) print $1 }' /proc/cgroups); do
mkdir -p $sys
if ! mountpoint -q $sys; then
if ! mount -n -t cgroup -o $sys cgroup $sys; then
rmdir $sys || true
fi
fi
done
# example /proc/cgroups:
# #subsys_name hierarchy num_cgroups enabled
# cpuset 2 3 1
# cpu 3 3 1
# cpuacct 4 3 1
# memory 5 3 0
# devices 6 3 1
# freezer 7 3 1
# blkio 8 3 1
# enable cgroups memory hierarchy, like systemd does (and lxc/docker desires)
# https://github.com/systemd/systemd/blob/v245/src/core/cgroup.c#L2983
# https://bugs.debian.org/940713
if [ -e /sys/fs/cgroup/memory/memory.use_hierarchy ]; then
echo 1 > /sys/fs/cgroup/memory/memory.use_hierarchy
fi
exit 0
#!/bin/sh
# Copyright 2011 Canonical, Inc
# 2014 Tianon Gravi
# Author: Serge Hallyn <serge.hallyn@canonical.com>
# Tianon Gravi <tianon@debian.org>
set -e
# we don't care to move tasks around gratuitously - just umount the cgroups
# if we don't even have the directory we need, something else must be wrong
if [ ! -d /sys/fs/cgroup ]; then
exit 0
fi
# if /sys/fs/cgroup is not mounted, we don't bother
if ! mountpoint -q /sys/fs/cgroup; then
exit 0
fi
cd /sys/fs/cgroup
for sys in *; do
if mountpoint -q $sys; then
umount $sys
fi
if [ -d $sys ]; then
rmdir $sys || true
fi
done
exit 0
#!/bin/sh /etc/rc.common
. /lib/functions.sh
START=99
STOP=00
run_command() {
local command="$1"
$command
}
start_container() {
local cfg="$1"
local name
config_get name "$cfg" name
config_list_foreach "$cfg" command run_command
if [ -n "$name" ]; then
/usr/bin/lxc-start -n "$name"
fi
}
max_timeout=0
stop_container() {
local cfg="$1"
local name timeout
config_get name "$cfg" name
config_get timeout "$cfg" timeout 300
if [ "$max_timeout" -lt "$timeout" ]; then
max_timeout=$timeout
fi
if [ -n "$name" ]; then
if [ "$timeout" = "0" ]; then
/usr/bin/lxc-stop -n "$name" &
else
/usr/bin/lxc-stop -n "$name" -t $timeout &
fi
fi
}
start() {
config_load lxc-auto
config_foreach start_container container
}
stop() {
config_load lxc-auto
config_foreach stop_container container
# ensure e.g. shutdown doesn't occur before maximum timeout on
# containers that are shutting down
if [ $max_timeout -gt 0 ]; then
sleep $max_timeout
fi
}
### ZX: Create missing LXC resources (cgroup mount points)
boot() {
if [ ! -d /sys/fs/cgroup/systemd ]; then
echo "Creating systemd cgroup..."
mkdir -p /sys/fs/cgroup/systemd
mount -t cgroup -o rw,nosuid,nodev,noexec,relatime,none,name=systemd cgroup /sys/fs/cgroup/systemd
fi
start
}