Skip to content

Commit 7230987

Browse files
committed
make the document easier for others to follow
1 parent a1a469f commit 7230987

File tree

1 file changed

+69
-32
lines changed

1 file changed

+69
-32
lines changed

ETS website maintenance howto.md

Lines changed: 69 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,24 @@
33

44
# Echothrust Solutions website maintenance HOWTO
55

6-
This is a small howto on how we perform scheduled maintenance on our websites that require a database update or re-import.
6+
This is a small paper on a method we employ in order to perform scheduled maintenance on our web servers.
77

8-
The guide assumes you're running OpenBSD and nginx but the principles can be applied to a variety of applications and services.
8+
The guide assumes you're running `OpenBSD` and `nginx` but the principles can be applied to a variety of applications and services.
9+
10+
The method as its pros and cons but they depend on your own requirements and limitations. In our case we are quite happy with this method and we've been using ever since.
11+
* It allows you to stop the web server for your site completely so you can perform updates. But this comes at the penalty of having to maintain an extra service
12+
* It is fairly simple to "script" and automate
13+
* It assumes that both web services run on the same host, if you dont have this limitation then other methods may be better
14+
15+
## The idea
16+
The idea is as the following:
17+
* Setup two different nginx servers on of them listens on ports 80,443 and the other on localhost:8080 and localhost:8443
18+
* The server listening on localhost, serves a single static html file for every request and returns status 503 for every request
19+
* We setup a pf table called `maintenance` which is initially empty
20+
* We redirect any request from addresses found in `maintenance` towards ports 80 and 443 to our nginx listening on localhost at 8080 and 8443 respectively
21+
* We allow the allow any remaining requests to access the nginx instance listening on our public interface
22+
23+
## Configuration
924

1025
* Configure pf
1126
```
@@ -14,40 +29,62 @@ pass in quick inet proto tcp from <maintenance> to port 80 rdr-to port 8080 labe
1429
pass in quick inet proto tcp from <maintenance> to port 443 rdr-to port 8443 label "www-maintenance"
1530
pass in quick inet proto tcp to port {80,443} label "www-normal"
1631
```
17-
* Configure nginx
18-
```
19-
server {
20-
listen 8080;
21-
listen 8443 ssl;
22-
server_name SERVER_NAME;
23-
root /var/www/maintenance;
24-
25-
# include acme-client.conf;
26-
ssl_certificate /etc/ssl/acme/fullchain.pem;
27-
ssl_certificate_key /etc/ssl/acme/private/privkey.pem;
28-
ssl_session_timeout 5m;
29-
ssl_session_cache shared:SSL:50m;
30-
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
31-
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
32-
ssl_prefer_server_ciphers on;
33-
ssl_dhparam /etc/ssl/private/dhparam.pem;
34-
35-
return 503;
36-
error_page 503 @maintenance;
37-
location @maintenance {
38-
rewrite ^(.*)$ /maintenance.html break;
39-
}
40-
}
41-
```
42-
43-
Now in when you want to add your website under maintenance you can simply do
32+
33+
* Configure nginx that will be used when we are under maintenance, we use `/etc/nginx/maintenance.conf`
34+
```
35+
server {
36+
listen localhost:8080;
37+
listen localhost:8443 ssl;
38+
server_name SERVER_NAME;
39+
root /var/www/maintenance;
40+
41+
ssl_certificate /etc/ssl/acme/fullchain.pem;
42+
ssl_certificate_key /etc/ssl/acme/private/privkey.pem;
43+
ssl_session_timeout 5m;
44+
ssl_session_cache shared:SSL:50m;
45+
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
46+
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
47+
ssl_prefer_server_ciphers on;
48+
ssl_dhparam /etc/ssl/private/dhparam.pem;
49+
50+
return 503;
51+
error_page 503 @maintenance;
52+
53+
location @maintenance {
54+
rewrite ^(.*)$ /maintenance.html break;
55+
}
56+
}
57+
```
58+
59+
* copy the nginx service so that it can be managed indipendently
60+
```sh
61+
cp /etc/rc.d/nginx /etc/rc.d/nginx_maintenance
62+
rcctl enable nginx_maintenance
63+
rcctl set nginx_maintenance flags -c /etc/nginx/maintenance.conf
64+
rcctl start nginx_maintenance
65+
```
66+
Add your `maintenance.html` under `/var/www/html` or any other location you picked and you're good to give it a go.
67+
68+
## Setting your site in maintenance mode
69+
Now in when we want to add our website under maintenance you can simply do
70+
```sh
71+
pfctl -t maintenance -T add 0.0.0.0/0
72+
```
73+
74+
In order to kill any existing connections to the live nginx we use our defined label
4475
```sh
45-
doas pfctl -t maintenance -T add 0.0.0.0/0
46-
doas pfctl -k label -k www-normal # flush existing sessions
76+
pfctl -k label -k www-normal
4777
```
4878

49-
Remove website from maintenance
79+
At this point any request towards our normal webserver should display our nice `maintenance.html`.
80+
81+
## Setting your site back online
82+
In order to finish the maintenance we first have to empty the `maintenance` table
5083
```sh
5184
doas pfctl -t maintenance -T flush
85+
```
86+
87+
And again we kill any existing sessions that are left open at the maintenance nginx
88+
```sh
5289
doas pfctl -k label -k www-maintenance
5390
```

0 commit comments

Comments
 (0)