]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - support/doc/production.md
Update changelog
[github/Chocobozzz/PeerTube.git] / support / doc / production.md
... / ...
CommitLineData
1# Production guide
2
3 * [Installation](#installation)
4 * [Upgrade](#upgrade)
5
6## Installation
7
8**Please don't install PeerTube for production on a small device behind a low bandwidth connection (example: a Raspberry PI behind your ADSL link) because it could slow down the fediverse.**
9
10### Dependencies
11
12Follow the steps of the [dependencies guide](dependencies.md).
13
14### PeerTube user
15
16Create a `peertube` user with `/var/www/peertube` home:
17
18```
19$ sudo useradd -m -d /var/www/peertube -s /bin/bash -p peertube peertube
20```
21
22Set its password:
23```
24$ sudo passwd peertube
25```
26
27### Database
28
29Create the production database and a peertube user inside PostgreSQL:
30
31```
32$ sudo -u postgres createuser -P peertube
33$ sudo -u postgres createdb -O peertube peertube_prod
34```
35
36### Prepare PeerTube directory
37
38Fetch the latest tagged version of Peertube
39```
40$ VERSION=$(curl -s https://api.github.com/repos/chocobozzz/peertube/releases/latest | grep tag_name | cut -d '"' -f 4) && echo "Latest Peertube version is $VERSION"
41```
42
43Open the peertube directory, create a few required directories
44```
45$ cd /var/www/peertube && sudo -u peertube mkdir config storage versions && cd versions
46```
47
48Download the latest version of the Peertube client, unzip it and remove the zip
49```
50$ sudo -u peertube wget -q "https://github.com/Chocobozzz/PeerTube/releases/download/${VERSION}/peertube-${VERSION}.zip"
51$ sudo -u peertube unzip peertube-${VERSION}.zip && sudo -u peertube rm peertube-${VERSION}.zip
52```
53
54Install Peertube
55```
56$ cd ../ && sudo -u peertube ln -s versions/peertube-${VERSION} ./peertube-latest
57$ cd ./peertube-latest && sudo -H -u peertube yarn install --production --pure-lockfile
58```
59
60### PeerTube configuration
61
62Copy example configuration:
63
64```
65$ cd /var/www/peertube && sudo -u peertube cp peertube-latest/config/production.yaml.example config/production.yaml
66```
67
68Then edit the `config/production.yaml` file according to your webserver
69configuration.
70
71### Webserver
72
73We only provide official configuration files for Nginx.
74
75Copy the nginx configuration template:
76
77```
78$ sudo cp /var/www/peertube/peertube-latest/support/nginx/peertube /etc/nginx/sites-available/peertube
79```
80
81Then modify the webserver configuration file. Please pay attention to the `alias` keys of the static locations.
82It should correspond to the paths of your storage directories (set in the configuration file inside the `storage` key).
83
84```
85$ sudo vim /etc/nginx/sites-available/peertube
86```
87
88Activate the configuration file:
89
90```
91$ sudo ln -s /etc/nginx/sites-available/peertube /etc/nginx/sites-enabled/peertube
92```
93
94To generate the certificate for your domain as required to make https work you can use [Let's Encrypt](https://letsencrypt.org/):
95
96```
97$ sudo systemctl stop nginx
98$ sudo vim /etc/nginx/sites-available/peertube # Comment ssl_certificate and ssl_certificate_key lines
99$ sudo certbot --authenticator standalone --installer nginx --post-hook "systemctl start nginx"
100$ sudo vim /etc/nginx/sites-available/peertube # Uncomment ssl_certificate and ssl_certificate_key lines
101$ sudo systemctl reload nginx
102```
103
104Remember your certificate will expire in 90 days, and thus needs renewal.
105
106Now you have the certificates you can reload nginx:
107
108```
109$ sudo systemctl reload nginx
110```
111
112### Systemd
113
114Copy the SystemD configuration template:
115
116```
117$ sudo cp /var/www/peertube/peertube-latest/support/systemd/peertube.service /etc/systemd/system/
118```
119
120Update the service file:
121
122```
123$ sudo vim /etc/systemd/system/peertube.service
124```
125
126
127Tell systemd to reload its config:
128
129```
130$ sudo systemctl daemon-reload
131```
132
133If you want to start PeerTube on boot:
134
135```
136$ sudo systemctl enable peertube
137```
138
139### Run
140
141```
142$ sudo systemctl start peertube
143$ sudo journalctl -feu peertube
144```
145
146### Administrator
147
148The administrator password is automatically generated and can be found in the
149logs. You can set another password with:
150
151```
152$ cd /var/www/peertube/peertube-latest && NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run reset-password -- -u root
153```
154
155Now you can subscribe to the mailing list for PeerTube administrators: https://framalistes.org/sympa/subscribe/peertube-admin
156
157## Upgrade
158
159#### Auto (minor versions only)
160
161```
162$ cd /var/www/peertube/peertube-latest/scripts && sudo -u peertube ./upgrade.sh
163$ sudo systemctl restart peertube && sudo journalctl -fu peertube
164```
165
166#### Manually
167
168Make a SQL backup
169
170```
171$ SQL_BACKUP_PATH="backup/sql-peertube_prod-$(date -Im).bak" && \
172 cd /var/www/peertube && sudo -u peertube mkdir -p backup && \
173 sudo pg_dump -U peertube -W -h localhost -F c peertube_prod -f "$SQL_BACKUP_PATH"
174```
175
176Fetch the latest tagged version of Peertube:
177
178```
179$ VERSION=$(curl -s https://api.github.com/repos/chocobozzz/peertube/releases/latest | grep tag_name | cut -d '"' -f 4) && echo "Latest Peertube version is $VERSION"
180```
181
182Download the new version and unzip it:
183
184```
185$ cd /var/www/peertube/versions && \
186 sudo -u peertube wget -q "https://github.com/Chocobozzz/PeerTube/releases/download/${VERSION}/peertube-${VERSION}.zip" && \
187 sudo -u peertube unzip -o peertube-${VERSION}.zip && \
188 sudo -u peertube rm peertube-${VERSION}.zip
189```
190
191Install node dependencies:
192
193```
194$ cd /var/www/peertube/versions/peertube-${VERSION} && \
195 sudo -u peertube yarn install --production --pure-lockfile
196```
197
198Copy new configuration defaults values and update your configuration file:
199
200```
201$ sudo -u peertube cp /var/www/peertube/versions/peertube-${VERSION}/config/default.yaml /var/www/peertube/config/default.yaml
202$ diff /var/www/peertube/versions/peertube-${VERSION}/config/production.yaml.example /var/www/peertube/config/production.yaml
203```
204
205Change the link to point to the latest version:
206
207```
208$ cd /var/www/peertube && \
209 sudo unlink ./peertube-latest && \
210 sudo -u peertube ln -s versions/peertube-${VERSION} ./peertube-latest
211```
212
213
214Restart PeerTube:
215```
216$ sudo systemctl restart peertube
217```
218
219### Things went wrong?
220
221Change `peertube-latest` destination to the previous version and restore your SQL backup:
222
223```
224$ OLD_VERSION="v0.42.42" && SQL_BACKUP_PATH="backup/sql-peertube_prod-2018-01-19T10:18+01:00.bak" && \
225 cd /var/www/peertube && unlink ./peertube-latest && \
226 sudo -u peertube ln -s "versions/peertube-$OLD_VERSION" peertube-latest && \
227 pg_restore -U peertube -W -h localhost -c -d peertube_prod "$SQL_BACKUP_PATH"
228 sudo systemctl restart peertube
229```