]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - support/doc/production.md
Improving the CentOS7 specific parts
[github/Chocobozzz/PeerTube.git] / support / doc / production.md
CommitLineData
63bfad7e
C
1# Production guide
2
4df6a1b8
C
3 * [Installation](#installation)
4 * [Upgrade](#upgrade)
5
63bfad7e
C
6## Installation
7
66c3b774 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.**
1185c246 9
63bfad7e
C
10### Dependencies
11
12Follow the steps of the [dependencies guide](dependencies.md).
13
14### PeerTube user
15
59c48d49 16Create a `peertube` user with `/var/www/peertube` home:
63bfad7e 17
afe81767 18```
59c48d49 19$ sudo useradd -m -d /var/www/peertube -s /bin/bash -p peertube peertube
e5203ffa
TC
20```
21
22Set its password:
23```
d2000ca6 24$ sudo passwd peertube
63bfad7e
C
25```
26
27### Database
28
e5203ffa 29Create the production database and a peertube user inside PostgreSQL:
63bfad7e 30
afe81767 31```
d2000ca6
C
32$ sudo -u postgres createuser -P peertube
33$ sudo -u postgres createdb -O peertube peertube_prod
63bfad7e
C
34```
35
d2000ca6 36### Prepare PeerTube directory
63bfad7e 37
e5203ffa
TC
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```
59c48d49 42
e5203ffa
TC
43Open the peertube directory, create a few required directories
44```
15dbc134 45$ cd /var/www/peertube && sudo -u peertube mkdir config storage versions && cd versions
e5203ffa 46```
59c48d49 47
e5203ffa 48Download the latest version of the Peertube client, unzip it and remove the zip
afe81767 49```
15dbc134
TC
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
e5203ffa 52```
59c48d49 53
e5203ffa
TC
54Install Peertube
55```
15dbc134 56$ cd ../ && sudo -u peertube ln -s versions/peertube-${VERSION} ./peertube-latest
09c93c20 57$ cd ./peertube-latest && sudo -H -u peertube yarn install --production --pure-lockfile
63bfad7e
C
58```
59
60### PeerTube configuration
61
62Copy example configuration:
63
afe81767 64```
59c48d49 65$ cd /var/www/peertube && sudo -u peertube cp peertube-latest/config/production.yaml.example config/production.yaml
63bfad7e
C
66```
67
68Then edit the `config/production.yaml` file according to your webserver
d2000ca6 69configuration.
63bfad7e 70
30f55025
C
71**PeerTube does not support webserver host change**. Keep in mind your domain name is definitive after your first PeerTube start.
72
63bfad7e
C
73### Webserver
74
e883399f
RK
75We only provide official configuration files for Nginx.
76
63bfad7e
C
77Copy the nginx configuration template:
78
afe81767 79```
59c48d49 80$ sudo cp /var/www/peertube/peertube-latest/support/nginx/peertube /etc/nginx/sites-available/peertube
63bfad7e
C
81```
82
5668bf2e
C
83Then modify the webserver configuration file. Please pay attention to the `alias` keys of the static locations.
84It should correspond to the paths of your storage directories (set in the configuration file inside the `storage` key).
63bfad7e 85
afe81767 86```
63bfad7e
C
87$ sudo vim /etc/nginx/sites-available/peertube
88```
89
0b495712
C
90Activate the configuration file:
91
92```
93$ sudo ln -s /etc/nginx/sites-available/peertube /etc/nginx/sites-enabled/peertube
94```
95
96To generate the certificate for your domain as required to make https work you can use [Let's Encrypt](https://letsencrypt.org/):
97
98```
99$ sudo systemctl stop nginx
e6607b25 100$ sudo vim /etc/nginx/sites-available/peertube # Comment ssl_certificate and ssl_certificate_key lines
0b495712 101$ sudo certbot --authenticator standalone --installer nginx --post-hook "systemctl start nginx"
e6607b25
C
102$ sudo vim /etc/nginx/sites-available/peertube # Uncomment ssl_certificate and ssl_certificate_key lines
103$ sudo systemctl reload nginx
e883399f
RK
104```
105
106Remember your certificate will expire in 90 days, and thus needs renewal.
63bfad7e 107
0b495712 108Now you have the certificates you can reload nginx:
63bfad7e 109
afe81767 110```
63bfad7e
C
111$ sudo systemctl reload nginx
112```
113
07aa93a8 114### systemd
63bfad7e 115
07aa93a8 116If your OS uses systemd, copy the configuration template:
63bfad7e 117
afe81767 118```
59c48d49 119$ sudo cp /var/www/peertube/peertube-latest/support/systemd/peertube.service /etc/systemd/system/
63bfad7e
C
120```
121
122Update the service file:
123
afe81767 124```
d2000ca6 125$ sudo vim /etc/systemd/system/peertube.service
63bfad7e
C
126```
127
63bfad7e
C
128
129Tell systemd to reload its config:
130
afe81767 131```
d2000ca6 132$ sudo systemctl daemon-reload
63bfad7e
C
133```
134
6b2ef589
C
135If you want to start PeerTube on boot:
136
137```
9625507f 138$ sudo systemctl enable peertube
6b2ef589
C
139```
140
07aa93a8 141Run:
63bfad7e 142
afe81767 143```
d2000ca6
C
144$ sudo systemctl start peertube
145$ sudo journalctl -feu peertube
63bfad7e
C
146```
147
6d55bd21
GN
148### FreeBSD
149
07aa93a8 150If you're using FreeBSD, copy the startup script and update rc.conf:
6d55bd21
GN
151
152```
153$ sudo cp /var/www/peertube/peertube-latest/support/freebsd/peertube /usr/local/etc/rc.d/
154$ sudo chmod +x /usr/local/etc/rc.d/peertube
155$ sudo echo peertube_enable="YES" >> /etc/rc.conf
156```
157
07aa93a8 158Run:
6d55bd21
GN
159
160```
161$ sudo service peertube start
162```
163
63bfad7e
C
164### Administrator
165
166The administrator password is automatically generated and can be found in the
167logs. You can set another password with:
168
afe81767 169```
59c48d49 170$ cd /var/www/peertube/peertube-latest && NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run reset-password -- -u root
63bfad7e
C
171```
172
2e3a0215
C
173Now you can subscribe to the mailing list for PeerTube administrators: https://framalistes.org/sympa/subscribe/peertube-admin
174
63bfad7e
C
175## Upgrade
176
a8b5ce95 177#### Auto (minor versions only)
1007a018
SL
178
179```
a8b5ce95 180$ cd /var/www/peertube/peertube-latest/scripts && sudo -u peertube ./upgrade.sh
a8b5ce95 181$ sudo systemctl restart peertube && sudo journalctl -fu peertube
1007a018
SL
182```
183
a8b5ce95
C
184#### Manually
185
ce487e1e 186Make a SQL backup
c7a9f34f
C
187
188```
189$ SQL_BACKUP_PATH="backup/sql-peertube_prod-$(date -Im).bak" && \
59c48d49 190 cd /var/www/peertube && sudo -u peertube mkdir -p backup && \
c7a9f34f
C
191 sudo pg_dump -U peertube -W -h localhost -F c peertube_prod -f "$SQL_BACKUP_PATH"
192```
193
ce487e1e 194Fetch the latest tagged version of Peertube:
23e27dd5
C
195
196```
ce487e1e 197$ 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"
23e27dd5
C
198```
199
ce487e1e 200Download the new version and unzip it:
c7a9f34f 201
afe81767 202```
ce487e1e 203$ cd /var/www/peertube/versions && \
fd206f0b 204 sudo -u peertube wget -q "https://github.com/Chocobozzz/PeerTube/releases/download/${VERSION}/peertube-${VERSION}.zip" && \
ce487e1e
C
205 sudo -u peertube unzip -o peertube-${VERSION}.zip && \
206 sudo -u peertube rm peertube-${VERSION}.zip
207```
208
4805cff1 209Install node dependencies:
ce487e1e
C
210
211```
4805cff1
C
212$ cd /var/www/peertube/versions/peertube-${VERSION} && \
213 sudo -u peertube yarn install --production --pure-lockfile
ce487e1e
C
214```
215
4805cff1 216Copy new configuration defaults values and update your configuration file:
ce487e1e 217
63bfad7e 218```
4805cff1 219$ sudo -u peertube cp /var/www/peertube/versions/peertube-${VERSION}/config/default.yaml /var/www/peertube/config/default.yaml
a8b5ce95 220$ diff /var/www/peertube/versions/peertube-${VERSION}/config/production.yaml.example /var/www/peertube/config/production.yaml
ce487e1e
C
221```
222
4805cff1 223Change the link to point to the latest version:
ce487e1e
C
224
225```
4805cff1 226$ cd /var/www/peertube && \
2519d9fe 227 sudo unlink ./peertube-latest && \
4805cff1 228 sudo -u peertube ln -s versions/peertube-${VERSION} ./peertube-latest
ce487e1e
C
229```
230
4805cff1 231
ce487e1e
C
232Restart PeerTube:
233```
234$ sudo systemctl restart peertube
235```
236
237### Things went wrong?
c7a9f34f 238
ce487e1e 239Change `peertube-latest` destination to the previous version and restore your SQL backup:
c7a9f34f
C
240
241```
242$ OLD_VERSION="v0.42.42" && SQL_BACKUP_PATH="backup/sql-peertube_prod-2018-01-19T10:18+01:00.bak" && \
2519d9fe 243 cd /var/www/peertube && unlink ./peertube-latest && \
c7a9f34f 244 sudo -u peertube ln -s "versions/peertube-$OLD_VERSION" peertube-latest && \
f529f983 245 pg_restore -U peertube -W -h localhost -c -d peertube_prod "$SQL_BACKUP_PATH"
c7a9f34f
C
246 sudo systemctl restart peertube
247```