···28282929### Production deployment on Ubuntu (and similar systems) [WIP]
30303131-```sh
3232-# create group for service socket access
3333-sudo addgroup millipds-sock
3434-3535-# create unprivileged user
3636-sudo adduser --system --shell /bin/false --home /opt/millipds millipds
3737-3838-# add the user to the group (leaving its primary group as the default)
3939-sudo usermod -aG millipds-sock millipds
4040-4141-# start a shell session under the new user
4242-sudo -u millipds -s
4343-4444-# all commands below this point are run as the millipds user
4545-4646-# create a virtualenv (maybe this will prove unnecessary, but it probably doesn't hurt)
4747-python3 -m venv ~/.venv
4848-4949-# activate the virtualenv (this must be re-run every time you want to use it)
5050-source ~/.venv/bin/activate
5151-5252-# all commands below this point are run inside the virtualenv
5353-5454-# upgrade pip (maybe optional, again, probably doesn't hurt)
5555-python3 -m pip install --upgrade pip
5656-5757-# install millipds
5858-python3 -m pip install --upgrade millipds@git+https://github.com/DavidBuchanan314/millipds
5959-```
6060-6161-Upgrading:
6262-6363-```sh
6464-sudo -u millipds -s
6565-source ~/.venv/bin/activate
6666-python3 -m pip install --upgrade --force-reinstall --no-cache-dir millipds@git+https://github.com/DavidBuchanan314/millipds
6767-exit
6868-sudo systemctl restart millipds
6969-```
7070-7171-Create a systemd service
7272-7373-```
7474-[Unit]
7575-Description=millipds
7676-After=network.target
7777-7878-[Service]
7979-Type=simple
8080-Restart=on-failure
8181-User=millipds
8282-WorkingDirectory=/opt/millipds
8383-ExecStart=/opt/millipds/.venv/bin/millipds run --sock_path=/run/millipds/millipds.sock
8484-RuntimeDirectory=millipds
8585-8686-[Install]
8787-WantedBy=multi-user.target
8888-```
8989-9090-TODO: put this file in the repo so it can be copied into place more easily.
9191-9292-Put this in `/etc/systemd/system/millipds.service`
9393-9494-Create a new nginx config:
9595-```
9696-upstream millipds {
9797- server unix:/run/millipds/millipds.sock fail_timeout=0;
9898-}
9999-100100-server {
101101- listen 80;
102102- server_name millipds.test; # CHANGEME!
103103-104104- location / {
105105- proxy_pass http://millipds;
106106- proxy_http_version 1.1;
107107- proxy_set_header Connection "upgrade";
108108- proxy_set_header Upgrade $http_upgrade;
109109- proxy_set_header X-Forwarded-For $remote_addr;
110110- proxy_read_timeout 1d;
111111- proxy_redirect off;
112112- proxy_buffering off;
113113- access_log off;
114114- }
115115-}
116116-```
117117-TODO: is fail_timeout=0 sensible?
118118-119119-Put this in `/etc/nginx/sites-enabled/millipds`
120120-121121-Note: For a prod setup, you'll need to enable SSL. That's outside the scope of this guide, but one way is "once you have the service accessible via HTTP, use certbot"
122122-123123-Add the user that nginx runs under (`www-data`) to the `millipds-sock` group:
124124-125125-```sh
126126-sudo adduser www-data millipds-sock
127127-```
128128-129129-Start the service:
130130-131131-```sh
132132-sudo systemctl start millipds # make it start now
133133-sudo systemctl enable millipds # make it start on every boot
134134-systemctl status millipds # check that it's running
135135-sudo systemctl reload nginx # get nginx to see your new config
136136-```
137137-138138-Useful command for watching the logs:
139139-```sh
140140-sudo journalctl -u millipds.service -f
141141-```
3131+See [./docs/DEPLOY.md](./docs/DEPLOY.md)
+118
docs/DEPLOY.md
···11+22+### Production deployment on Ubuntu[WIP]
33+44+These specific instructions assume ubuntu+nginx+systemd. If you're on something else, it shouldn't be too hard to adapt.
55+66+```sh
77+# create group for service socket access
88+sudo addgroup millipds-sock
99+1010+# create unprivileged user
1111+sudo adduser --system --shell /bin/false --home /opt/millipds millipds
1212+1313+# add the user to the group (leaving its primary group as the default)
1414+sudo usermod -aG millipds-sock millipds
1515+1616+# start a shell session under the new user
1717+sudo -u millipds -s
1818+1919+# all commands below this point are run as the millipds user
2020+2121+# create a virtualenv (maybe this will prove unnecessary, but it probably doesn't hurt)
2222+python3 -m venv ~/.venv
2323+2424+# activate the virtualenv (this must be re-run every time you want to use it)
2525+source ~/.venv/bin/activate
2626+2727+# all commands below this point are run inside the virtualenv
2828+2929+# upgrade pip (maybe optional, again, probably doesn't hurt)
3030+python3 -m pip install --upgrade pip
3131+3232+# install millipds
3333+python3 -m pip install --upgrade millipds@git+https://github.com/DavidBuchanan314/millipds
3434+```
3535+3636+Upgrading:
3737+3838+```sh
3939+sudo -u millipds -s
4040+source ~/.venv/bin/activate
4141+python3 -m pip install --upgrade --force-reinstall --no-cache-dir millipds@git+https://github.com/DavidBuchanan314/millipds
4242+exit
4343+sudo systemctl restart millipds
4444+```
4545+4646+Create a systemd service
4747+4848+```
4949+[Unit]
5050+Description=millipds
5151+After=network.target
5252+5353+[Service]
5454+Type=simple
5555+Restart=on-failure
5656+User=millipds
5757+WorkingDirectory=/opt/millipds
5858+ExecStart=/opt/millipds/.venv/bin/millipds run --sock_path=/run/millipds/millipds.sock
5959+RuntimeDirectory=millipds
6060+6161+[Install]
6262+WantedBy=multi-user.target
6363+```
6464+6565+TODO: put this file in the repo so it can be copied into place more easily.
6666+6767+Put this in `/etc/systemd/system/millipds.service`
6868+6969+Create a new nginx config:
7070+```
7171+upstream millipds {
7272+ server unix:/run/millipds/millipds.sock fail_timeout=0;
7373+}
7474+7575+server {
7676+ listen 80;
7777+ server_name millipds.test; # CHANGEME!
7878+7979+ location / {
8080+ proxy_pass http://millipds;
8181+ proxy_http_version 1.1;
8282+ proxy_set_header Connection "upgrade";
8383+ proxy_set_header Upgrade $http_upgrade;
8484+ proxy_set_header X-Forwarded-For $remote_addr;
8585+ proxy_read_timeout 1d;
8686+ proxy_redirect off;
8787+ proxy_buffering off;
8888+ access_log off;
8989+ }
9090+}
9191+```
9292+TODO: is fail_timeout=0 sensible?
9393+9494+Put this in `/etc/nginx/sites-enabled/millipds`
9595+9696+Note: For a prod setup, you'll need to enable SSL. That's outside the scope of this guide, but one way is "once you have the service accessible via HTTP, use certbot"
9797+9898+Add the user that nginx runs under (`www-data`) to the `millipds-sock` group:
9999+100100+```sh
101101+sudo adduser www-data millipds-sock
102102+```
103103+104104+Start the service:
105105+106106+```sh
107107+sudo systemctl start millipds # make it start now
108108+sudo systemctl enable millipds # make it start on every boot
109109+systemctl status millipds # check that it's running
110110+sudo systemctl reload nginx # get nginx to see your new config
111111+```
112112+113113+Useful command for watching the logs:
114114+```sh
115115+sudo journalctl -u millipds.service -f
116116+```
117117+118118+Once the service is up, see [ACCOUNTS.md](./ACCOUNTS.md) for setting up user accounts.