Revision f6781abf daemons/ganeti-cleaner.in
b/daemons/ganeti-cleaner.in | ||
---|---|---|
20 | 20 |
|
21 | 21 |
set -e |
22 | 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 |
|
|
23 | 35 |
DATA_DIR=@LOCALSTATEDIR@/lib/ganeti |
36 |
CLEANER_LOG_DIR=@LOCALSTATEDIR@/log/ganeti/cleaner |
|
24 | 37 |
QUEUE_ARCHIVE_DIR=$DATA_DIR/queue/archive |
25 | 38 |
|
26 | 39 |
# Define how many days archived jobs should be left alone |
27 | 40 |
REMOVE_AFTER=21 |
28 | 41 |
|
29 |
# Exit if machine is not part of a cluster |
|
30 |
[[ -e $DATA_DIR/ssconf_master_node ]] || exit 0 |
|
42 |
# Define how many log files to keep around (usually one per day) |
|
43 |
KEEP_LOGS=50 |
|
44 |
|
|
45 |
# Log file for this run |
|
46 |
LOG_FILE=$CLEANER_LOG_DIR/cleaner-$(date +'%Y-%m-%dT%H_%M').$$.log |
|
47 |
|
|
48 |
# Create log directory |
|
49 |
mkdir -p $CLEANER_LOG_DIR |
|
50 |
|
|
51 |
# Redirect all output to log file |
|
52 |
exec >>$LOG_FILE 2>&1 |
|
53 |
|
|
54 |
echo "Cleaner started at $(date)" |
|
31 | 55 |
|
32 |
# Exit if queue archive directory doesn't exist |
|
33 |
[[ -d $QUEUE_ARCHIVE_DIR ]] || exit 0 |
|
56 |
# Remove old cleaner log files |
|
57 |
find $CLEANER_LOG_DIR -maxdepth 1 -type f | sort | head -n -$KEEP_LOGS | \ |
|
58 |
xargs -r rm -vf |
|
34 | 59 |
|
35 |
# Remove old jobs |
|
36 |
find $QUEUE_ARCHIVE_DIR -mindepth 2 -type f -mtime +$REMOVE_AFTER -print0 | \ |
|
37 |
xargs -r0 rm -f |
|
60 |
cleanup_master |
|
38 | 61 |
|
39 | 62 |
exit 0 |
Also available in: Unified diff