Statistics
| Branch: | Tag: | Revision:

root / daemons / ganeti-cleaner.in @ d72ff6c3

History | View | Annotate | Download (2.2 kB)

1
#!/bin/bash
2
#
3

    
4
# Copyright (C) 2009, 2010 Google Inc.
5
#
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
# General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
# 02110-1301, USA.
20

    
21
set -e
22

    
23
cleanup_master() {
24
  # Return if machine is not part of a cluster
25
  [[ -e $DATA_DIR/ssconf_master_node ]] || return 0
26

    
27
  # Return if queue archive directory doesn't exist
28
  [[ -d $QUEUE_ARCHIVE_DIR ]] || return 0
29

    
30
  # Remove old jobs
31
  find $QUEUE_ARCHIVE_DIR -mindepth 2 -type f -mtime +$REMOVE_AFTER -print0 | \
32
  xargs -r0 rm -vf
33
}
34

    
35
cleanup_node() {
36
  # Return if directory for crypto keys doesn't exist
37
  [[ -d $CRYPTO_DIR ]] || return 0
38

    
39
  find $CRYPTO_DIR -mindepth 1 -maxdepth 1 -type d | \
40
  while read dir; do
41
    if $CHECK_CERT_EXPIRED $dir/cert; then
42
      rm -vf $dir/{cert,key}
43
      rmdir -v --ignore-fail-on-non-empty $dir
44
    fi
45
  done
46
}
47

    
48
# Overridden by unittest
49
: ${LOCALSTATEDIR:=@LOCALSTATEDIR@}
50
: ${CHECK_CERT_EXPIRED:=@PKGLIBDIR@/check-cert-expired}
51

    
52
DATA_DIR=$LOCALSTATEDIR/lib/ganeti
53
CLEANER_LOG_DIR=$LOCALSTATEDIR/log/ganeti/cleaner
54
QUEUE_ARCHIVE_DIR=$DATA_DIR/queue/archive
55
CRYPTO_DIR=$LOCALSTATEDIR/run/ganeti/crypto
56

    
57
# Define how many days archived jobs should be left alone
58
REMOVE_AFTER=21
59

    
60
# Define how many log files to keep around (usually one per day)
61
KEEP_LOGS=50
62

    
63
# Log file for this run
64
LOG_FILE=$CLEANER_LOG_DIR/cleaner-$(date +'%Y-%m-%dT%H_%M').$$.log
65

    
66
# Create log directory
67
mkdir -p $CLEANER_LOG_DIR
68

    
69
# Redirect all output to log file
70
exec >>$LOG_FILE 2>&1
71

    
72
echo "Cleaner started at $(date)"
73

    
74
# Remove old cleaner log files
75
find $CLEANER_LOG_DIR -maxdepth 1 -type f | sort | head -n -$KEEP_LOGS | \
76
xargs -r rm -vf
77

    
78
cleanup_master
79
cleanup_node
80

    
81
exit 0