Browse Source

simplify the shell scripts and make them easier to maintain going forward

tags/1.0
Tianon Gravi 7 years ago
parent
commit
9e474d190c
2 changed files with 42 additions and 18 deletions
  1. +30
    -11
      cgroupfs-mount
  2. +12
    -7
      cgroupfs-umount

+ 30
- 11
cgroupfs-mount View File

@@ -1,15 +1,16 @@
#!/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
# 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 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"
echo 'cgroups mounted from fstab, not mounting /sys/fs/cgroup'
exit 0
fi

@@ -18,13 +19,31 @@ if [ ! -e /proc/cgroups ]; then
exit 0
fi

# Mount /sys/fs/cgroup if not already done
mountpoint -q /sys/fs/cgroup || mount -t tmpfs -o uid=0,gid=0,mode=0755 cgroup /sys/fs/cgroup
# 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 list of cgroup controllers
for d in `sed -e '1d;s/\([^\t]\)\t.*$/\1/' /proc/cgroups`; do
mkdir -p /sys/fs/cgroup/$d
mountpoint -q /sys/fs/cgroup/$d || (mount -n -t cgroup -o $d cgroup /sys/fs/cgroup/$d || rmdir /sys/fs/cgroup/$d || true)
# 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

exit 0

+ 12
- 7
cgroupfs-umount View File

@@ -1,19 +1,24 @@
#!/bin/sh
# Copyright 2011 Canonical, Inc
# 2014 Tianon Gravi
# Author: Serge Hallyn <serge.hallyn@canonical.com>
# Tianon Gravi <admwiggin@gmail.com>
set -e

# We don't care to move tasks around gratuitously - just umount
# the cgroups
# we don't care to move tasks around gratuitously - just umount the cgroups

# If /sys/fs/cgroup is not mounted, we don't bother
# if /sys/fs/cgroup is not mounted, we don't bother
mountpoint -q /sys/fs/cgroup || exit 0

cd /sys/fs/cgroup
for d in `sed -e '1d;s/\([^\t]\)\t.*$/\1/' /proc/cgroups`; do
mountpoint -q $d && umount $d
[ -d $d ] && rmdir $d

for sys in *; do
if mountpoint -q $sys; then
umount $sys
fi
if [ -d $sys ]; then
rmdir $sys || true
fi
done

exit 0

Loading…
Cancel
Save