Skip to content

Commit

Permalink
Merge branch 'uwsgi-systemd'
Browse files Browse the repository at this point in the history
  • Loading branch information
tsibley committed Jul 15, 2021
2 parents e2c73fa + e143b36 commit 0ad27a0
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 42 deletions.
14 changes: 4 additions & 10 deletions backoffice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
become: true
vars:
app_user: ubuntu
uwsgi_apps:
- api-production
- api-testing
- husky-musher

tasks:
- import_tasks: tasks/apt-update.yaml
Expand All @@ -29,16 +33,6 @@
name: prometheus
state: reloaded

- name: uwsgi is restarted
service:
name: uwsgi
state: restarted

- name: uwsgi is reloaded
service:
name: uwsgi
state: reloaded

- name: promtail is restarted
service:
name: promtail
Expand Down
4 changes: 2 additions & 2 deletions files/etc/systemd/system/[email protected]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Unit]
Description=Prometheus uWSGI exporter for %i
After=uwsgi.service
BindsTo=uwsgi.service
After=uwsgi@%i.service
BindsTo=uwsgi@%i.service

[Service]
User=prometheus
Expand Down
25 changes: 25 additions & 0 deletions files/etc/systemd/system/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[Unit]
Description=uWSGI server for %i app
Before=multi-user.target
Before=graphical.target
After=remote-fs.target
After=network-online.target
Wants=network-online.target
Wants=prometheus-uwsgi-exporter@%i.service

[Service]
ExecStart=/usr/bin/uwsgi --ini /etc/uwsgi/base.ini --ini /etc/uwsgi/apps-available/%i.ini
ExecReload=/bin/kill -HUP $MAINPID
RuntimeDirectory=uwsgi/app/%i
# Newer versions of systemd export RUNTIME_DIRECTORY automatically, but not the
# version we have.
Environment=RUNTIME_DIRECTORY=%t/uwsgi/app/%i
User=www-data
Group=www-data
Restart=on-failure
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all

[Install]
WantedBy=default.target
2 changes: 2 additions & 0 deletions files/etc/uwsgi/apps-available/api-production.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[uwsgi]
ini = /opt/backoffice/id3c-production/uwsgi.ini
2 changes: 2 additions & 0 deletions files/etc/uwsgi/apps-available/api-testing.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[uwsgi]
ini = /opt/backoffice/id3c-testing/uwsgi.ini
2 changes: 2 additions & 0 deletions files/etc/uwsgi/apps-available/husky-musher.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[uwsgi]
ini = /opt/backoffice/husky-musher/uwsgi.ini
22 changes: 22 additions & 0 deletions files/etc/uwsgi/base.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Originally based on the Ubuntu defaults in /usr/share/uwsgi/conf/default.ini.
# Expects to be run under the systemd [email protected] template.
[uwsgi]
# try to autoload appropriate plugin if "unknown" option has been specified
autoload = true

# enable main process manager
master = true

# start a couple worker/child processes by default
processes = 2

# automatically stop child procs when the main proc goes away
no-orphans = true

# app and stats sockets
socket = $(RUNTIME_DIRECTORY)/socket
stats = $(RUNTIME_DIRECTORY)/stats
chmod-socket = 660

# place timestamps into log
log-date = true
42 changes: 12 additions & 30 deletions tasks/uwsgi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,23 @@
- uwsgi
- uwsgi-plugin-python3

- name: uwsgi is enabled
service:
name: uwsgi
enabled: yes
state: started

- name: uwsgi base config exists
copy:
remote_src: true
src: /usr/share/uwsgi/conf/default.ini
src: files/etc/uwsgi/base.ini
dest: /etc/uwsgi/base.ini
force: no
backup: yes

- name: uwsgi base config enables stats
community.general.ini_file:
path: /etc/uwsgi/base.ini
section: uwsgi
option: stats
# See the comments in /etc/uwsgi/base.ini (as copied from the original
# source above) for where these %(…) substitutions come from.
value: /run/uwsgi/%(deb-confnamespace)/%(deb-confname)/stats
backup: yes
notify:
- uwsgi is reloaded
owner: root
group: root
mode: ugo=r

- name: uwsgi default invocation is configured
lineinfile:
path: /etc/default/uwsgi
regexp: '^INHERITED_CONFIG='
line: 'INHERITED_CONFIG=/etc/uwsgi/base.ini'
notify:
# Restart not reload since the actual options used to invoke uWSGI changed,
# not just the contents of its config files.
- uwsgi is restarted
- name: uwsgi app configs exists
loop: "{{ uwsgi_apps }}"
copy:
src: "files/etc/uwsgi/apps-available/{{ item }}.ini"
dest: /etc/uwsgi/apps-available/
owner: root
group: root
mode: ugo=r

- name: uwsgi app logs readable by adm group
file:
Expand Down

0 comments on commit 0ad27a0

Please sign in to comment.