]>
Commit | Line | Data |
---|---|---|
63bfad7e C |
1 | # Production guide |
2 | ||
4df6a1b8 C |
3 | * [Installation](#installation) |
4 | * [Upgrade](#upgrade) | |
5 | ||
63bfad7e C |
6 | ## Installation |
7 | ||
1185c246 C |
8 | **Please don't install PeerTube for production on a small device behind a low bandwidth connection because it could slow down the fediverse.** |
9 | ||
63bfad7e C |
10 | ### Dependencies |
11 | ||
12 | Follow the steps of the [dependencies guide](dependencies.md). | |
13 | ||
14 | ### PeerTube user | |
15 | ||
59c48d49 | 16 | Create 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 | ||
22 | Set its password: | |
23 | ``` | |
d2000ca6 | 24 | $ sudo passwd peertube |
63bfad7e C |
25 | ``` |
26 | ||
27 | ### Database | |
28 | ||
e5203ffa | 29 | Create 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 |
38 | Fetch 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 |
43 | Open 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 | 48 | Download 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 |
54 | Install 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 | ||
62 | Copy 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 | ||
68 | Then edit the `config/production.yaml` file according to your webserver | |
d2000ca6 | 69 | configuration. |
63bfad7e C |
70 | |
71 | ### Webserver | |
72 | ||
e883399f RK |
73 | We only provide official configuration files for Nginx. |
74 | ||
63bfad7e C |
75 | Copy the nginx configuration template: |
76 | ||
afe81767 | 77 | ``` |
59c48d49 | 78 | $ sudo cp /var/www/peertube/peertube-latest/support/nginx/peertube /etc/nginx/sites-available/peertube |
63bfad7e C |
79 | ``` |
80 | ||
5668bf2e C |
81 | Then modify the webserver configuration file. Please pay attention to the `alias` keys of the static locations. |
82 | It should correspond to the paths of your storage directories (set in the configuration file inside the `storage` key). | |
63bfad7e | 83 | |
afe81767 | 84 | ``` |
63bfad7e C |
85 | $ sudo vim /etc/nginx/sites-available/peertube |
86 | ``` | |
87 | ||
0b495712 C |
88 | Activate the configuration file: |
89 | ||
90 | ``` | |
91 | $ sudo ln -s /etc/nginx/sites-available/peertube /etc/nginx/sites-enabled/peertube | |
92 | ``` | |
93 | ||
94 | To 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 | |
e6607b25 | 98 | $ sudo vim /etc/nginx/sites-available/peertube # Comment ssl_certificate and ssl_certificate_key lines |
0b495712 | 99 | $ sudo certbot --authenticator standalone --installer nginx --post-hook "systemctl start nginx" |
e6607b25 C |
100 | $ sudo vim /etc/nginx/sites-available/peertube # Uncomment ssl_certificate and ssl_certificate_key lines |
101 | $ sudo systemctl reload nginx | |
e883399f RK |
102 | ``` |
103 | ||
104 | Remember your certificate will expire in 90 days, and thus needs renewal. | |
63bfad7e | 105 | |
0b495712 | 106 | Now you have the certificates you can reload nginx: |
63bfad7e | 107 | |
afe81767 | 108 | ``` |
63bfad7e C |
109 | $ sudo systemctl reload nginx |
110 | ``` | |
111 | ||
112 | ### Systemd | |
113 | ||
e883399f | 114 | Copy the SystemD configuration template: |
63bfad7e | 115 | |
afe81767 | 116 | ``` |
59c48d49 | 117 | $ sudo cp /var/www/peertube/peertube-latest/support/systemd/peertube.service /etc/systemd/system/ |
63bfad7e C |
118 | ``` |
119 | ||
120 | Update the service file: | |
121 | ||
afe81767 | 122 | ``` |
d2000ca6 | 123 | $ sudo vim /etc/systemd/system/peertube.service |
63bfad7e C |
124 | ``` |
125 | ||
63bfad7e C |
126 | |
127 | Tell systemd to reload its config: | |
128 | ||
afe81767 | 129 | ``` |
d2000ca6 | 130 | $ sudo systemctl daemon-reload |
63bfad7e C |
131 | ``` |
132 | ||
6b2ef589 C |
133 | If you want to start PeerTube on boot: |
134 | ||
135 | ``` | |
9625507f | 136 | $ sudo systemctl enable peertube |
6b2ef589 C |
137 | ``` |
138 | ||
63bfad7e C |
139 | ### Run |
140 | ||
afe81767 | 141 | ``` |
d2000ca6 C |
142 | $ sudo systemctl start peertube |
143 | $ sudo journalctl -feu peertube | |
63bfad7e C |
144 | ``` |
145 | ||
146 | ### Administrator | |
147 | ||
148 | The administrator password is automatically generated and can be found in the | |
149 | logs. You can set another password with: | |
150 | ||
afe81767 | 151 | ``` |
59c48d49 | 152 | $ cd /var/www/peertube/peertube-latest && NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run reset-password -- -u root |
63bfad7e C |
153 | ``` |
154 | ||
155 | ## Upgrade | |
156 | ||
a8b5ce95 | 157 | #### Auto (minor versions only) |
1007a018 SL |
158 | |
159 | ``` | |
a8b5ce95 | 160 | $ cd /var/www/peertube/peertube-latest/scripts && sudo -u peertube ./upgrade.sh |
a8b5ce95 | 161 | $ sudo systemctl restart peertube && sudo journalctl -fu peertube |
1007a018 SL |
162 | ``` |
163 | ||
a8b5ce95 C |
164 | #### Manually |
165 | ||
ce487e1e | 166 | Make a SQL backup |
c7a9f34f C |
167 | |
168 | ``` | |
169 | $ SQL_BACKUP_PATH="backup/sql-peertube_prod-$(date -Im).bak" && \ | |
59c48d49 | 170 | cd /var/www/peertube && sudo -u peertube mkdir -p backup && \ |
c7a9f34f C |
171 | sudo pg_dump -U peertube -W -h localhost -F c peertube_prod -f "$SQL_BACKUP_PATH" |
172 | ``` | |
173 | ||
ce487e1e | 174 | Fetch the latest tagged version of Peertube: |
23e27dd5 C |
175 | |
176 | ``` | |
ce487e1e | 177 | $ 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 |
178 | ``` |
179 | ||
ce487e1e | 180 | Download the new version and unzip it: |
c7a9f34f | 181 | |
afe81767 | 182 | ``` |
ce487e1e | 183 | $ cd /var/www/peertube/versions && \ |
fd206f0b | 184 | sudo -u peertube wget -q "https://github.com/Chocobozzz/PeerTube/releases/download/${VERSION}/peertube-${VERSION}.zip" && \ |
ce487e1e C |
185 | sudo -u peertube unzip -o peertube-${VERSION}.zip && \ |
186 | sudo -u peertube rm peertube-${VERSION}.zip | |
187 | ``` | |
188 | ||
4805cff1 | 189 | Install node dependencies: |
ce487e1e C |
190 | |
191 | ``` | |
4805cff1 C |
192 | $ cd /var/www/peertube/versions/peertube-${VERSION} && \ |
193 | sudo -u peertube yarn install --production --pure-lockfile | |
ce487e1e C |
194 | ``` |
195 | ||
4805cff1 | 196 | Copy new configuration defaults values and update your configuration file: |
ce487e1e | 197 | |
63bfad7e | 198 | ``` |
4805cff1 | 199 | $ sudo -u peertube cp /var/www/peertube/versions/peertube-${VERSION}/config/default.yaml /var/www/peertube/config/default.yaml |
a8b5ce95 | 200 | $ diff /var/www/peertube/versions/peertube-${VERSION}/config/production.yaml.example /var/www/peertube/config/production.yaml |
ce487e1e C |
201 | ``` |
202 | ||
4805cff1 | 203 | Change the link to point to the latest version: |
ce487e1e C |
204 | |
205 | ``` | |
4805cff1 | 206 | $ cd /var/www/peertube && \ |
2519d9fe | 207 | sudo unlink ./peertube-latest && \ |
4805cff1 | 208 | sudo -u peertube ln -s versions/peertube-${VERSION} ./peertube-latest |
ce487e1e C |
209 | ``` |
210 | ||
4805cff1 | 211 | |
ce487e1e C |
212 | Restart PeerTube: |
213 | ``` | |
214 | $ sudo systemctl restart peertube | |
215 | ``` | |
216 | ||
217 | ### Things went wrong? | |
c7a9f34f | 218 | |
ce487e1e | 219 | Change `peertube-latest` destination to the previous version and restore your SQL backup: |
c7a9f34f C |
220 | |
221 | ``` | |
222 | $ OLD_VERSION="v0.42.42" && SQL_BACKUP_PATH="backup/sql-peertube_prod-2018-01-19T10:18+01:00.bak" && \ | |
2519d9fe | 223 | cd /var/www/peertube && unlink ./peertube-latest && \ |
c7a9f34f | 224 | sudo -u peertube ln -s "versions/peertube-$OLD_VERSION" peertube-latest && \ |
f529f983 | 225 | pg_restore -U peertube -W -h localhost -c -d peertube_prod "$SQL_BACKUP_PATH" |
c7a9f34f C |
226 | sudo systemctl restart peertube |
227 | ``` |