extract lxc_hostname and lxc_ip into functions
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 24 Oct 2010 11:55:02 +0000 (11:55 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 24 Oct 2010 11:55:02 +0000 (11:55 +0000)
git-svn-id: svn://svn.rot13.org/sysadmin-cookbook@232 191e9f34-6774-4a6d-acfc-7664dacd4a2a

recepies/lxc/lxc-watchdog.sh

index fb0aa44..9220c9f 100755 (executable)
@@ -40,15 +40,22 @@ lxc_rootfs() {
        grep '^ *lxc\.rootfs *=' "/var/lib/lxc/$1/config" | cut -d= -f2 | sed 's/^ *//'
 }
 
+lxc_hostname() {
+       inside=`cat $(lxc_rootfs $1)/etc/hostname`
+       config=`grep lxc.utsname /var/lib/lxc/$name/config | cut -d= -f2`
+       echo "$config [$inside]";
+}
+
+lxc_ip() {
+       grep lxc.network.ipv4 /var/lib/lxc/$name/config | cut -d= -f2 ||
+       grep address $(lxc_rootfs $name)/etc/network/interfaces | sed 's/.*address //'
+}
 
 lxc_status() {
        ( find /var/lib/lxc/ -name "config" | cut -d/ -f5 | sort -u | xargs -i lxc-info -n {} | sed "s/'//g" | while read name is status ; do
                boot="-"
-               hostname=`cat $(lxc_rootfs $name)/etc/hostname`
-               ip=`grep address $(lxc_rootfs $name)/etc/network/interfaces | sed 's/.*address //'`
-               test -z "$ip" && ip=`grep lxc.network.ipv4 /var/lib/lxc/$name/config | cut -d= -f2`
                test -s /var/lib/lxc/$name/on_boot && boot="boot"
-               echo "$name $status $boot $(lxc_rootfs $name) $ip $hostname"
+               echo "$name $status $boot $(lxc_rootfs $name) $(lxc_ip $name) $(lxc_hostname $name)"
        done ) | column -t
 }