3 if [[ -n "${PPG_DEBUG}" ]]; then
7 pushd /etc
/puppet
>/dev
/null ||
exit 1
9 PPG_EXEC_PATH
=$
( dirname $
(readlink
-f "${BASH_SOURCE[0]}" ) )
10 GIT_EXEC_PATH
=$
(git
--exec-path)
11 GIT_DIR
=$
(git rev-parse
--git-dir)
12 export GIT_SSH
="${PPG_EXEC_PATH}/ppg-ssh"
14 .
${PPG_EXEC_PATH}/ppg-functions
16 if [ -z "$GIT_DIR" ]; then
17 echo >&2 "Not in a git checkout"
21 ## FIXME?: check whether these are overriden
22 PUPPETCONF
=/etc
/puppet
/puppet.conf
23 REPORT_PATH
=/var
/lib
/puppet
/state
/last_run_report.yaml
25 # puppet.conf syntax is compat with git config syntax
26 # (both are INI style). How lucky can we be? :-)
27 report_bool
=$
(git config
-f $PUPPETCONF --bool --get agent.report
)
29 # note: default is true
30 if [ "$report_bool" = 'false' ]; then
31 echo >&2 "ERROR: reports are disabled!"
35 if [ -x /etc
/puppet
/local-puppet-apply
]; then
36 puppetcmd
=/etc
/puppet
/local-puppet-apply
38 puppetcmd
="puppet apply --detailed-exitcodes $@"
41 if /bin
/mountpoint
-q /mnt
/cluster
; then
42 # timeout at 50m, so the next hourly run has a go at it
43 # sleep ~30s between tries at the flock
44 # default 10 flocks, but will be overridden by /mnt/cluster/conf/lock/puppet
45 ${PPG_EXEC_PATH}/flock_multi
--timeout 50m
--sleeptime 30 --queuemonitor puppet
10 \
49 # some hosts don't have /mnt/cluster
50 # some need puppet to set it up first
55 # From http://docs.puppetlabs.com/man/apply.html
56 # 0 means ?? (guess: no changes)
57 # 2 means there were changes
59 # 6 means changes & failures
61 # 200 means flock_multi found an error
62 # 201 means flock_multi timed out waiting for the flock
64 if [[ $pexit -eq 00 ]] ||
[[ $pexit -eq 2 ]]; then
67 lastgood_sha1
=$
(git rev-parse
--revs-only ppg
/lastgood
)
68 if [ -n "$lastgood_sha1" ]; then
69 git push
--force . HEAD
:ppg
/lastgood
71 # setup with reflog - may be handy
73 git branch
-l ppg
/lastgood
75 elif [[ $pexit -eq 200 ]]; then
76 echo flock_multi error
!
78 elif [[ $pexit -eq 201 ]]; then # soft error
79 echo flock_multi timed out
82 ## TODO: do we want to warn in any way?
87 reportsdir
='/etc/puppet/.ppg/reports'
88 mkdir
-p ${reportsdir}/${hostname}
90 datestamp
=$
(date -u --rfc-3339=seconds|
sed 's/ /_/')
91 cp ${REPORT_PATH} ${reportsdir}/${hostname}/${datestamp}.yaml
93 # NOTE: callers rely on getting an error through if push-reports
95 exec $PPG_EXEC_PATH/ppg-push-reports