Skip to content

Commit 5c2372b

Browse files
committed
Add configuration for forwarder service
1 parent b91770e commit 5c2372b

14 files changed

Lines changed: 183 additions & 66 deletions

File tree

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ test: test-debian test-ubuntu test-rocky
2828
test-%: tpod_%
2929
podman run --rm -it \
3030
--hostname service01-test \
31-
-v "$(PWD):/srv/ansible" \
32-
tpod_$* /srv/ansible/test/docker/test.sh
31+
-v "$(PWD):/srv/services" \
32+
tpod_$* /srv/services/test/docker/test.sh
3333

3434

3535
##
@@ -45,7 +45,7 @@ tpod_%:
4545
login-%: tpod_%
4646
podman run --rm -it \
4747
--hostname service01-test \
48-
-v "$(PWD):/srv/ansible" \
48+
-v "$(PWD):/srv/services" \
4949
tpod_$* /bin/bash
5050

5151

README.md

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,17 @@ Recovery Source: Services
44
This repository provides a "standardized" solution to test, deploy, and maintain
55
various web "services" provided by [Recovery Source](https://handbook.recoverysource.net/).
66

7-
Basic Workflows
8-
---------------
9-
10-
To Do ...
11-
127
Repository Structure
138
--------------------
149

15-
The structure of this repository:
10+
Important directories:
1611

17-
- ``Makefile``: Convenient helper tasks
18-
- ``data/``: Primary source of data (all known 12-Step groups)
19-
- ``sync/``: Python3 module that collects and re-mangles data
20-
- ``web_index/``: Hugo-based website that hosts https://sober.page
21-
- ``ansible/``: Used for configuration management (deploy, maintain, etc.)
22-
- ``test/``: Data used for automated testing
12+
- **data**: Source data for all services
13+
- **web_index**: [Directory listing of 12-Step groups](https://sober.page/)
14+
- **nameserver**: Configuration for [DNS](https://handbook.recoverysource.net/essentials/websites.html#domain-name-system) services
15+
- **forwarder**: Configuration for "HTTP Redirector" service
16+
- **sync**: Python module used to synchronize data
17+
- **test**: Data used for automated testing
2318

2419
Web Index
2520
---------
@@ -69,23 +64,7 @@ of feed locations (type+url)
6964
Sync
7065
----
7166

72-
Data synchronization is done using the ``sync`` python module.
73-
74-
**$ cd services && python3 -m sync -h**:
67+
Data synchronization is done using the ``sync`` python module:
7568
```
76-
usage: python3 -m sync [-h] [actions] <options>
77-
78-
Synchronize sober.page data with various destinations
79-
80-
options:
81-
-h, --help show this help message and exit
82-
-H <path> Path to source data (hugo format)
83-
-w <path> Local workspace used for importing/caching data
84-
-l <level> Log level (DEBUG, INFO*, WARNING, ERROR)
85-
86-
actions[*]:
87-
-m <path> Generate nginx map file at <path>
88-
-z <zone>:<path> Generate bind9 zone (db) at <path>
89-
90-
[*] At least one script action must be specified.
69+
$ cd services && python3 -m sync -h
9170
```

ansible/bootstrap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ elif command -v dnf >/dev/null; then
6969
fi
7070

7171
NOTE 'Verify the ansible repository is present'
72-
if [ ! -d /srv/ansible ]; then
73-
git clone -b release https://github.com/recoverysource/services /srv/ansible
72+
if [ ! -d /srv/services ]; then
73+
git clone -b release https://github.com/recoverysource/services /srv/services
7474
fi
7575

7676
NOTE 'Change to ansible directory' # avoids repetitive references
77-
cd /srv/ansible/ansible || exit 1
77+
cd /srv/services/ansible || exit 1
7878

7979
NOTE 'Unpack vault password'
8080
if [ ! -e .vaultpass ]; then

ansible/roles/common/tasks/baseline.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@
7979
- name: Obtain copy of configuration repository
8080
ansible.builtin.git:
8181
repo: https://github.com/recoverysource/services.git
82-
dest: /srv/ansible
82+
dest: /srv/services
8383
update: false # ansible-forced updates will reset local history
8484
version: release
8585

8686
- name: Add self-managed ansible runs to cron
8787
ansible.builtin.cron:
88-
job: "cd /srv/ansible/ansible && git pull && ansible-playbook maintenance.yml"
88+
job: "cd /srv/services/ansible && git pull && ansible-playbook maintenance.yml"
8989
name: ansible-maintenance
9090
special_time: hourly
9191
when: "'test' not in ansible_os_family"
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
- name: Run extra tasks for "service" hosts
2-
ansible.builtin.include_tasks:
3-
file: service.yml
1+
- name: Include name server on (service) hosts
2+
ansible.builtin.include_role:
3+
name: nameserver
4+
when: "'service' in ansible_hostname"
5+
6+
- name: Include forwarding service on (service) hosts
7+
ansible.builtin.include_role:
8+
name: forwarder
49
when: "'service' in ansible_hostname"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
- name: Restart nginx service
2+
listen: restart-nginx
3+
ansible.builtin.service:
4+
name: nginx
5+
state: restarted
6+
7+
- name: Reload nginx service
8+
listen: reload-nginx
9+
ansible.builtin.service:
10+
name: nginx
11+
state: reloaded

ansible/roles/nginx/tasks/main.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
- name: Install nginx package
2+
ansible.builtin.package:
3+
name: nginx
4+
5+
- name: Manage no-tokens.conf
6+
ansible.builtin.copy:
7+
dest: /etc/nginx/conf.d/no-tokens.conf
8+
content: |
9+
server_tokens off;
10+
mode: '0644'
11+
notify: reload-nginx
12+
13+
- name: Manage ssl-settings.conf
14+
ansible.builtin.copy:
15+
dest: /etc/nginx/conf.d/ssl-settings.conf
16+
content: |
17+
ssl_session_cache shared:SSL:10m;
18+
ssl_session_tickets off;
19+
ssl_session_timeout 10m;
20+
ssl_stapling on;
21+
ssl_stapling_verify on;
22+
mode: '0644'
23+
notify: reload-nginx
24+
25+
- name: Manage nginx.conf
26+
ansible.builtin.template:
27+
src: nginx.conf
28+
dest: /etc/nginx/nginx.conf
29+
mode: '0644'
30+
notify: reload-nginx
31+
32+
- name: Remove default site configuration
33+
ansible.builtin.file:
34+
path: /etc/nginx/sites-enabled/default
35+
state: absent
36+
notify: reload-nginx
37+
38+
- name: Ensure service is running
39+
ansible.builtin.service:
40+
name: nginx
41+
state: started
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
user www-data;
2+
worker_processes auto;
3+
pid /run/nginx.pid;
4+
error_log /var/log/nginx/error.log;
5+
include /etc/nginx/modules-enabled/*.conf;
6+
7+
events {
8+
worker_connections 1000;
9+
# multi_accept on;
10+
}
11+
12+
http {
13+
14+
##
15+
# Basic Settings
16+
##
17+
18+
sendfile on;
19+
tcp_nopush on;
20+
tcp_nodelay on;
21+
keepalive_timeout 65;
22+
types_hash_max_size 2048;
23+
# server_tokens off;
24+
etag on;
25+
26+
# server_names_hash_bucket_size 64;
27+
# server_name_in_redirect off;
28+
29+
include /etc/nginx/mime.types;
30+
default_type application/octet-stream;
31+
32+
##
33+
# SSL Settings
34+
##
35+
36+
ssl_protocols TLSv1.2 TLSv1.3;
37+
ssl_prefer_server_ciphers on;
38+
39+
##
40+
# Logging Settings
41+
##
42+
43+
access_log /var/log/nginx/access.log;
44+
45+
##
46+
# Gzip Settings
47+
##
48+
49+
gzip on;
50+
51+
# gzip_vary on;
52+
# gzip_proxied any;
53+
# gzip_comp_level 6;
54+
# gzip_buffers 16 8k;
55+
# gzip_http_version 1.1;
56+
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
57+
58+
##
59+
# Virtual Host Configs
60+
##
61+
62+
#include /etc/nginx/sites-enabled/*;
63+
include /etc/nginx/conf.d/*.conf;
64+
}

forwarder/tasks/main.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
- name: Depends on nginx role
2+
ansible.builtin.include_role:
3+
name: nginx
4+
5+
- name: Manage nginx forwarder configuration
6+
ansible.builtin.copy:
7+
src: nginx_forwarder.conf
8+
dest: /etc/nginx/conf.d/forwarder.conf
9+
notify: reload-nginx
10+
11+
- name: Ensure canonical_redirects.map exists
12+
ansible.builtin.command:
13+
chdir: /srv/service
14+
cmd: python3 -m sync -n /etc/nginx/canonical_redirects.map
15+
creates: /etc/nginx/canonical_redirects.map
16+
notify: reload-nginx
17+
18+
- name: Regularly re-generate canonical_redirects.map
19+
ansible.builtin.cron:
20+
job: "cd /srv/service && python3 -m sync -n /etc/nginx/canonical_redirects.map && service nginx reload"
21+
name: canonical_redirects
22+
special_time: hourly

0 commit comments

Comments
 (0)