]> git.proxmox.com Git - mirror_lxc.git/commitdiff
List the available containers and the processes belonging to such container.
authordlezcano <dlezcano>
Tue, 18 Nov 2008 09:40:05 +0000 (09:40 +0000)
committerdlezcano <dlezcano>
Tue, 18 Nov 2008 09:40:05 +0000 (09:40 +0000)
From: Daniel Lezcano <dlezcano@fr.ibm.com>

This modification change the lxc-ps command and adds the lxc-ls command.

The lxc-ps command takes the container name argument and shows the processes
belonging to the specified container. The usual ps argument can be passed to
the lxc-ps to change the output.
Examples:
  lxc-ps -n foo --forest
  lxc-ps -n foo -o pid=

The lxc-ls command list the container name available on the system. This is
useful to retrieve information for each container.
Examples:
  for i in $(lxc-ls); do
lxc-info -n $i
lxc-ps -n $i --forest
  done

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
src/lxc/Makefile.am
src/lxc/lxc-ls.in [new file with mode: 0644]
src/lxc/lxc-ps.in

index ead9a8ac9d639d2cb43cfe59438b1361bf24b364..4ea70008e4f3f9cc6f963a1a727531d0ed4d9616 100644 (file)
@@ -42,6 +42,7 @@ liblxc_la_LDFLAGS = -release @PACKAGE_VERSION@
 
 bin_SCRIPTS = \
        lxc-ps \
+       lxc-ls \
        lxc-checkconfig
 
 bin_PROGRAMS = \
diff --git a/src/lxc/lxc-ls.in b/src/lxc/lxc-ls.in
new file mode 100644 (file)
index 0000000..f7dd15d
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+lxcpath=@prefix@/var/lxc
+
+if [ ! -r $lxcpath ]; then
+    exit 0
+fi
+
+ls -1 $lxcpath
index dae220b21ef4170464f49617ec2e68c8e2f751fd..f4c197005c176b357c3ab2420f155ac2a06a42f7 100755 (executable)
@@ -1,17 +1,34 @@
 #!/bin/bash
+# set -ex
+lxcpath=@prefix@/var/lxc
 
-LXCPATH=/var/lxc
-
-if [ ! -r $LXCPATH ]; then
+if [ ! -r $lxcpath ]; then
     exit 0
 fi
 
-LXCS=$(ls $LXCPATH)
+if [ $# -eq  0 ]; then
+    echo "usage: $0 -n <name>"
+    exit 1
+fi
 
-for i in $LXCS; do
-    if [ -d $LXCPATH/$i/nsgroup ]; then
-       echo "Container : $(basename $i)"
-       cat $LXCPATH/$i/nsgroup/tasks
-    fi
+for i in $*; do
+    case $i in
+       -n)
+           name=$2; shift 2;;
+    esac
 done
 
+if [ -z "$name" ]; then
+    echo "usage: $0 -n <name>"
+    exit 1
+fi
+
+if [ ! -d $lxcpath/$name ]; then
+    echo "'$name' does not exists"
+    exit 1
+fi
+
+if [ -h $lxcpath/$name/nsgroup ]; then
+    ps $* -p $(cat $lxcpath/$name/nsgroup/tasks)
+fi
+