root / daemons / ganeti-master-cleaner.in @ 2958c56e
History | View | Annotate | Download (1.8 kB)
1 |
#!/bin/bash |
---|---|
2 |
# |
3 |
|
4 |
# Copyright (C) 2009, 2010, 2011, 2012 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 -u |
22 |
|
23 |
@SHELL_ENV_INIT@ |
24 |
|
25 |
readonly CLEANER_LOG_DIR=$LOG_DIR/master-cleaner |
26 |
readonly QUEUE_ARCHIVE_DIR=$DATA_DIR/queue/archive |
27 |
|
28 |
in_cluster() { |
29 |
[[ -e $DATA_DIR/ssconf_master_node ]] |
30 |
} |
31 |
|
32 |
cleanup_master() { |
33 |
# Return if machine is not part of a cluster |
34 |
in_cluster || return 0 |
35 |
|
36 |
# Return if queue archive directory doesn't exist |
37 |
[[ -d $QUEUE_ARCHIVE_DIR ]] || return 0 |
38 |
|
39 |
# Remove old jobs |
40 |
find $QUEUE_ARCHIVE_DIR -mindepth 2 -type f -mtime +$REMOVE_AFTER -print0 | \ |
41 |
xargs -r0 rm -vf |
42 |
} |
43 |
|
44 |
# Define how many days archived jobs should be left alone |
45 |
REMOVE_AFTER=21 |
46 |
|
47 |
# Define how many log files to keep around (usually one per day) |
48 |
KEEP_LOGS=50 |
49 |
|
50 |
# Log file for this run |
51 |
LOG_FILE=$CLEANER_LOG_DIR/cleaner-$(date +'%Y-%m-%dT%H_%M').$$.log |
52 |
|
53 |
# Create log directory |
54 |
mkdir -p $CLEANER_LOG_DIR |
55 |
|
56 |
# Redirect all output to log file |
57 |
exec >>$LOG_FILE 2>&1 |
58 |
|
59 |
echo "Cleaner started at $(date)" |
60 |
|
61 |
# Remove old cleaner log files |
62 |
find $CLEANER_LOG_DIR -maxdepth 1 -type f | sort | head -n -$KEEP_LOGS | \ |
63 |
xargs -r rm -vf |
64 |
|
65 |
cleanup_master |
66 |
|
67 |
exit 0 |