cleanup ip address and insert it into /etc/hosts inside container
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 24 Oct 2010 12:23:20 +0000 (12:23 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 24 Oct 2010 12:23:20 +0000 (12:23 +0000)
git-svn-id: svn://svn.rot13.org/sysadmin-cookbook@233 191e9f34-6774-4a6d-acfc-7664dacd4a2a

recepies/lxc/lxc-watchdog.sh

index 9220c9f..14b8b7c 100755 (executable)
@@ -47,8 +47,9 @@ lxc_hostname() {
 }
 
 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 //'
+       ( grep lxc.network.ipv4 /var/lib/lxc/$name/config | cut -d= -f2 || \
+       grep address $(lxc_rootfs $name)/etc/network/interfaces | sed 's/.*address //' ) | \
+       sed -e 's/ *//g' -e 's/\/.*$//'
 }
 
 lxc_status() {
@@ -71,6 +72,7 @@ cleanup_init_scripts() {
        2>/dev/null | xargs -i rm -v {}
 
        echo $1 > $rootfs/etc/hostname
+       grep $1 $rootfs/etc/hosts || echo "$(lxc_ip $1) $1" >> $rootfs/etc/hosts
 }