You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

62 lines
1.5 KiB

  1. #!/bin/sh
  2. # Copyright 2011 Canonical, Inc
  3. # 2014 Tianon Gravi
  4. # Author: Serge Hallyn <serge.hallyn@canonical.com>
  5. # Tianon Gravi <tianon@debian.org>
  6. set -e
  7. # for simplicity this script provides no flexibility
  8. # if cgroup is mounted by fstab, don't run
  9. # don't get too smart - bail on any uncommented entry with 'cgroup' in it
  10. if grep -v '^#' /etc/fstab | grep -q cgroup; then
  11. echo 'cgroups mounted from fstab, not mounting /sys/fs/cgroup'
  12. exit 0
  13. fi
  14. # kernel provides cgroups?
  15. if [ ! -e /proc/cgroups ]; then
  16. exit 0
  17. fi
  18. # if we don't even have the directory we need, something else must be wrong
  19. if [ ! -d /sys/fs/cgroup ]; then
  20. exit 0
  21. fi
  22. # mount /sys/fs/cgroup if not already done
  23. if ! mountpoint -q /sys/fs/cgroup; then
  24. mount -t tmpfs -o uid=0,gid=0,mode=0755 cgroup /sys/fs/cgroup
  25. fi
  26. cd /sys/fs/cgroup
  27. # get/mount list of enabled cgroup controllers
  28. for sys in $(awk '!/^#/ { if ($4 == 1) print $1 }' /proc/cgroups); do
  29. mkdir -p $sys
  30. if ! mountpoint -q $sys; then
  31. if ! mount -n -t cgroup -o $sys cgroup $sys; then
  32. rmdir $sys || true
  33. fi
  34. fi
  35. done
  36. # example /proc/cgroups:
  37. # #subsys_name hierarchy num_cgroups enabled
  38. # cpuset 2 3 1
  39. # cpu 3 3 1
  40. # cpuacct 4 3 1
  41. # memory 5 3 0
  42. # devices 6 3 1
  43. # freezer 7 3 1
  44. # blkio 8 3 1
  45. # enable cgroups memory hierarchy, like systemd does (and lxc/docker desires)
  46. # https://github.com/systemd/systemd/blob/v245/src/core/cgroup.c#L2983
  47. # https://bugs.debian.org/940713
  48. if [ -e /sys/fs/cgroup/memory/memory.use_hierarchy ]; then
  49. echo 1 > /sys/fs/cgroup/memory/memory.use_hierarchy
  50. fi
  51. exit 0