Revision 7b642c49
b/daemons/ganeti-cleaner.in | ||
---|---|---|
1 | 1 |
#!/bin/bash |
2 | 2 |
# |
3 | 3 |
|
4 |
# Copyright (C) 2009, 2010 Google Inc. |
|
4 |
# Copyright (C) 2009, 2010, 2011 Google Inc.
|
|
5 | 5 |
# |
6 | 6 |
# This program is free software; you can redistribute it and/or modify |
7 | 7 |
# it under the terms of the GNU General Public License as published by |
... | ... | |
20 | 20 |
|
21 | 21 |
set -e |
22 | 22 |
|
23 |
in_cluster() { |
|
24 |
[[ -e $DATA_DIR/ssconf_master_node ]] |
|
25 |
} |
|
26 |
|
|
23 | 27 |
cleanup_master() { |
24 | 28 |
# Return if machine is not part of a cluster |
25 |
[[ -e $DATA_DIR/ssconf_master_node ]] || return 0
|
|
29 |
in_cluster || return 0
|
|
26 | 30 |
|
27 | 31 |
# Return if queue archive directory doesn't exist |
28 | 32 |
[[ -d $QUEUE_ARCHIVE_DIR ]] || return 0 |
... | ... | |
45 | 49 |
done |
46 | 50 |
} |
47 | 51 |
|
52 |
cleanup_watcher() { |
|
53 |
# Return if machine is not part of a cluster |
|
54 |
in_cluster || return 0 |
|
55 |
|
|
56 |
# Remove old watcher files |
|
57 |
find $DATA_DIR -maxdepth 1 -type f -mtime +$REMOVE_AFTER \ |
|
58 |
-name 'watcher.*-*-*-*.data' -print0 | \ |
|
59 |
xargs -r0 rm -vf |
|
60 |
} |
|
61 |
|
|
48 | 62 |
# Overridden by unittest |
49 | 63 |
: ${LOCALSTATEDIR:=@LOCALSTATEDIR@} |
50 | 64 |
: ${CHECK_CERT_EXPIRED:=@PKGLIBDIR@/check-cert-expired} |
... | ... | |
77 | 91 |
|
78 | 92 |
cleanup_master |
79 | 93 |
cleanup_node |
94 |
cleanup_watcher |
|
80 | 95 |
|
81 | 96 |
exit 0 |
b/test/ganeti-cleaner_unittest.bash | ||
---|---|---|
55 | 55 |
[[ "$count" -eq "$n" ]] || err "Found $count jobs instead of $n" |
56 | 56 |
} |
57 | 57 |
|
58 |
count_watcher() { |
|
59 |
local n=$1 |
|
60 |
local count=$(find $watcherdir -maxdepth 1 -type f \ |
|
61 |
-name 'watcher.*.data' | wc -l) |
|
62 |
[[ "$count" -eq "$n" ]] || err "Found $count watcher files instead of $n" |
|
63 |
} |
|
64 |
|
|
58 | 65 |
count_and_check_certs() { |
59 | 66 |
local n=$1 |
60 | 67 |
local count=$(find $cryptodir -mindepth 1 -type f -name cert | wc -l) |
... | ... | |
97 | 104 |
done |
98 | 105 |
} |
99 | 106 |
|
107 |
create_watcher_state() { |
|
108 |
local uuids=( |
|
109 |
6792a0d5-f8b6-4531-8d8c-3680c86b8a53 |
|
110 |
ab74da37-f5f7-44c4-83ad-074159772593 |
|
111 |
fced2e48-ffff-43ae-919e-2b77d37ecafa |
|
112 |
6e89ac57-2eb1-4a16-85a1-94daa815d643 |
|
113 |
8714e8f5-59c4-47db-b2cb-196ec37978e5 |
|
114 |
91763d73-e1f3-47c7-a735-57025d4e2a7d |
|
115 |
e27d3ff8-9546-4e86-86a4-04151223e140 |
|
116 |
aa3f63dd-be17-4ac8-bd01-d71790e124cb |
|
117 |
05b6d7e2-003b-40d9-a6d6-ab61bf123a15 |
|
118 |
54c93e4c-61fe-40de-b47e-2a8e6c805d02 |
|
119 |
) |
|
120 |
|
|
121 |
i=0 |
|
122 |
for uuid in ${uuids[@]}; do |
|
123 |
touch -d "$(( 5 * i )) days ago" $watcherdir/watcher.$uuid.data |
|
124 |
|
|
125 |
let ++i |
|
126 |
done |
|
127 |
} |
|
128 |
|
|
100 | 129 |
create_certdirs() { |
101 | 130 |
local cert=$1; shift |
102 | 131 |
local certdir |
... | ... | |
117 | 146 |
tmpls=$tmpdir/var |
118 | 147 |
queuedir=$tmpls/lib/ganeti/queue |
119 | 148 |
cryptodir=$tmpls/run/ganeti/crypto |
149 |
watcherdir=$tmpls/lib/ganeti |
|
120 | 150 |
|
121 | 151 |
mkdir -p $tmpls/{lib,log,run}/ganeti $queuedir/archive $cryptodir |
122 | 152 |
|
... | ... | |
165 | 195 |
check_logfiles $maxlog |
166 | 196 |
count_jobs 31 |
167 | 197 |
|
198 |
upto 'Watcher status files' |
|
199 |
create_watcher_state |
|
200 |
count_watcher 10 |
|
201 |
run_cleaner |
|
202 |
count_watcher 5 |
|
203 |
|
|
168 | 204 |
exit 0 |
Also available in: Unified diff