Skip to content
This repository was archived by the owner on Oct 7, 2025. It is now read-only.

Commit b2f8bac

Browse files
authored
Merge pull request #2627 from codeenigma/Gitlab-letsencrypt-hook-PR-2.x
Gitlab-letsencrypt-hook
2 parents 42e089c + fa268bf commit b2f8bac

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

roles/debian/gitlab/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ gitlab:
4545
unicorn_worker_processes: 2
4646
puma_worker_processes: 2
4747
initial_root_password: "Ch@ng3m3"
48+
letsencrypt_timer: false
4849
# LDAP settings
4950
ldap:
5051
enable: false # enable/disable LDAP integration

roles/debian/gitlab/tasks/main.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,46 @@
138138
timer_OnCalendar: "{{ gitlab.block_removed_ldap_users_on_calendar }}"
139139
when: gitlab.ldap.enable
140140

141+
# Set up LE renewal timer and service on boot for servers that are shut down overnight.
142+
143+
- name: Check if GitLab is installed
144+
ansible.builtin.stat:
145+
path: /opt/gitlab/bin/gitlab-ctl
146+
register: gitlab_ctl_binary
147+
148+
- name: Configure GitLab LE boot-time renewal timer
149+
when:
150+
- gitlab.letsencrypt_timer
151+
- gitlab_ctl_binary.stat.exists
152+
block:
153+
- name: Install systemd service for LE renewal
154+
ansible.builtin.template:
155+
src: gitlab-renew-le.service.j2
156+
dest: /etc/systemd/system/gitlab-renew-le.service
157+
owner: root
158+
group: root
159+
mode: '0644'
160+
161+
- name: Install systemd timer for LE renewal
162+
ansible.builtin.template:
163+
src: gitlab-renew-le.timer.j2
164+
dest: /etc/systemd/system/gitlab-renew-le.timer
165+
owner: root
166+
group: root
167+
mode: '0644'
168+
169+
- name: Reload systemd daemon
170+
ansible.builtin.systemd_service:
171+
daemon_reload: true
172+
when: is_local is not defined or not is_local
173+
174+
- name: Enable and start the LE renewal timer
175+
ansible.builtin.systemd:
176+
name: gitlab-renew-le.timer
177+
enabled: true
178+
state: started
179+
when: is_local is not defined or not is_local
180+
141181
# @TODO - this task fails in CI with GitHub Actions because PostGreSQL isn't running
142182
- name: Run the GitLab configuration script for config that cannot be set in gitlab.rb.
143183
ansible.builtin.command: /opt/gitlab/bin/gitlab-rails runner /etc/gitlab/gitlab-config.rb
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[Unit]
2+
Description=Force GitLab LE Cert Renewal at Boot
3+
After=network.target
4+
5+
[Service]
6+
ExecStart=/opt/gitlab/bin/gitlab-ctl renew-le-certs
7+
Type=oneshot
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[Unit]
2+
Description=Run GitLab LE Renewal at Boot
3+
4+
[Timer]
5+
OnBootSec=5min
6+
Unit=gitlab-renew-le.service
7+
8+
[Install]
9+
WantedBy=timers.target

0 commit comments

Comments
 (0)