summaryrefslogtreecommitdiff
path: root/bin/trove-gc
blob: 82545f55a37c5345fdf6678b5c6e46243f146c25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/sh
#
# Trove garbage collection script
#
# Copyright (C) 2014  Codethink Limited
#
# 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
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

# This is a rudimentary garbage collector for Trove instances. It wraps the
# `morph gc` command.
#
# Artifacts older than 1 week will be deleted, and artifacts less than 1 day
# old will not be. Age is calculated from mtime, which is set at the time the
# artifact is uploaded to the cache and after that is not updated by any Trove
# components.
#
# Morph's default `cachedir-min-space` value is taken as the amount of space
# to free. Pass --cachedir-min-space to this command to specify your own value.
#
# `morph gc` is designed for running on build machines so it expects there to
# be a tempdir. A harmless side-effect of this script is that you'll get some
# pointless directories created in /tmp/trove-gc-fake-tempdir.
#
# The 'remove all artifacts older than xx' rule is effectively disabled, to
# prevent artifacts that are still needed but do not change often (such as
# stage1 and stage2 of the bootstrap) from being automatically deleted. Those
# artifacts will still be first to be removed in a low disk space condition,
# which is an unfortunate consequence of the simple heuristic we are using
# right now.

set -eu

/usr/bin/morph gc --no-default-config \
    --cachedir=/home/cache \
    --cachedir-artifact-delete-older-than=31557600000 \
    --cachedir-artifact-keep-younger-than=86400 \
    --tempdir=/tmp/trove-gc-fake-tempdir \
    --tempdir-min-space=0M \
    "$@"