diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-03-17 12:46:37 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-03-19 16:19:17 +0100 |
commit | cfa8eb925ff0115d5d4b2298f7d9a054b869fa75 (patch) | |
tree | 7ec29ae80af561a848a9c9da7f01731345afe587 /modules/base_installation/files/scripts/puppet_apply | |
parent | 82caf31189f11a9bca4836260e8ee8ba954690f2 (diff) | |
download | Puppet-cfa8eb925ff0115d5d4b2298f7d9a054b869fa75.tar.gz Puppet-cfa8eb925ff0115d5d4b2298f7d9a054b869fa75.tar.zst Puppet-cfa8eb925ff0115d5d4b2298f7d9a054b869fa75.zip |
Add puppet_apply script with lockfile
Diffstat (limited to 'modules/base_installation/files/scripts/puppet_apply')
-rw-r--r-- | modules/base_installation/files/scripts/puppet_apply | 23 |
1 files changed, 23 insertions, 0 deletions
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 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | lockfile=/var/run/puppet-apply.lock | ||
4 | path=`dirname $0` | ||
5 | path=`cd $path/..; pwd` | ||
6 | |||
7 | if [ $(id -u) -gt 0 ]; then | ||
8 | echo "You must be root to run this script." >&2 | ||
9 | exit 2 | ||
10 | fi | ||
11 | |||
12 | if (set -o noclobber; echo "$$" > "$lockfile") 2> /dev/null; then | ||
13 | trap 'rm -f "$lockfile"; exit $?' INT TERM EXIT | ||
14 | |||
15 | puppet apply "$@" | ||
16 | |||
17 | rm -f "$lockfile" | ||
18 | trap - INT TERM EXIT | ||
19 | else | ||
20 | echo "Failed to acquire lockfile: $lockfile." >&2 | ||
21 | echo "Held by $(cat $lockfile 2>/dev/null)" >&2 | ||
22 | exit 1 | ||
23 | fi | ||