This repository has been archived by the owner on Sep 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
puppet-done-test.sh
executable file
·132 lines (116 loc) · 2.78 KB
/
puppet-done-test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
NO_ARGS=0
OPTERROR=65
usage()
{
echo "Usage: $0 -s <seconds>"
echo " s = number of seconds to sleep"
exit 1
}
if [ $# -eq "$NO_ARGS" ]
then
usage
fi
# how long do we wait in the different stages?
# 5 minutes is 300 seconds
# 30 minutes is 1800 seconds
MAX_STATE_WAIT=300
MAX_LOCK_WAIT=1800
MAX_FINISH_WAIT=1800
look_for_state()
{
WAIT=0
while [[ ! -d /var/lib/puppet/state ]]
do
echo "no /var/lib/puppet/state yet, waiting since ${WAIT} seconds, checking again in 10 seconds"
sleep 10
((WAIT+=10))
if [[ ${WAIT} -gt ${MAX_STATE_WAIT} ]]
then
echo "no /var/lib/puppet/state after ${MAX_STATE_WAIT} seconds. Exiting."
exit 1
fi
done
}
look_for_daemon_lock()
{
WAIT=0
while [[ -e /var/lib/puppet/state/puppetdlock ]]
do
echo "puppet daemon is holding a lock, waiting since ${WAIT} seconds, waiting 10 secs until next check"
sleep 10
((WAIT+=10))
if [[ ${WAIT} -gt ${MAX_LOCK_WAIT} ]]
then
echo "puppet daemon still holding lock after ${MAX_LOCK_WAIT} seconds. Exiting."
exit 1
fi
done
echo "puppet daemon not holding lock"
}
look_for_agent_lock()
{
WAIT=0
while [[ -e /var/lib/puppet/state/agent_catalog_run.lock ]]
do
echo "puppet agent is holding a lock, waiting since ${WAIT} seconds, waiting 10 secs until next check"
sleep 10
((WAIT+=10))
if [[ ${WAIT} -gt ${MAX_LOCK_WAIT} ]]
then
echo "puppet agent still holding lock after ${MAX_LOCK_WAIT} seconds. Exiting."
exit 1
fi
done
echo "puppet agent not holding lock"
}
look_for_finished()
{
NOTFINISHED=1
WAIT=0
while [[ ${NOTFINISHED} -ne 0 ]]
do
echo "Checking if puppet is done, waiting since ${WAIT} seconds"
grep 'Finished catalog run\|Failed to apply catalog' /var/lib/puppet/state/last_run_report.yaml
NOTFINISHED=$?
sleep 10
((WAIT+=10))
if [[ ${WAIT} -gt ${MAX_FINISH_WAIT} ]]
then
echo "puppet not done after ${MAX_FINISH_WAIT} seconds. Exiting."
exit 1
fi
done
}
date
# Let's not wait for puppet on a host that is actually using Ansible
if ! rpm -q puppet ; then
echo "puppet is not installed"
exit 0
fi
while getopts "c:n:s:h" Option
do
case $Option in
s) SLEEP=${OPTARG}
;;
h)
usage
;;
*) echo "Non valid switch"
;;
esac
done
# if you run puppet on boot, sleep 75 seconds (just over a minute)
# if this is a run in the puppet only workflow, no real need to sleep
echo "waiting ${SLEEP} seconds before checking on puppet"
sleep ${SLEEP}
# /var/lib/puppet/state gets created on first run?
look_for_state
# now that the directory is there, look for the daemon lock
look_for_daemon_lock
# look for agent lock
look_for_agent_lock
# see if puppet has finished
look_for_finished
date
echo "puppet seems done"