From c02c01e0accf61fe8ef30ac8cbe7c085472c00fd Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Mon, 23 Oct 2017 10:38:39 +0200 Subject: [PATCH] saving uncommitted changes in /etc prior to emerge run --- conf.d/localmount | 2 +- init.d/sysfs | 109 ++++++++++++++++++++++++++++++++++++++-------- rc.conf | 74 ++++++++++++++++++++++++++----- 3 files changed, 157 insertions(+), 28 deletions(-) diff --git a/conf.d/localmount b/conf.d/localmount index e727719..25ca3cd 100644 --- a/conf.d/localmount +++ b/conf.d/localmount @@ -3,7 +3,7 @@ #no_umounts="/dir1:/var/dir2" # # Mark certain mount points as critical. -# This contains aspace separated list of mount points which should be +# This contains a space separated list of mount points which should be # considered critical. If one of these mount points cannot be mounted, # localmount will fail. # By default, this is empty. diff --git a/init.d/sysfs b/init.d/sysfs index 55e1258..d257543 100755 --- a/init.d/sysfs +++ b/init.d/sysfs @@ -107,20 +107,16 @@ mount_misc() fi } -mount_cgroups() +cgroup1_base() { - # set up kernel support for cgroups - if [ -d /sys/fs/cgroup ] && ! mountinfo -q /sys/fs/cgroup; then - if grep -qs cgroup /proc/filesystems; then - ebegin "Mounting cgroup filesystem" - local opts="${sysfs_opts},mode=755,size=${rc_cgroupsize:-10m}" - mount -n -t tmpfs -o ${opts} cgroup_root /sys/fs/cgroup - eend $? - fi + grep -qw cgroup /proc/filesystems || return 0 + if ! mountinfo -q /sys/fs/cgroup; then + ebegin "Mounting cgroup filesystem" + local opts="${sysfs_opts},mode=755,size=${rc_cgroupsize:-10m}" + mount -n -t tmpfs -o "${opts}" cgroup_root /sys/fs/cgroup + eend $? fi - mountinfo -q /sys/fs/cgroup || return 0 - if ! mountinfo -q /sys/fs/cgroup/openrc; then local agent="/lib64/rc/sh/cgroup-release-agent.sh" mkdir /sys/fs/cgroup/openrc @@ -129,17 +125,96 @@ mount_cgroups() openrc /sys/fs/cgroup/openrc printf 1 > /sys/fs/cgroup/openrc/notify_on_release fi + return 0 +} - yesno ${rc_controller_cgroups:-YES} && [ -e /proc/cgroups ] || return 0 - while read name hier groups enabled rest; do +cgroup1_controllers() +{ + yesno "${rc_controller_cgroups:-YES}" && [ -e /proc/cgroups ] || return 0 + while read -r name _ _ enabled rest; do case "${enabled}" in - 1) mountinfo -q /sys/fs/cgroup/${name} && continue - mkdir /sys/fs/cgroup/${name} - mount -n -t cgroup -o ${sysfs_opts},${name} \ - ${name} /sys/fs/cgroup/${name} + 1) mountinfo -q "/sys/fs/cgroup/${name}" && continue + local x + for x in $rc_cgroup_controllers; do + [ "${name}" = "blkio" ] && [ "${x}" = "io" ] && + continue 2 + [ "${name}" = "${x}" ] && + continue 2 + done + mkdir "/sys/fs/cgroup/${name}" + mount -n -t cgroup -o "${sysfs_opts},${name}" \ + "${name}" "/sys/fs/cgroup/${name}" ;; esac done < /proc/cgroups + return 0 +} + +cgroup2_base() +{ + local base + base="$(cgroup2_find_path)" + mkdir -p "${base}" + mount -t cgroup2 none -o "${sysfs_opts},nsdelegate" "${base}" 2> /dev/null || + mount -t cgroup2 none -o "${sysfs_opts}" "${base}" + return 0 +} + +cgroup2_controllers() +{ + local active cgroup_path x y + cgroup_path="$(cgroup2_find_path)" + [ -z "${cgroup_path}" ] && return 0 + [ -e "${cgroup_path}/cgroup.controllers" ] && + read -r active < "${cgroup_path}/cgroup.controllers" + for x in ${rc_cgroup_controllers}; do + for y in ${active}; do + [ "$x" = "$y" ] && + [ -e "${cgroup_path}/cgroup.subtree_control" ]&& + echo "+${x}" > "${cgroup_path}/cgroup.subtree_control" + done + done + return 0 +} + +cgroups_hybrid() +{ + grep -qw cgroup /proc/filesystems || return 0 + cgroup1_base + if grep -qw cgroup2 /proc/filesystems; then + cgroup2_base + cgroup2_controllers + fi + cgroup1_controllers + return 0 +} + +cgroups_legacy() +{ + grep -qw cgroup /proc/filesystems || return 0 + cgroup1_base + cgroup1_controllers + return 0 +} + +cgroups_unified() +{ + cgroup2_base + cgroup2_controllers + return 0 +} + +mount_cgroups() +{ + # set up kernel support for cgroups + if [ -d /sys/fs/cgroup ]; then + case "${rc_cgroup_mode:-hybrid}" in + hybrid) cgroups_hybrid ;; + legacy) cgroups_legacy ;; + unified) cgroups_unified ;; + esac + fi + return 0 } restorecon_sys() diff --git a/rc.conf b/rc.conf index beafd91..d066c8a 100644 --- a/rc.conf +++ b/rc.conf @@ -191,13 +191,43 @@ rc_tty_number=12 ############################################################################## # LINUX CGROUPS RESOURCE MANAGEMENT -# If you have cgroups turned on in your kernel, this switch controls -# whether or not a group for each controller is mounted under -# /sys/fs/cgroup. -# None of the other options in this section work if this is set to "NO". +# This sets the mode used to mount cgroups. +# "hybrid" mounts cgroups version 2 on /sys/fs/cgroup/unified and +# cgroups version 1 on /sys/fs/cgroup. +# "legacy" mounts cgroups version 1 on /sys/fs/cgroup +# "unified" mounts cgroups version 2 on /sys/fs/cgroup +#rc_cgroup_mode="hybrid" + +# This is a list of controllers which should be enabled for cgroups version 2. +# If hybrid mode is being used, controllers listed here will not be +# available for cgroups version 1. +# This is a global setting. +#rc_cgroup_controllers="" + +# This variable contains the cgroups version 2 settings for your services. +# If this is set in this file, the settings will apply to all services. +# If you want different settings for each service, place the settings in +# /etc/conf.d/foo for service foo. +# The format is to specify the setting and value followed by a newline. +# Multiple settings and values can be specified. +# For example, you would use this to set the maximum memory and maximum +# number of pids for a service. +#rc_cgroup_settings=" +#memory.max 10485760 +#pids.max max +#" +# +# For more information about the adjustments that can be made with +# cgroups version 2, see Documentation/cgroups-v2.txt in the linux kernel +# source tree. +#rc_cgroup_settings="" + +# This switch controls whether or not cgroups version 1 controllers are +# individually mounted under +# /sys/fs/cgroup in hybrid or legacy mode. #rc_controller_cgroups="YES" -# The following settings allow you to set up values for the cgroup +# The following settings allow you to set up values for the cgroups version 1 # controllers for your services. # They can be set in this file;, however, if you do this, the settings # will apply to all of your services. @@ -211,8 +241,9 @@ rc_tty_number=12 # cpu.shares 512 # " # -#For more information about the adjustments that can be made with -#cgroups, see Documentation/cgroups/* in the linux kernel source tree. +# For more information about the adjustments that can be made with +# cgroups version 1, see Documentation/cgroups-v1/* in the linux kernel +# source tree. # Set the blkio controller settings for this service. #rc_cgroup_blkio="" @@ -246,10 +277,33 @@ rc_tty_number=12 # Set this to YES if you want all of the processes in a service's cgroup # killed when the service is stopped or restarted. -# This should not be set globally because it kills all of the service's -# child processes, and most of the time this is undesirable. Please set -# it in /etc/conf.d/. +# Be aware that setting this to yes means all of a service's +# child processes will be killed. Keep this in mind if you set this to +# yes here instead of for the individual services in +# /etc/conf.d/. # To perform this cleanup manually for a stopped service, you can # execute cgroup_cleanup with /etc/init.d/ cgroup_cleanup or # rc-service cgroup_cleanup. +# The process followed in this cleanup is the following: +# 1. send stopsig (sigterm if it isn't set) to all processes left in the +# cgroup immediately followed by sigcont. +# 2. Send sighup to all processes in the cgroup if rc_send_sighup is +# yes. +# 3. delay for rc_timeout_stopsec seconds. +# 4. send sigkill to all processes in the cgroup unless disabled by +# setting rc_send_sigkill to no. # rc_cgroup_cleanup="NO" + +# If this is yes, we will send sighup to the processes in the cgroup +# immediately after stopsig and sigcont. +#rc_send_sighup="NO" + +# This is the amount of time in seconds that we delay after sending sigcont +# and optionally sighup, before we optionally send sigkill to all +# processes in the # cgroup. +# The default is 90 seconds. +#rc_timeout_stopsec="90" + +# If this is set to no, we do not send sigkill to all processes in the +# cgroup. +#rc_send_sigkill="YES" -- 2.39.5