#! /bin/sh ### BEGIN INIT INFO # Provides: cgroupfs-systemd # Required-Start: mountkernfs $local_fs # Required-Stop: # Default-Start: S # Default-Stop: 0 6 # Should-Start: cgroupfs-mount # Short-Description: systemd cgroup filesystem # Description: Mount a named cgroup hierarchy 'systemd' so that Jessie # systemd containers will work under this host. ### END INIT INFO # Author: Christian Seiler # PATH should only include /usr/* if it runs after the mountnfs.sh script PATH=/sbin:/usr/sbin:/bin:/usr/bin DESC="systemd cgroup filesystem" SCRIPTNAME=/etc/init.d/cgfs-systemd # Load the VERBOSE setting and other rcS variables . /lib/init/vars.sh # Define LSB log_* functions. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present # and status_of_proc is working. . /lib/lsb/init-functions CGTMPFS=/sys/fs/cgroup CGPATH=/sys/fs/cgroup/systemd XATTR=",xattr" # see http://stackoverflow.com/questions/4023830/bash-how-compare-two-strings-in-version-format verlte() { [ "$1" = "`printf '%s\n%s\n' "$1" "$2" | sort -V | head -n1`" ] return $? } if ! verlte 3.7 "$(uname --kernel-release)" ; then # Kernel not new enough to support xattrs for cgroups, # mount anyway, and hope that the user knows what they're # doing. XATTR="" fi if [ -x /usr/bin/cgroupfs-mount ] ; then # cgroupfs-mount is installed from wheezy-backports, so maybe # the default path in /sys/fs/cgroup is actually used if grep -v '^#' /etc/fstab | grep -q cgroup; then # oh, but cgroup is active in /etc/fstab, # so cgroupfs-mount will just be a NO-OP, # so use other path CGTMPFS= CGPATH=/run/cgroup/systemd fi else # either in /etc/fstab or something else, in either case # be conservative and mount the systemd hierarchy to # somewhere else... CGTMPFS= CGPATH=/run/cgroup/systemd fi [ -d /etc/default/cgfs-systemd ] && . /etc/default/cgfs-systemd umask 022 do_start() { if [ -n "$CGTMPFS" ] ; then mkdir -p "$CGTMPFS" || return 2 if ! mountpoint -q "$CGTMPFS" ; then mount -t tmpfs none "$CGTMPFS" fi fi mkdir -p "$CGPATH" || return 2 mount -t cgroup \ -o rw,none,name=systemd,nosuid,nodev,noexec,relatime$XATTR \ cgroup "$CGPATH" || return 2 } do_stop() { umount "$CGPATH" || : if mountpoint -q "$CGPATH" ; then return 2 fi # try to remove, but don't care about errors here rmdir "$CGPATH" || : # ignore errors here, other hierarchies might be mounted if [ -n "$CGTMPFS" ] ; then umount "$CGTMPFS" || : fi return 0 } case "$1" in start) [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" do_start case "$?" in 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; esac ;; stop) [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" do_stop case "$?" in 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; esac ;; status) status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? ;; restart|force-reload) # # If the "reload" option is implemented then remove the # 'force-reload' alias # log_daemon_msg "Restarting $DESC" "$NAME" do_stop case "$?" in 0|1) do_start case "$?" in 0) log_end_msg 0 ;; 1) log_end_msg 1 ;; # Old process is still running *) log_end_msg 1 ;; # Failed to start esac ;; *) # Failed to stop log_end_msg 1 ;; esac ;; *) echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 exit 3 ;; esac :