summaryrefslogtreecommitdiff
path: root/lxc/lxc-cgroups
blob: c920d44ccb212686b1f3e83cf50e205a19f8bb4b (plain)
    1 #!/bin/sh
    2 #
    3 # /etc/rc.d/lxc-cgroups: setup lxc cgroups
    4 #
    5 
    6 if test ! -f /proc/cgroups
    7 then
    8     echo 'cgroups are not enabled on this kernel.'
    9     exit 1
   10 fi
   11 
   12 case $1 in
   13     start)
   14         # Mount system cgroups.
   15         mount -t tmpfs -o nosuid,nodev,noexec,mode=0755 tmpfs /sys/fs/cgroup
   16         for i in $(awk '!/^#/{if($4==1){print$1}}' /proc/cgroups)
   17         do
   18             mkdir /sys/fs/cgroup/$i
   19             mount -t cgroup -o nosuid,nodev,noexec,$i cgroup /sys/fs/cgroup/$i
   20         done
   21         mkdir /sys/fs/cgroup/systemd
   22         mount -t cgroup -o nosuid,nodev,noexec,none,name=systemd cgroup /sys/fs/cgroup/systemd
   23         mkdir /sys/fs/cgroup/unified
   24         mount -t cgroup2 -o nosuid,nodev,noexec cgroup /sys/fs/cgroup/unified
   25         mount -o ro,remount /sys/fs/cgroup
   26         # Setup user cgroups.
   27         if test -f /etc/lxc/lxc-usernet
   28         then
   29             test -f /sys/fs/cgroup/cpuset/cgroup.clone_children && echo 1 > /sys/fs/cgroup/cpuset/cgroup.clone_children
   30             test -f /sys/fs/cgroup/memory/memory.use_hierarchy  && echo 1 > /sys/fs/cgroup/memory/memory.use_hierarchy
   31             for i in $(awk '!/^#/{if($1!~"@"){print$1}}' /etc/lxc/lxc-usernet)
   32             do
   33                 for j in /sys/fs/cgroup/*
   34                 do
   35                     test $j = /sys/fs/cgroup/unified && continue
   36                     mkdir -m 0755 -p $j/$i
   37                     chown -R $i $j/$i
   38                 done
   39             done
   40         fi
   41         ;;
   42     stop)
   43         umount -R /sys/fs/cgroup
   44         ;;
   45     restart)
   46         $0 stop
   47         $0 start
   48         ;;
   49     *)
   50         echo "Usage: $0 [start|stop|restart]"
   51         ;;
   52 esac
   53 
   54 # End of file

Generated by cgit