Skip to content

Commit c229361

Browse files
authored
Merge pull request #31 from galaxyproject/fix-gc
Fix stratum 0/1 garbage collection cron job, use cvmfs_server gc -a
2 parents 99a0c55 + 60dbfbe commit c229361

File tree

4 files changed

+63
-8
lines changed

4 files changed

+63
-8
lines changed

defaults/main.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,42 @@ cvmfs_config_apache: true
4545
# group_names
4646
cvmfs_role: '' # (client, Or stratum1 or stratum0 or localproxy)
4747

48+
# Specify whether `cvmfs_server gc -a` should be run from cron to garbage collect all repos on the server, disable this
49+
# option if your repos don't use CVMFS_AUTO_GC=false.
50+
cvmfs_gc_enabled: true
51+
52+
# Garbage collection log path (directory will be created if necessary). This is the default path but CVMFS packages
53+
# don't precreate the directory for you so `cvmfs_server gc -a` will fail by default.
54+
cvmfs_gc_log: /var/log/cvmfs/gc.log
55+
56+
# User to run garbage collection as. This user must have permission to gc all repositories on the server (i.e. it should
57+
# be `root` if you have repositories owned by multiple users)
58+
cvmfs_gc_user: root
59+
60+
# Specify the options passed to `cvmfs_server gc`. If you override these you will need to include `-a -f` in your value
61+
# or the job will fail
62+
cvmfs_gc_options: "-a -f -L {{ cvmfs_gc_log }}"
63+
64+
# Garbage collection cron job timing, hash keys correspond to the cron module options:
65+
# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/cron_module.html
66+
#
67+
#cvmfs_gc_time:
68+
# special_time:
69+
# hour:
70+
# minute:
71+
# day:
72+
# month:
73+
# weekday:
74+
#
75+
# e.g. for 3 AM nightly:
76+
#cvmfs_gc_time:
77+
# hour: 3
78+
# minute: 0
79+
#
80+
# Use @weekly by default:
81+
cvmfs_gc_time:
82+
special_time: weekly
83+
4884
# Optionally download the preload utility
4985
cvmfs_preload_install: false
5086
cvmfs_preload_path: /usr/bin

tasks/gc.yml

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
---
22

3-
- name: Schedule garbage collection
3+
# gc -a support implemented in 2021/02, this task can be removed at some later date
4+
- name: Remove per-repository garbage collection cron jobs
45
cron:
5-
name: cvmfs_gc_{{ item.1.repository }}
6+
name: cvmfs_gc_{{ item.repository }}
67
cron_file: ansible_cvmfs_gc
7-
user: "{{ item.1.owner | default('root') }}"
8-
job: output=$(/usr/bin/cvmfs_server gc -f -t '1 Jan 1970 00:00:00' {{ item.1.repository }} 2>&1) || echo "$output"
9-
hour: 3
10-
minute: "{{ item.0 }}"
11-
weekday: 3
12-
with_indexed_items: "{{ cvmfs_repositories }}"
8+
state: absent
9+
loop: "{{ cvmfs_repositories }}"
10+
11+
- name: Create garbage collection log directory
12+
file:
13+
path: "{{ cvmfs_gc_log | dirname }}"
14+
state: directory
15+
owner: "{{ cvmfs_gc_user }}"
16+
mode: 0755
17+
18+
- name: Schedule garbage collection
19+
cron:
20+
name: cvmfs_gc_all
21+
cron_file: ansible_cvmfs_gc_all
22+
user: "{{ cvmfs_gc_user }}"
23+
job: /usr/bin/cvmfs_server gc {{ cvmfs_gc_options }}
24+
hour: "{{ cvmfs_gc_time.hour | default(omit) }}"
25+
minute: "{{ cvmfs_gc_time.minute | default(omit) }}"
26+
day: "{{ cvmfs_gc_time.day | default(omit) }}"
27+
month: "{{ cvmfs_gc_time.month | default(omit) }}"
28+
weekday: "{{ cvmfs_gc_time.weekday | default(omit) }}"
29+
special_time: "{{ cvmfs_gc_time.special_time | default(omit) }}"

tasks/stratum0.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,4 @@
8888

8989
- name: Include garbage collection tasks
9090
include_tasks: gc.yml
91+
when: cvmfs_gc_enabled

tasks/stratum1.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114

115115
- name: Include garbage collection tasks
116116
include_tasks: gc.yml
117+
when: cvmfs_gc_enabled
117118

118119
# allow unprivileged users to restart squid
119120
- name: Allow users to manage services

0 commit comments

Comments
 (0)