From f1d32f86b785c7b32b2385899bfb37fce9ce75c1 Mon Sep 17 00:00:00 2001 From: Timo Makinen Date: Wed, 29 May 2019 03:14:46 +0300 Subject: [PATCH] added gunicorn role --- roles/gunicorn/files/gunicorn.service | 16 ++++++++++ roles/gunicorn/files/gunicorn.socket | 11 +++++++ roles/gunicorn/tasks/main.yml | 42 +++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 roles/gunicorn/files/gunicorn.service create mode 100644 roles/gunicorn/files/gunicorn.socket create mode 100644 roles/gunicorn/tasks/main.yml diff --git a/roles/gunicorn/files/gunicorn.service b/roles/gunicorn/files/gunicorn.service new file mode 100644 index 0000000..9ad0e5c --- /dev/null +++ b/roles/gunicorn/files/gunicorn.service @@ -0,0 +1,16 @@ +[Unit] +Description=Gunicorn Service +After=nss-user-lookup-target + +[Service] +PIDFile=/run/gunicorn/%i.pid +User=%i +Group=%i +ExecStart=/usr/bin/gunicorn --pid /run/gunicorn/%i.pid \ + --bind unix:/run/gunicorn/%i.sock %i +ExecReload=/bin/kill -s HUP $MAINPID +ExecStop=/bin/kill -s TERM $MAINPID +PrivateTmp=true + +[Install] +Also=gunicorn@%i.socket diff --git a/roles/gunicorn/files/gunicorn.socket b/roles/gunicorn/files/gunicorn.socket new file mode 100644 index 0000000..8849715 --- /dev/null +++ b/roles/gunicorn/files/gunicorn.socket @@ -0,0 +1,11 @@ +[Unit] +Description=Gunicorn Socket + +[Socket] +ListenStream=/run/gunicorn/gunicorn-%i.sock +RuntimeDirectory=gunicorn +SocketUser=%i +SocketMode=0660 + +[Install] +WantedBy=sockets.target diff --git a/roles/gunicorn/tasks/main.yml b/roles/gunicorn/tasks/main.yml new file mode 100644 index 0000000..e613e34 --- /dev/null +++ b/roles/gunicorn/tasks/main.yml @@ -0,0 +1,42 @@ +--- +- name: create gunicorn group + group: + name: gunicorn + system: true + +- name: install gunicorn packages + package: + name: python-gunicorn + state: installed + +- name: create runtime directory + file: + dest: /run/gunicorn + state: directory + mode: 0770 + owner: root + group: gunicorn + +- name: create tmpfiles config + copy: + dest: /etc/tmpfiles.d/gunicorn.conf + content: "d /run/gunicorn 770 root gunicorn\n" + mode: 0644 + owner: root + group: "{{ ansible_wheel }}" + +- name: create systemd socket template + copy: + dest: /lib/systemd/system/gunicorn@.socket + src: gunicorn.socket + mode: 0644 + owner: root + group: "{{ ansible_wheel }}" + +- name: create systemd service template + copy: + dest: /lib/systemd/system/gunicorn@.service + src: gunicorn.service + mode: 0644 + owner: root + group: "{{ ansible_wheel }}"