Update loki playbook

This commit is contained in:
Wojciech Kozlowski 2019-12-14 14:12:35 +01:00
parent 1c8bc92000
commit 2c3c38f106
4 changed files with 69 additions and 28 deletions

View File

@ -0,0 +1,8 @@
[Unit]
Description=Backup Loki server
[Service]
WorkingDirectory={{ loki_dir }}
Type=oneshot
ExecStartPre={{ loki_dir }}/registry-cleaner.sh
ExecStart={{ loki_dir }}/backup.sh -b

View File

@ -0,0 +1,10 @@
[Unit]
Description=Back up Loki once a week
[Timer]
OnCalendar=weekly
AccuracySec=1h
Persistent=true
[Install]
WantedBy=timers.target

View File

@ -3,7 +3,7 @@ Description=Dockerised web server
After=docker.service After=docker.service
[Service] [Service]
WorkingDirectory=/root/Loki WorkingDirectory={{ loki_dir }}
Environment="COMPOSE_HTTP_TIMEOUT=300" Environment="COMPOSE_HTTP_TIMEOUT=300"
ExecStart=/usr/bin/docker-compose up ExecStart=/usr/bin/docker-compose up
ExecStop=/usr/bin/docker-compose down ExecStop=/usr/bin/docker-compose down

View File

@ -6,7 +6,6 @@
vars: vars:
- debian_release: buster - debian_release: buster
- loki_dir: /srv/loki
tasks: tasks:
@ -62,33 +61,19 @@
register: loki_git register: loki_git
- block: - block:
- name: Install Loki service - name: Update
command: cp "{{ loki_dir }}"/loki-server.service /lib/systemd/system/ command: ./update.sh
args:
chdir: "{{ loki_dir }}"
- name: Update service file rescue:
lineinfile: - debug:
path: /lib/systemd/system/loki-server.service msg: "Failed to pull containers from registry - will build locally"
regexp: '^WorkingDirectory='
line: 'WorkingDirectory={{ loki_dir }}'
- name: Reload systemd daemon - name: Build locally
systemd: command: make build-all
daemon_reload: yes args:
chdir: "{{ loki_dir }}"
- block:
- name: Update
command: ./update.sh
args:
chdir: "{{ loki_dir }}"
rescue:
- debug:
msg: "Failed to pull containers from registry - will build locally"
- name: Build locally
command: make build-all
args:
chdir: "{{ loki_dir }}"
when: loki_git is changed when: loki_git is changed
@ -100,8 +85,46 @@
dest: /etc/hosts dest: /etc/hosts
mode: 0644 mode: 0644
- name: Ensure service is started # -------------------------------------------------------------------------
# Loki server service.
# -------------------------------------------------------------------------
- name: Install Loki server
template:
src: ./etc/systemd/system/loki-server.service.j2
dest: /etc/systemd/system/loki-server.service
mode: 0644
- name: Enable and start Loki server
service: service:
name: loki-server name: loki-server
state: started state: started
enabled: yes enabled: yes
# -------------------------------------------------------------------------
# Loki backup service.
# -------------------------------------------------------------------------
- name: Create GitLab credentials file
template:
src: ./gitlab.cred.j2
dest: "{{ loki_dir }}/gitlab.cred"
mode: 0644
- name: Install Loki backup service
template:
src: ./etc/systemd/system/loki-backup.service.j2
dest: /etc/systemd/system/loki-backup.service
mode: 0644
- name: Install Loki backup timer
template:
src: ./etc/systemd/system/loki-backup.timer.j2
dest: /etc/systemd/system/loki-backup.timer
mode: 0644
- name: Enable and start Loki backup
service:
name: loki-backup.timer
state: started
enabled: yes