]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/commitdiff
Add puppet_apply script with lockfile
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Sat, 17 Mar 2018 11:46:37 +0000 (12:46 +0100)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 19 Mar 2018 15:19:17 +0000 (16:19 +0100)
modules/base_installation/files/cronie/puppet-post-merge
modules/base_installation/files/scripts/puppet_apply [new file with mode: 0644]
modules/base_installation/files/scripts/puppet_reset_and_apply
modules/base_installation/manifests/cronie.pp
modules/base_installation/manifests/puppet.pp

index ac5e3ff1cc57456ad93054d7fff9a697a1f7f035..f5c21a72aa796fd5b475bee2ab6805781f1b20ad 100644 (file)
@@ -1,7 +1,7 @@
 #!/bin/bash
-## Run Puppet locally using puppet apply
+## Run Puppet locally using puppet_apply
 git submodule update --init
-/usr/bin/puppet apply `pwd`/manifests/site.pp
+/usr/local/sbin/puppet_apply `pwd`/manifests/site.pp
 
 ## Log status of the Puppet run
 if [ $? -eq 0 ]
diff --git a/modules/base_installation/files/scripts/puppet_apply b/modules/base_installation/files/scripts/puppet_apply
new file mode 100644 (file)
index 0000000..69673cc
--- /dev/null
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+lockfile=/var/run/puppet-apply.lock
+path=`dirname $0`
+path=`cd $path/..; pwd`
+
+if [ $(id -u) -gt 0 ]; then
+  echo "You must be root to run this script." >&2
+  exit 2
+fi
+
+if (set -o noclobber; echo "$$" > "$lockfile") 2> /dev/null; then
+  trap 'rm -f "$lockfile"; exit $?' INT TERM EXIT
+
+  puppet apply "$@"
+
+  rm -f "$lockfile"
+  trap - INT TERM EXIT
+else
+  echo "Failed to acquire lockfile: $lockfile." >&2
+  echo "Held by $(cat $lockfile 2>/dev/null)" >&2
+  exit 1
+fi
index 6743044152de39e24c0ef3bd7e0b37b33b40448a..0350e6e17e7e78ebe4eeb4029c289490d937fb8e 100644 (file)
@@ -11,4 +11,4 @@ fi
 git reset --hard origin/$branch
 
 git submodule update --init
-puppet apply --test manifests/site.pp
+puppet_apply --test manifests/site.pp
index e8d5dfd6980f2d2531963097e1b35893fdb513dc..e8f3e20eb456d8d87257812879d4f07897f02796 100644 (file)
@@ -19,13 +19,13 @@ class base_installation::cronie inherits base_installation {
     }
     cron { 'puppet-apply':
       ensure  => present,
-      command => "cd $base_installation::puppet_code_path ; puppet apply $base_installation::puppet_code_path/manifests/site.pp",
+      command => "cd $base_installation::puppet_code_path ; puppet_apply $base_installation::puppet_code_path/manifests/site.pp",
       user    => root,
       minute  => '*/20'
     }
     cron { 'puppet-apply-reboot':
       ensure  => present,
-      command => "cd $base_installation::puppet_code_path ; puppet apply $base_installation::puppet_code_path/manifests/site.pp",
+      command => "cd $base_installation::puppet_code_path ; puppet_apply $base_installation::puppet_code_path/manifests/site.pp",
       user    => root,
       special => "reboot"
     }
index 6f7732dfed2b83c63cdbd62cd13233c5af2d87ff..0cb43bcdd24635ef84df3f9f977e4ceeb5b566ae 100644 (file)
@@ -39,6 +39,12 @@ class base_installation::puppet (
     source => "puppet:///modules/base_installation/scripts/report_print.rb"
   }
 
+  file { '/usr/local/sbin/puppet_apply':
+    mode   => "0755",
+    ensure => present,
+    source => "puppet:///modules/base_installation/scripts/puppet_apply",
+  }
+
   unless empty(find_file($password_seed)) {
     $ldap_password = generate_password(24, $password_seed, "ldap")
     $ssha_ldap_seed = generate_password(5, $password_seed, "ldap_seed")