]> WPIA git - infra.git/blobdiff - modules/lxc/manifests/init.pp
chg: extract lxc-bind-mounts to own resources
[infra.git] / modules / lxc / manifests / init.pp
index 4b7b64222461cc461d0b5f7053b2ae08c3dc3c90..3693966f0f0ef965356efe63692dc0a2929880ef 100644 (file)
@@ -23,6 +23,20 @@ class lxc {
       refreshonly => true,
       subscribe => File['/etc/network/interfaces.d/lxcbr0']
     }
+    
+    define container_bind($container, $out = $name, $target, $option = ""){
+      file{"/var/lib/lxc/$container/rootfs/$target":
+        ensure => directory,
+        require => File_line["lxc-$container-conf5"],
+        before => Exec["lxc-$container-started"]
+      }->
+      file_line { "lxc-$container-mount-$out":
+        path   => "/var/lib/lxc/$container/config",
+        line   => "lxc.mount.entry = $out $target none bind$option 0 0",
+        require=> [File_line["lxc-$container-conf5"], File["$out"]],
+        notify  => Exec["lxc-$container-started"],
+      }
+    }
     define container ($contname, $ip, $dir = [], $bind = {}, $confline = []) {
         exec {"lxc-$contname-issue-cert":
           command => "/usr/bin/puppet ca destroy \"$contname\";/usr/bin/puppet ca generate \"$contname\"",
@@ -75,9 +89,9 @@ class lxc {
         } -> exec {"lxc-$contname-started":
             path => '/usr/bin',
             refreshonly   => true,
-            refresh   => "/usr/bin/lxc-stop -n $contname ; /usr/bin/lxc-start -dn $contname",
+            refresh   => "/usr/bin/lxc-stop -n $contname ; /usr/bin/lxc-start -dn $contname; /usr/bin/lxc-attach -n $contname -- bash -c 'while ! [[ -S /run/systemd/private ]]; do sleep 1; done'",
         }-> exec {"lxc-$contname-started1":
-            command   => "/usr/bin/lxc-start -dn $contname",
+            command   => "/usr/bin/lxc-start -dn $contname; /usr/bin/lxc-attach -n $contname -- bash -c 'while ! [[ -S /run/systemd/private ]]; do sleep 1; done'",
             unless    => "/usr/bin/[ \"\$(lxc-info -Hsn $contname)\" != \"STOPPED\" ]",
         }
         $dir.each |String $in| {