From afbaec650def427987e0caf3a9a852a67d046247 Mon Sep 17 00:00:00 2001 From: Thedro Neely Date: Sun, 2 Feb 2020 01:44:51 -0500 Subject: roles/healthchecks: Add --- roles/healthchecks/files/supervisord.conf | 30 ++++++++ roles/healthchecks/main.yml | 120 ++++++++++++++++++++++++++++++ 2 files changed, 150 insertions(+) create mode 100644 roles/healthchecks/files/supervisord.conf create mode 100644 roles/healthchecks/main.yml diff --git a/roles/healthchecks/files/supervisord.conf b/roles/healthchecks/files/supervisord.conf new file mode 100644 index 0000000..52c3c43 --- /dev/null +++ b/roles/healthchecks/files/supervisord.conf @@ -0,0 +1,30 @@ +; Supervisor config file. + +[program:healthchecks] +command=/usr/sbin/uwsgi uwsgi.ini +directory=/opt/%(program_name)s +stopasgroup=true +stdout_logfile=/var/log/%(program_name)s.log +stdout_logfile_maxbytes=0 +stdout_logfile_backups=0 +redirect_stderr=true +user=%(program_name)s + +[inet_http_server] +port = 9100 +username = healthchecks +password = healthchecks + +[unix_http_server] +file=/run/supervisord.sock + +[supervisord] +logfile=/var/log/supervisord.log +loglevel=info +user=root + +[rpcinterface:supervisor] +supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface + +[supervisorctl] +serverurl=unix:///run/supervisord.sock diff --git a/roles/healthchecks/main.yml b/roles/healthchecks/main.yml new file mode 100644 index 0000000..1a0e4b9 --- /dev/null +++ b/roles/healthchecks/main.yml @@ -0,0 +1,120 @@ +--- +# target: alpine3.11 +- name: Install Health Checks + hosts: healthchecks + + vars_files: + - ../variables.yml + + tasks: + + - name: Ensuring group exists + group: + name: "{{ healthchecks_user }}" + state: present + + - name: Creating user and making home directory + user: + system: yes + state: present + name: "{{ healthchecks_user }}" + groups: "{{ healthchecks_user }}" + home: "{{ healthchecks_home }}" + + - name: Installing the required dependencies + apk: + state: present + update_cache: yes + name: + - musl-dev + - postgresql-dev + - python3-dev + - gcc + - git + - supervisor + - sudo + - uwsgi + - uwsgi-python + + - block: + + - name: Cloning repository + git: + repo: "{{ healthchecks_repository }}" + dest: "{{ healthchecks_home }}" + version: "{{ healthchecks_version }}" + + - name: Setting up python virtual environment + shell: python3 -m venv . + args: + chdir: "{{ healthchecks_home }}" + creates: bin/activate + + - name: Pip installing application + shell: | + . bin/activate + pip install -r requirements.txt + args: + chdir: "{{ healthchecks_home }}" + + - name: Migrating database + shell: | + . bin/activate + ./manage.py migrate + args: + chdir: "{{ healthchecks_home }}" + creates: hc.sqlite + + - name: Setting up application assets + blockinfile: + path: "{{ healthchecks_home }}/uwsgi.ini" + block: | + [uwsgi] + http-socket = 0.0.0.0:8000 + enable-threads + plugin = python + virtualenv = /opt/healthchecks + module = hc.wsgi:application + static-map = /static=static-collected + static-gzip-dir = static-collected/CACHE + hook-pre-app = exec:./manage.py collectstatic --noinput + hook-pre-app = exec:./manage.py compress --force + attach-daemon = ./manage.py sendalerts + create: yes + + - name: Setting up application configuration + blockinfile: + path: "{{ healthchecks_home }}/hc/local_settings.py" + block: | + SITE_NAME = "Check" + DEBUG = False + COMPRESS_ENABLED = True + REGISTRATION_OPEN = False + SECRET = "{{ secret_key }}" + create: yes + + become: true + become_user: "{{ healthchecks_user }}" + + - name: Copying supervisord config file + copy: + src: supervisord.conf + dest: /etc/supervisord.conf + mode: '0644' + register: supervisorConfig + + - name: Ensuring supervisord has been started and enabled + service: + name: supervisord + state: started + enabled: yes + + - name: Waiting for supervisor to become active + wait_for: + port: 9100 + + - name: Restarting supervisord due to config change + service: + name: supervisord + state: restarted + when: supervisorConfig.changed -- cgit v1.2.3