[cgmanager-devel] [PATCH RFC] Add a cgm client script for convenience

Serge Hallyn serge.hallyn at ubuntu.com
Thu Mar 20 00:14:08 UTC 2014


Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
---
 Makefile.am |   2 +
 cgm         | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 132 insertions(+)
 create mode 100755 cgm

diff --git a/Makefile.am b/Makefile.am
index 5d1cc47..adc0d24 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -24,6 +24,8 @@ CLEANFILES = \
 
 sbin_PROGRAMS = cgmanager cgproxy
 
+bin_SCRIPTS = cgm
+
 lib_LTLIBRARIES = libcgmanager.la
 
 pkginclude_HEADERS = cgmanager-client.h cgmanager.h
diff --git a/cgm b/cgm
new file mode 100755
index 0000000..931303c
--- /dev/null
+++ b/cgm
@@ -0,0 +1,130 @@
+#!/bin/bash
+
+# (C) Copyright Canonical Ltd. 2014
+#
+# Authors:
+# Serge Hallyn <serge.hallyn at ubuntu.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+
+usage() {
+	me=`basename $1`
+	echo "Usage:"
+	echo "   $me ping"
+	echo "   $me create <controller<>> cgroup"
+	echo "   $me chown <controller> <cgroup> uid gid"
+	echo "   $me chmod <controller> <cgroup> mode"
+	echo "   $me remove <controller> <cgroup>"
+	echo "   $me getpidcgroup <controller> pid"
+	echo "   $me movepid <controller> <cgroup> pid"
+	echo "   $me getvalue <controller> <cgroup> file"
+	echo "   $me setvalue <controller> <cgroup> file value"
+	echo "   $me gettasks <controller> <cgroup>"
+	echo "   $me listchildren <controller> <cgroup>"
+	echo "   $me apiversion"
+	echo ""
+	echo " Replace '<controller>' with the desired controller, i.e."
+	echo " memory, and '<cgroup>' with the desired cgroup, i.e. x1."
+	echo " To refer to the current cgroup, use ''."
+	exit 1
+}
+
+if [ $# -lt 1 ]; then
+	usage $0
+fi
+
+case "$1" in
+	ping)
+		dbus-send --print-reply --address=unix:path=/sys/fs/cgroup/cgmanager/sock --type=method_call /org/linuxcontainers/cgmanager org.linuxcontainers.cgmanager0_0.Ping int32:0
+		exit $?
+	;;
+	getvalue)
+		if [ $# -lt 4 ]; then
+			usage $0
+		fi
+		dbus-send --print-reply --address=unix:path=/sys/fs/cgroup/cgmanager/sock --type=method_call /org/linuxcontainers/cgmanager org.linuxcontainers.cgmanager0_0.GetValue string:$2 string:$3 string:$4
+		exit $?
+	;;
+	remove)
+		if [ $# -lt 3 ]; then
+			usage $0
+		fi
+		dbus-send --print-reply --address=unix:path=/sys/fs/cgroup/cgmanager/sock --type=method_call /org/linuxcontainers/cgmanager org.linuxcontainers.cgmanager0_0.Remove string:$2 string:$3 int32:1
+		exit $?
+	;;
+	create)
+		if [ $# -lt 3 ]; then
+			usage $0
+		fi
+		dbus-send --print-reply --address=unix:path=/sys/fs/cgroup/cgmanager/sock --type=method_call /org/linuxcontainers/cgmanager org.linuxcontainers.cgmanager0_0.Create string:$2 string:$3
+		exit $?
+	;;
+	chown)
+		if [ $# -lt 5 ]; then
+			usage $0
+		fi
+		dbus-send --print-reply --address=unix:path=/sys/fs/cgroup/cgmanager/sock --type=method_call /org/linuxcontainers/cgmanager org.linuxcontainers.cgmanager0_0.Chown string:$2 string:$3 int32:$4 int32:$5
+		exit $?
+	;;
+	chmod)
+		if [ $# -lt 4 ]; then
+			usage $0
+		fi
+		dbus-send --print-reply --address=unix:path=/sys/fs/cgroup/cgmanager/sock --type=method_call /org/linuxcontainers/cgmanager org.linuxcontainers.cgmanager0_0.Chmod string:$2 string:$3 int32:$4
+		exit $?
+	;;
+	getpidcgroup)
+		if [ $# -lt 3 ]; then
+			usage $0
+		fi
+		dbus-send --print-reply --address=unix:path=/sys/fs/cgroup/cgmanager/sock --type=method_call /org/linuxcontainers/cgmanager org.linuxcontainers.cgmanager0_0.GetPidCgroup string:$2 int32:$3
+		exit $?
+	;;
+	movepid)
+		if [ $# -lt 4 ]; then
+			usage $0
+		fi
+		dbus-send --print-reply --address=unix:path=/sys/fs/cgroup/cgmanager/sock --type=method_call /org/linuxcontainers/cgmanager org.linuxcontainers.cgmanager0_0.MovePid string:$2 string:$3 int32:$4
+		exit $?
+	;;
+	setvalue)
+		if [ $# -lt 5 ]; then
+			usage $0
+		fi
+		dbus-send --print-reply --address=unix:path=/sys/fs/cgroup/cgmanager/sock --type=method_call /org/linuxcontainers/cgmanager org.linuxcontainers.cgmanager0_0.SetValue string:$2 string:$3 string:$4 string:"$5"
+		exit $?
+	;;
+	gettasks)
+		if [ $# -lt 3 ]; then
+			usage $0
+		fi
+		dbus-send --print-reply --address=unix:path=/sys/fs/cgroup/cgmanager/sock --type=method_call /org/linuxcontainers/cgmanager org.linuxcontainers.cgmanager0_0.GetTasks string:$2 string:$3
+		exit $?
+	;;
+	listchildren)
+		if [ $# -lt 3 ]; then
+			usage $0
+		fi
+		dbus-send --print-reply --address=unix:path=/sys/fs/cgroup/cgmanager/sock --type=method_call /org/linuxcontainers/cgmanager org.linuxcontainers.cgmanager0_0.ListChildren string:$2 string:$3
+		exit $?
+	;;
+	apiversion)
+		dbus-send --print-reply --address=unix:path=/sys/fs/cgroup/cgmanager/sock /org/linuxcontainers/cgmanager org.freedesktop.DBus.Properties.Get string:'org.linuxcontainers.cgmanager0_0' string:'api_version'
+		exit $?
+	;;
+	*)
+	usage $0
+esac
-- 
1.9.0



More information about the cgmanager-devel mailing list