Skip to content

Commit 0ad27a0

Browse files
committed
Merge branch 'uwsgi-systemd'
2 parents e2c73fa + e143b36 commit 0ad27a0

File tree

8 files changed

+71
-42
lines changed

8 files changed

+71
-42
lines changed

Diff for: backoffice.yaml

+4-10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
become: true
66
vars:
77
app_user: ubuntu
8+
uwsgi_apps:
9+
- api-production
10+
- api-testing
11+
- husky-musher
812

913
tasks:
1014
- import_tasks: tasks/apt-update.yaml
@@ -29,16 +33,6 @@
2933
name: prometheus
3034
state: reloaded
3135

32-
- name: uwsgi is restarted
33-
service:
34-
name: uwsgi
35-
state: restarted
36-
37-
- name: uwsgi is reloaded
38-
service:
39-
name: uwsgi
40-
state: reloaded
41-
4236
- name: promtail is restarted
4337
service:
4438
name: promtail

Diff for: files/etc/systemd/system/[email protected]

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[Unit]
22
Description=Prometheus uWSGI exporter for %i
3-
After=uwsgi.service
4-
BindsTo=uwsgi.service
3+
After=uwsgi@%i.service
4+
BindsTo=uwsgi@%i.service
55

66
[Service]
77
User=prometheus

Diff for: files/etc/systemd/system/[email protected]

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[Unit]
2+
Description=uWSGI server for %i app
3+
Before=multi-user.target
4+
Before=graphical.target
5+
After=remote-fs.target
6+
After=network-online.target
7+
Wants=network-online.target
8+
Wants=prometheus-uwsgi-exporter@%i.service
9+
10+
[Service]
11+
ExecStart=/usr/bin/uwsgi --ini /etc/uwsgi/base.ini --ini /etc/uwsgi/apps-available/%i.ini
12+
ExecReload=/bin/kill -HUP $MAINPID
13+
RuntimeDirectory=uwsgi/app/%i
14+
# Newer versions of systemd export RUNTIME_DIRECTORY automatically, but not the
15+
# version we have.
16+
Environment=RUNTIME_DIRECTORY=%t/uwsgi/app/%i
17+
User=www-data
18+
Group=www-data
19+
Restart=on-failure
20+
KillSignal=SIGQUIT
21+
Type=notify
22+
NotifyAccess=all
23+
24+
[Install]
25+
WantedBy=default.target

Diff for: files/etc/uwsgi/apps-available/api-production.ini

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[uwsgi]
2+
ini = /opt/backoffice/id3c-production/uwsgi.ini

Diff for: files/etc/uwsgi/apps-available/api-testing.ini

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[uwsgi]
2+
ini = /opt/backoffice/id3c-testing/uwsgi.ini

Diff for: files/etc/uwsgi/apps-available/husky-musher.ini

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[uwsgi]
2+
ini = /opt/backoffice/husky-musher/uwsgi.ini

Diff for: files/etc/uwsgi/base.ini

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Originally based on the Ubuntu defaults in /usr/share/uwsgi/conf/default.ini.
2+
# Expects to be run under the systemd [email protected] template.
3+
[uwsgi]
4+
# try to autoload appropriate plugin if "unknown" option has been specified
5+
autoload = true
6+
7+
# enable main process manager
8+
master = true
9+
10+
# start a couple worker/child processes by default
11+
processes = 2
12+
13+
# automatically stop child procs when the main proc goes away
14+
no-orphans = true
15+
16+
# app and stats sockets
17+
socket = $(RUNTIME_DIRECTORY)/socket
18+
stats = $(RUNTIME_DIRECTORY)/stats
19+
chmod-socket = 660
20+
21+
# place timestamps into log
22+
log-date = true

Diff for: tasks/uwsgi.yaml

+12-30
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,23 @@
55
- uwsgi
66
- uwsgi-plugin-python3
77

8-
- name: uwsgi is enabled
9-
service:
10-
name: uwsgi
11-
enabled: yes
12-
state: started
138

149
- name: uwsgi base config exists
1510
copy:
16-
remote_src: true
17-
src: /usr/share/uwsgi/conf/default.ini
11+
src: files/etc/uwsgi/base.ini
1812
dest: /etc/uwsgi/base.ini
19-
force: no
20-
backup: yes
21-
22-
- name: uwsgi base config enables stats
23-
community.general.ini_file:
24-
path: /etc/uwsgi/base.ini
25-
section: uwsgi
26-
option: stats
27-
# See the comments in /etc/uwsgi/base.ini (as copied from the original
28-
# source above) for where these %(…) substitutions come from.
29-
value: /run/uwsgi/%(deb-confnamespace)/%(deb-confname)/stats
30-
backup: yes
31-
notify:
32-
- uwsgi is reloaded
13+
owner: root
14+
group: root
15+
mode: ugo=r
3316

34-
- name: uwsgi default invocation is configured
35-
lineinfile:
36-
path: /etc/default/uwsgi
37-
regexp: '^INHERITED_CONFIG='
38-
line: 'INHERITED_CONFIG=/etc/uwsgi/base.ini'
39-
notify:
40-
# Restart not reload since the actual options used to invoke uWSGI changed,
41-
# not just the contents of its config files.
42-
- uwsgi is restarted
17+
- name: uwsgi app configs exists
18+
loop: "{{ uwsgi_apps }}"
19+
copy:
20+
src: "files/etc/uwsgi/apps-available/{{ item }}.ini"
21+
dest: /etc/uwsgi/apps-available/
22+
owner: root
23+
group: root
24+
mode: ugo=r
4325

4426
- name: uwsgi app logs readable by adm group
4527
file:

0 commit comments

Comments
 (0)