improve upgrade and update to 7.0.5 (#49)

See Disroot/Disroot-Project#920

@muppeth I've just have a question about why you restart forgejo with:

```
- name: '[UPGRADE] - Restart forgejo'
  systemd:
    name: forgejo
    state: restarted
  when:
    - forgejo_is_installed.rc == 0
    - forgejo_health is defined and forgejo_health.rc is defined and forgejo_health.rc == 0

- name: '[UPGRADE] - Wait for forgejo to be back online'
  pause:
    seconds: 10
  when:
    - forgejo_is_installed.rc == 0
    - forgejo_health is defined and forgejo_health.rc is defined and forgejo_health.rc == 0
```

does forgejo need to be up to run `forgejo manager flush-queues` ?  I'm asking coz we stop forgejo just after flush.

Reviewed-on: #49
Reviewed-by: muppeth <muppeth@no-reply@disroot.org>
Co-authored-by: meaz <meaz@disroot.org>
Co-committed-by: meaz <meaz@disroot.org>
This commit is contained in:
meaz 2024-07-15 18:36:23 +02:00 committed by meaz
parent 538d530f51
commit 4690ef208e
3 changed files with 35 additions and 26 deletions

View file

@ -7,7 +7,7 @@ forgejo_group: 'git'
forgejo_confdir: '/etc/forgejo/app.ini'
forgejo_dump_path: '/srv/forgejo-dump'
forgejo_flavor: 'forgejo'
forgejo_version: '7.0.4'
forgejo_version: '7.0.5'
#forgejo_version: '1.21.7-0'
forgejo_arch: 'linux-amd64'
#forgejo_download_url: 'https://github.com/go-gitea/gitea/releases/download/v{{ forgejo_version }}/gitea-{{ forgejo_version }}-{{ forgejo_arch }}'
@ -49,7 +49,7 @@ forgejo_database_config:
- 'SSL_MODE = disable'
forgejo_repository_config:
- 'ROOT = /home/git/forgejo-repositories'
- 'ROOT = {{ forgejo_lib_dir }}/gitea-repositories'
forgejo_server_config:
- 'SSH_DOMAIN = git.example.org'

View file

@ -4,3 +4,8 @@
systemd:
name: forgejo
state: restarted
- name: 'Stop forgejo'
systemd:
name: forgejo
state: stopped

View file

@ -16,17 +16,30 @@
forgejo_download_url: '{{ forgejo_url.stdout }}'
when: forgejo_flavor == 'forgejo'
- name: '[INSTALL] - Check if forgejo is installed'
- name: '[INSTALL] - Check if forgejo is already installed'
shell:
cmd: '{{ forgejo_bindir }}/forgejo --version -c {{ forgejo_confdir }}'
register: forgejo_is_installed
ignore_errors: true # needed when forgejo is not yet installed
- name: '[UPGRADE] - Check forgejo health'
# The following task is needed for the doctor check task, as `gitea-repositories` needs to exist,
# but is created only when the first user creates a repo # so doctor gives an error on first installation
# and on other installation if no user has created any repo yet.
# It also allows to make sure forgejo was installed and used.
- name: '[INSTALL] - Check gitea-repositories exists'
stat:
path: "{{ forgejo_lib_dir }}/gitea-repositories"
register: gitea_repositories
- name: '[UPGRADE] - Check forgejo health with doctor before updating'
shell:
cmd: '{{ forgejo_bindir }}/forgejo doctor check --all -c {{ forgejo_confdir }}'
become: 'yes'
become_user: '{{ forgejo_user }}'
register: forgejo_health
when:
- forgejo_is_installed.rc == 0
- gitea_repositories.stat.exists
- name: '[UPGRADE] - Restart forgejo'
systemd:
@ -34,11 +47,14 @@
state: restarted
when:
- forgejo_is_installed.rc == 0
- forgejo_health.rc == 0
- forgejo_health is defined and forgejo_health.rc is defined and forgejo_health.rc == 0
- name: '[UPGRADE] - Wait for forgejo to be back online'
pause:
seconds: 10
when:
- forgejo_is_installed.rc == 0
- forgejo_health is defined and forgejo_health.rc is defined and forgejo_health.rc == 0
- name: '[UPGRADE] - Flush all queues'
shell:
@ -47,7 +63,7 @@
become_user: '{{ forgejo_user }}'
when:
- forgejo_is_installed.rc == 0
- forgejo_health.rc == 0
- forgejo_health is defined and forgejo_health.rc is defined and forgejo_health.rc == 0
- name: '[UPGRADE] - Stop forgejo'
systemd:
@ -55,8 +71,7 @@
state: stopped
when:
- forgejo_is_installed.rc == 0
- forgejo_health.rc == 0
- forgejo_health is defined and forgejo_health.rc is defined and forgejo_health.rc == 0
- name: '[INSTALL] - Download forgejo binary'
get_url:
@ -67,7 +82,6 @@
group: '{{ forgejo_group }}'
force: 'yes'
notify: 'Restart forgejo'
- name: '[INSTALL] - Set /etc/forgejo rights to read-only'
file:
@ -79,31 +93,21 @@
path: '/etc/forgejo/app.ini'
mode: '0640'
- name: '[UPGRADE] - Start forgejo'
systemd:
name: forgejo
state: started
when:
- forgejo_is_installed.rc == 0
- forgejo_health.rc == 0
- name: '[UPGRADE] - Check forgejo health'
- name: '[UPGRADE] - Check forgejo health after upgrading'
shell:
cmd: '{{ forgejo_bindir }}/forgejo doctor check --all -c {{ forgejo_confdir }}'
become: 'yes'
become_user: '{{ forgejo_user }}'
register: forgejo_health
- name: '[UPGRADE] - Stop forgejo. Something is wrong'
systemd:
name: forgejo
state: started
when:
- forgejo_health.rc != 0
when:
- forgejo_is_installed.rc == 0
- gitea_repositories.stat.exists
- name: '[UPGRADE] - Display problem message'
fail:
msg: 'Forgejo doctor detected issues after upgrade task. Please check the instance manually and fix issues before continuing'
when:
- forgejo_health.rc != 0
- forgejo_is_installed.rc == 0
- forgejo_health is defined and forgejo_health.rc is defined and forgejo_health.rc != 0
notify: 'Stop forgejo'