Revision 46118ed2 daemons/ganeti-cleaner.in
b/daemons/ganeti-cleaner.in | ||
---|---|---|
25 | 25 |
# Overridden by unittest |
26 | 26 |
: ${CHECK_CERT_EXPIRED:=$PKGLIBDIR/check-cert-expired} |
27 | 27 |
|
28 |
readonly CLEANER_LOG_DIR=$LOG_DIR/cleaner |
|
28 |
usage() { |
|
29 |
echo "Usage: $0 node|master" 2>&1 |
|
30 |
exit $1 |
|
31 |
} |
|
32 |
|
|
33 |
if [[ "$#" -ne 1 ]]; then |
|
34 |
usage 1 |
|
35 |
fi |
|
36 |
|
|
37 |
case "$1" in |
|
38 |
node) |
|
39 |
readonly CLEANER_LOG_DIR=$LOG_DIR/cleaner |
|
40 |
;; |
|
41 |
master) |
|
42 |
readonly CLEANER_LOG_DIR=$LOG_DIR/master-cleaner |
|
43 |
;; |
|
44 |
--help-completion) |
|
45 |
echo "choices=node,master 1 1" |
|
46 |
exit 0 |
|
47 |
;; |
|
48 |
--help) |
|
49 |
usage 0 |
|
50 |
;; |
|
51 |
*) |
|
52 |
usage 1 |
|
53 |
;; |
|
54 |
esac |
|
55 |
|
|
29 | 56 |
readonly CRYPTO_DIR=$RUN_DIR/crypto |
57 |
readonly QUEUE_ARCHIVE_DIR=$DATA_DIR/queue/archive |
|
30 | 58 |
|
31 | 59 |
in_cluster() { |
32 | 60 |
[[ -e $DATA_DIR/ssconf_master_node ]] |
... | ... | |
56 | 84 |
xargs -r0 rm -vf |
57 | 85 |
} |
58 | 86 |
|
87 |
cleanup_master() { |
|
88 |
# Return if machine is not part of a cluster |
|
89 |
in_cluster || return 0 |
|
90 |
|
|
91 |
# Return if queue archive directory doesn't exist |
|
92 |
[[ -d $QUEUE_ARCHIVE_DIR ]] || return 0 |
|
93 |
|
|
94 |
# Remove old jobs |
|
95 |
find $QUEUE_ARCHIVE_DIR -mindepth 2 -type f -mtime +$REMOVE_AFTER -print0 | \ |
|
96 |
xargs -r0 rm -vf |
|
97 |
} |
|
98 |
|
|
59 | 99 |
# Define how many days archived jobs should be left alone |
60 | 100 |
REMOVE_AFTER=21 |
61 | 101 |
|
... | ... | |
77 | 117 |
find $CLEANER_LOG_DIR -maxdepth 1 -type f | sort | head -n -$KEEP_LOGS | \ |
78 | 118 |
xargs -r rm -vf |
79 | 119 |
|
80 |
cleanup_node |
|
81 |
cleanup_watcher |
|
120 |
case "$1" in |
|
121 |
node) |
|
122 |
cleanup_node |
|
123 |
cleanup_watcher |
|
124 |
;; |
|
125 |
master) |
|
126 |
cleanup_master |
|
127 |
;; |
|
128 |
esac |
|
82 | 129 |
|
83 | 130 |
exit 0 |
Also available in: Unified diff