Skip to content
Snippets Groups Projects
Commit 7b642c49 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

ganeti-cleaner: Remove old watcher state files


Watcher state files can stay around if node groups are removed. With
this patch they're removed after 21 days.

Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 173dbf05
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
#
# Copyright (C) 2009, 2010 Google Inc.
# Copyright (C) 2009, 2010, 2011 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -20,9 +20,13 @@
set -e
in_cluster() {
[[ -e $DATA_DIR/ssconf_master_node ]]
}
cleanup_master() {
# Return if machine is not part of a cluster
[[ -e $DATA_DIR/ssconf_master_node ]] || return 0
in_cluster || return 0
# Return if queue archive directory doesn't exist
[[ -d $QUEUE_ARCHIVE_DIR ]] || return 0
......@@ -45,6 +49,16 @@ cleanup_node() {
done
}
cleanup_watcher() {
# Return if machine is not part of a cluster
in_cluster || return 0
# Remove old watcher files
find $DATA_DIR -maxdepth 1 -type f -mtime +$REMOVE_AFTER \
-name 'watcher.*-*-*-*.data' -print0 | \
xargs -r0 rm -vf
}
# Overridden by unittest
: ${LOCALSTATEDIR:=@LOCALSTATEDIR@}
: ${CHECK_CERT_EXPIRED:=@PKGLIBDIR@/check-cert-expired}
......@@ -77,5 +91,6 @@ xargs -r rm -vf
cleanup_master
cleanup_node
cleanup_watcher
exit 0
......@@ -55,6 +55,13 @@ count_jobs() {
[[ "$count" -eq "$n" ]] || err "Found $count jobs instead of $n"
}
count_watcher() {
local n=$1
local count=$(find $watcherdir -maxdepth 1 -type f \
-name 'watcher.*.data' | wc -l)
[[ "$count" -eq "$n" ]] || err "Found $count watcher files instead of $n"
}
count_and_check_certs() {
local n=$1
local count=$(find $cryptodir -mindepth 1 -type f -name cert | wc -l)
......@@ -97,6 +104,28 @@ create_archived_jobs() {
done
}
create_watcher_state() {
local uuids=(
6792a0d5-f8b6-4531-8d8c-3680c86b8a53
ab74da37-f5f7-44c4-83ad-074159772593
fced2e48-ffff-43ae-919e-2b77d37ecafa
6e89ac57-2eb1-4a16-85a1-94daa815d643
8714e8f5-59c4-47db-b2cb-196ec37978e5
91763d73-e1f3-47c7-a735-57025d4e2a7d
e27d3ff8-9546-4e86-86a4-04151223e140
aa3f63dd-be17-4ac8-bd01-d71790e124cb
05b6d7e2-003b-40d9-a6d6-ab61bf123a15
54c93e4c-61fe-40de-b47e-2a8e6c805d02
)
i=0
for uuid in ${uuids[@]}; do
touch -d "$(( 5 * i )) days ago" $watcherdir/watcher.$uuid.data
let ++i
done
}
create_certdirs() {
local cert=$1; shift
local certdir
......@@ -117,6 +146,7 @@ trap "rm -rf $tmpdir" EXIT
tmpls=$tmpdir/var
queuedir=$tmpls/lib/ganeti/queue
cryptodir=$tmpls/run/ganeti/crypto
watcherdir=$tmpls/lib/ganeti
mkdir -p $tmpls/{lib,log,run}/ganeti $queuedir/archive $cryptodir
......@@ -165,4 +195,10 @@ count_and_check_certs 5
check_logfiles $maxlog
count_jobs 31
upto 'Watcher status files'
create_watcher_state
count_watcher 10
run_cleaner
count_watcher 5
exit 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment