From: Ismaƫl Bouya Date: Sat, 17 Mar 2018 11:46:37 +0000 (+0100) Subject: Add puppet_apply script with lockfile X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=cfa8eb925ff0115d5d4b2298f7d9a054b869fa75;p=perso%2FImmae%2FProjets%2FPuppet.git Add puppet_apply script with lockfile --- diff --git a/modules/base_installation/files/cronie/puppet-post-merge b/modules/base_installation/files/cronie/puppet-post-merge index ac5e3ff..f5c21a7 100644 --- a/modules/base_installation/files/cronie/puppet-post-merge +++ b/modules/base_installation/files/cronie/puppet-post-merge @@ -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 index 0000000..69673cc --- /dev/null +++ b/modules/base_installation/files/scripts/puppet_apply @@ -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 diff --git a/modules/base_installation/files/scripts/puppet_reset_and_apply b/modules/base_installation/files/scripts/puppet_reset_and_apply index 6743044..0350e6e 100644 --- a/modules/base_installation/files/scripts/puppet_reset_and_apply +++ b/modules/base_installation/files/scripts/puppet_reset_and_apply @@ -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 diff --git a/modules/base_installation/manifests/cronie.pp b/modules/base_installation/manifests/cronie.pp index e8d5dfd..e8f3e20 100644 --- a/modules/base_installation/manifests/cronie.pp +++ b/modules/base_installation/manifests/cronie.pp @@ -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" } diff --git a/modules/base_installation/manifests/puppet.pp b/modules/base_installation/manifests/puppet.pp index 6f7732d..0cb43bc 100644 --- a/modules/base_installation/manifests/puppet.pp +++ b/modules/base_installation/manifests/puppet.pp @@ -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")