ニジカ投稿局 https://tv.nizika.tv
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tools.md 19 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. # CLI tools guide
  2. [[toc]]
  3. ## Remote PeerTube CLI
  4. `peertube-cli` is a tool that communicates with a PeerTube instance using its [REST API](https://docs.joinpeertube.org/api-rest-reference.html).
  5. It can be launched from a remote server/computer to easily upload videos, manage plugins, redundancies etc.
  6. ### Installation
  7. Ensure you have `node` installed on your system:
  8. ```bash
  9. node --version # Should be >= 16.x
  10. ```
  11. Then install the CLI:
  12. ```bash
  13. sudo npm install -g @peertube/peertube-cli
  14. ```
  15. ### CLI wrapper
  16. The wrapper provides a convenient interface to the following sub-commands.
  17. ```
  18. Usage: peertube-cli [command] [options]
  19. Options:
  20. -v, --version output the version number
  21. -h, --help display help for command
  22. Commands:
  23. auth Register your accounts on remote instances to use them with other commands
  24. upload|up [options] Upload a video on a PeerTube instance
  25. redundancy|r Manage instance redundancies
  26. plugins|p Manage instance plugins/themes
  27. get-access-token|token [options] Get a peertube access token
  28. help [command] display help for command
  29. ```
  30. The wrapper can keep track of instances you have an account on. We limit to one account per instance for now.
  31. ```bash
  32. peertube-cli auth add -u 'PEERTUBE_URL' -U 'PEERTUBE_USER' --password 'PEERTUBE_PASSWORD'
  33. peertube-cli auth list
  34. ┌──────────────────────────────┬──────────────────────────────┐
  35. │ instance │ login │
  36. ├──────────────────────────────┼──────────────────────────────┤
  37. │ 'PEERTUBE_URL' │ 'PEERTUBE_USER' │
  38. └──────────────────────────────┴──────────────────────────────┘
  39. ```
  40. You can now use that account to execute sub-commands without feeding the `--url`, `--username` and `--password` parameters:
  41. ```bash
  42. peertube-cli upload <videoFile>
  43. peertube-cli plugins list
  44. ...
  45. ```
  46. #### peertube-cli upload
  47. You can use this script to upload videos directly from the CLI.
  48. Videos will be publicly available after transcoding (you can see them before that in your account on the web interface).
  49. ```bash
  50. cd ${CLONE}
  51. peertube-cli upload --help
  52. ```
  53. #### peertube-cli plugins
  54. Install/update/uninstall or list local or NPM PeerTube plugins:
  55. ```bash
  56. cd ${CLONE}
  57. peertube-cli plugins --help
  58. peertube-cli plugins list --help
  59. peertube-cli plugins install --help
  60. peertube-cli plugins update --help
  61. peertube-cli plugins uninstall --help
  62. peertube-cli plugins install --path /my/plugin/path
  63. peertube-cli plugins install --npm-name peertube-theme-example
  64. ```
  65. #### peertube-cli redundancy
  66. Manage (list/add/remove) video redundancies:
  67. To list your videos that are duplicated by remote instances:
  68. ```bash
  69. peertube-cli redundancy list-remote-redundancies
  70. ```
  71. To list remote videos that your instance duplicated:
  72. ```bash
  73. peertube-cli redundancy list-my-redundancies
  74. ```
  75. To duplicate a specific video in your redundancy system:
  76. ```bash
  77. peertube-cli redundancy add --video 823
  78. ```
  79. To remove a video redundancy:
  80. ```bash
  81. peertube-cli redundancy remove --video 823
  82. ```
  83. ## PeerTube runner
  84. PeerTube supports VOD/Live transcoding and VOD transcription (PeerTube >= 6.2) by a remote PeerTube runner.
  85. ### Runner installation
  86. Ensure you have `node`, `ffmpeg` and `ffprobe` installed on your system:
  87. ```bash
  88. node --version # Should be >= 16.x
  89. ffprobe -version # Should be >= 4.3
  90. ffmpeg -version # Should be >= 4.3
  91. ```
  92. If you want to use video transcription:
  93. ```bash
  94. pip install whisper-ctranslate2 # or pipx install whisper-ctranslate2 depending on your distribution
  95. ```
  96. Then install the CLI:
  97. ```bash
  98. sudo npm install -g @peertube/peertube-runner
  99. ```
  100. ### Configuration
  101. The runner uses env paths like `~/.config`, `~/.cache` and `~/.local/share` directories to store runner configuration or temporary files.
  102. Multiple PeerTube runners can run on the same OS by using the `--id` CLI option (each runner uses its own config/tmp directories):
  103. ```bash
  104. peertube-runner [commands] --id instance-1
  105. peertube-runner [commands] --id instance-2
  106. peertube-runner [commands] --id instance-3
  107. ```
  108. You can change the runner configuration (jobs concurrency, ffmpeg threads/nice, whisper engines/models, etc.) by editing `~/.config/peertube-runner-nodejs/[id]/config.toml`.
  109. ### Run the server
  110. #### In a shell
  111. You need to run the runner in server mode first so it can run transcoding jobs of registered PeerTube instances:
  112. ```bash
  113. peertube-runner server
  114. ```
  115. #### As a Systemd service
  116. If your OS uses systemd, you can also configure a service so that the runner starts automatically.
  117. To do so, first create a dedicated user. Here, we are calling it `prunner`, but you can choose whatever name you want.
  118. We are using `/srv/prunner` as his home dir, but you can choose any other path.
  119. ```bash
  120. useradd -m -d /srv/prunner -s /bin/bash -p prunner prunner
  121. ```
  122. ::: info Note
  123. If you want to use `/home/prunner`, you have to set `ProtectHome=false` in the systemd configuration (see below).
  124. :::
  125. Now, you can create the `/etc/systemd/system/prunner.service` file (don't forget to adapt path and user/group names if you changed it):
  126. ```Systemd
  127. [Unit]
  128. Description=PeerTube runner daemon
  129. After=network.target
  130. [Service]
  131. Type=simple
  132. Environment=NODE_ENV=production
  133. User=prunner
  134. Group=prunner
  135. ExecStart=peertube-runner server
  136. WorkingDirectory=/srv/prunner
  137. SyslogIdentifier=prunner
  138. Restart=always
  139. ; Some security directives.
  140. ; Mount /usr, /boot, and /etc as read-only for processes invoked by this service.
  141. ProtectSystem=full
  142. ; Sets up a new /dev mount for the process and only adds API pseudo devices
  143. ; like /dev/null, /dev/zero or /dev/random but not physical devices. Disabled
  144. ; by default because it may not work on devices like the Raspberry Pi.
  145. PrivateDevices=false
  146. ; Ensures that the service process and all its children can never gain new
  147. ; privileges through execve().
  148. NoNewPrivileges=true
  149. ; This makes /home, /root, and /run/user inaccessible and empty for processes invoked
  150. ; by this unit. Make sure that you do not depend on data inside these folders.
  151. ProtectHome=true
  152. ; Drops the sys admin capability from the daemon.
  153. CapabilityBoundingSet=~CAP_SYS_ADMIN
  154. [Install]
  155. WantedBy=multi-user.target
  156. ```
  157. :::info Note
  158. You can add the parameter `--id instance-1` on the `ExecStart` line, if you want to have multiple instances.
  159. You can then create multiple separate services. They can use the same user and path.
  160. :::
  161. Finally, to enable the service for the first time:
  162. ```bash
  163. systemctl daemon-reload
  164. systemctl enable prunner.service
  165. systemctl restart prunner.service
  166. ```
  167. Next time, if you need to start/stop/restart the service:
  168. ```bash
  169. systemctl stop prunner.service
  170. systemctl start prunner.service
  171. systemctl restart prunner.service
  172. ```
  173. You can also check the status (and last logs):
  174. ```bash
  175. systemctl status prunner.service
  176. ```
  177. To edit the runner configuration: juste edit the `/srv/prunner/.config/peertube-runner-nodejs/default/config.toml` file,
  178. and restart the service (this file will be created when the runner starts for the first time).
  179. If you are using the `--id` parameter, you can change specific configuration by editing the file `/srv/prunner/.config/peertube-runner-nodejs/[id]/config.toml`.
  180. ::: info
  181. For every peertube-runner commands described below, you have to run them as the `prunner` user.
  182. So for example, to call the `list-registered` command: `sudo -u prunner peertube-runner list-registered`.
  183. Otherwise the script will read the wrong configuration and cache files, and won't work as expected.
  184. :::
  185. ### Register
  186. Then, you can register the runner to process transcoding job of a remote PeerTube instance:
  187. ::: code-group
  188. ```bash [Shell]
  189. peertube-runner register --url http://peertube.example.com --registration-token ptrrt-... --runner-name my-runner-name
  190. ```
  191. ```bash [Systemd]
  192. sudo -u prunner peertube-runner register --url http://peertube.example.com --registration-token ptrrt-... --runner-name my-runner-name
  193. ```
  194. :::
  195. The runner will then use a websocket connection with the PeerTube instance to be notified about new available transcoding jobs.
  196. ### Unregister
  197. To unregister a PeerTube instance:
  198. ::: code-group
  199. ```bash [Shell]
  200. peertube-runner unregister --url http://peertube.example.com --runner-name my-runner-name
  201. ```
  202. ```bash [Systemd]
  203. sudo -u prunner peertube-runner unregister --url http://peertube.example.com --runner-name my-runner-name
  204. ```
  205. :::
  206. ### List registered instances
  207. ::: code-group
  208. ```bash [Shell]
  209. peertube-runner list-registered
  210. ```
  211. ```bash [Systemd]
  212. sudo -u prunner peertube-runner list-registered
  213. ```
  214. :::
  215. ### Update the runner package
  216. You can check if there is a new runner version using:
  217. ```bash
  218. sudo npm outdated -g @peertube/peertube-runner
  219. ```
  220. ```
  221. Package Current Wanted Latest Location Depended by
  222. @peertube/peertube-runner 0.0.6 0.0.7 0.0.7 node_modules/@peertube/peertube-runner lib
  223. ```
  224. To update the runner:
  225. ```bash
  226. # Update the package
  227. sudo npm update -g @peertube/peertube-runner
  228. # Check that the version changed (optional)
  229. sudo npm list -g @peertube/peertube-runner
  230. # Restart the service (if you are using systemd)
  231. sudo systemctl restart prunner.service
  232. ```
  233. ## Server tools
  234. Server tools are scripts that interact directly with the code of your PeerTube instance.
  235. They must be run on the server, in `peertube-latest` directory.
  236. ### Parse logs
  237. To parse PeerTube last log file:
  238. ::: code-group
  239. ```bash [Classic installation]
  240. cd /var/www/peertube/peertube-latest
  241. sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run parse-log -- --level info
  242. ```
  243. ```bash [Docker]
  244. cd /var/www/peertube-docker
  245. docker compose exec -u peertube peertube npm run parse-log -- --level info
  246. ```
  247. :::
  248. `--level` is optional and could be `info`/`warn`/`error`
  249. You can also remove SQL or HTTP logs using `--not-tags` (PeerTube >= 3.2):
  250. ::: code-group
  251. ```bash [Classic installation]
  252. cd /var/www/peertube/peertube-latest
  253. sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run parse-log -- --level debug --not-tags http sql
  254. ```
  255. ```bash [Docker]
  256. cd /var/www/peertube-docker
  257. docker compose exec -u peertube peertube npm run parse-log -- --level debug --not-tags http sql
  258. ```
  259. :::
  260. ### Regenerate video thumbnails
  261. Regenerating local video thumbnails could be useful because new PeerTube releases may increase thumbnail sizes:
  262. ::: code-group
  263. ```bash [Classic installation]
  264. cd /var/www/peertube/peertube-latest
  265. sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run regenerate-thumbnails
  266. ```
  267. ```bash [Docker]
  268. cd /var/www/peertube-docker
  269. docker compose exec -u peertube peertube npm run regenerate-thumbnails
  270. ```
  271. :::
  272. ### Add or replace specific video file
  273. You can use this script to import a video file to replace an already uploaded file or to add a new web compatible resolution to a video. PeerTube needs to be running.
  274. You can then create a transcoding job using the web interface if you need to optimize your file or create an HLS version of it.
  275. ::: code-group
  276. ```bash [Classic installation]
  277. cd /var/www/peertube/peertube-latest
  278. sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run create-import-video-file-job -- -v [videoUUID] -i [videoFile]
  279. ```
  280. ```bash [Docker]
  281. cd /var/www/peertube-docker
  282. docker compose exec -u peertube peertube npm run create-import-video-file-job -- -v [videoUUID] -i [videoFile]
  283. ```
  284. :::
  285. ### Move video files from filesystem to object storage
  286. Use this script to move all video files or a specific video file to object storage.
  287. ::: code-group
  288. ```bash [Classic installation]
  289. cd /var/www/peertube/peertube-latest
  290. sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run create-move-video-storage-job -- --to-object-storage -v [videoUUID]
  291. ```
  292. ```bash [Docker]
  293. cd /var/www/peertube-docker
  294. docker compose exec -u peertube peertube npm run create-move-video-storage-job -- --to-object-storage -v [videoUUID]
  295. ```
  296. :::
  297. The script can also move all video files that are not already in object storage:
  298. ::: code-group
  299. ```bash [Classic installation]
  300. cd /var/www/peertube/peertube-latest
  301. sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run create-move-video-storage-job -- --to-object-storage --all-videos
  302. ```
  303. ```bash [Docker]
  304. cd /var/www/peertube-docker
  305. docker compose exec -u peertube peertube npm run create-move-video-storage-job -- --to-object-storage --all-videos
  306. ```
  307. :::
  308. ### Move video files from object storage to filesystem
  309. **PeerTube >= 6.0**
  310. Use this script to move all video files or a specific video file from object storage to the PeerTube instance filesystem.
  311. ::: code-group
  312. ```bash [Classic installation]
  313. cd /var/www/peertube/peertube-latest
  314. sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run create-move-video-storage-job -- --to-file-system -v [videoUUID]
  315. ```
  316. ```bash [Docker]
  317. cd /var/www/peertube-docker
  318. docker compose exec -u peertube peertube npm run create-move-video-storage-job -- --to-file-system -v [videoUUID]
  319. ```
  320. :::
  321. The script can also move all video files that are not already on the filesystem:
  322. ::: code-group
  323. ```bash [Classic installation]
  324. cd /var/www/peertube/peertube-latest
  325. sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run create-move-video-storage-job -- --to-file-system --all-videos
  326. ```
  327. ```bash [Docker]
  328. cd /var/www/peertube-docker
  329. docker compose exec -u peertube peertube npm run create-move-video-storage-job -- --to-file-system --all-videos
  330. ```
  331. :::
  332. ### Update object storage URLs
  333. **PeerTube >= 6.2**
  334. Use this script after you migrated to another object storage provider so PeerTube updates its internal object URLs (a confirmation will be demanded first).
  335. PeerTube must be stopped.
  336. ::: code-group
  337. ```bash [Classic installation]
  338. cd /var/www/peertube/peertube-latest
  339. sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run update-object-storage-url -- --from 'https://region.old-s3-provider.example.com' --to 'https://region.new-s3-provider.example.com'
  340. ```
  341. ```bash [Docker]
  342. cd /var/www/peertube-docker
  343. docker compose exec -u peertube peertube npm run update-object-storage-url -- --from 'https://region.old-s3-provider.example.com' --to 'https://region.new-s3-provider.example.com'
  344. ```
  345. :::
  346. ### Cleanup remote files
  347. **PeerTube >= 6.2**
  348. Use this script to recover disk space by removing remote files (thumbnails, avatars...) that can be re-fetched later by your PeerTube instance on-demand:
  349. ```bash [Classic installation]
  350. cd /var/www/peertube/peertube-latest
  351. sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run house-keeping -- --delete-remote-files
  352. ```
  353. ```bash [Docker]
  354. cd /var/www/peertube-docker
  355. docker compose exec -u peertube peertube npm run house-keeping -- --delete-remote-files
  356. ```
  357. :::
  358. ### Generate storyboard
  359. **PeerTube >= 6.0**
  360. Use this script to generate storyboard of a specific video:
  361. ::: code-group
  362. ```bash [Classic installation]
  363. cd /var/www/peertube/peertube-latest
  364. sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run create-generate-storyboard-job -- -v [videoUUID]
  365. ```
  366. ```bash [Docker]
  367. cd /var/www/peertube-docker
  368. docker compose exec -u peertube peertube npm run create-generate-storyboard-job -- -v [videoUUID]
  369. ```
  370. :::
  371. The script can also generate all missing storyboards of local videos:
  372. ::: code-group
  373. ```bash [Classic installation]
  374. cd /var/www/peertube/peertube-latest
  375. sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run create-generate-storyboard-job -- --all-videos
  376. ```
  377. ```bash [Docker]
  378. cd /var/www/peertube-docker
  379. docker compose exec -u peertube peertube npm run create-generate-storyboard-job -- --all-videos
  380. ```
  381. :::
  382. ### Prune filesystem/object storage
  383. Some transcoded videos or shutdown at a bad time can leave some unused files on your storage.
  384. To delete these files (a confirmation will be demanded first):
  385. ```bash
  386. cd /var/www/peertube/peertube-latest
  387. sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run prune-storage
  388. ```
  389. ### Update PeerTube instance domain name
  390. **Changing the hostname is unsupported and may be a risky operation, especially if you have already federated.**
  391. If you started PeerTube with a domain, and then changed it you will have
  392. invalid torrent files and invalid URLs in your database. To fix this, you have
  393. to run the command below (keep in mind your follower instances will NOT update their URLs).
  394. ::: code-group
  395. ```bash [Classic installation]
  396. cd /var/www/peertube/peertube-latest
  397. sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run update-host
  398. ```
  399. ```bash [Docker]
  400. cd /var/www/peertube-docker
  401. docker compose exec -u peertube peertube npm run update-host
  402. ```
  403. :::
  404. ### Reset user password
  405. To reset a user password from CLI, run:
  406. ::: code-group
  407. ```bash [Classic installation]
  408. cd /var/www/peertube/peertube-latest
  409. sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run reset-password -- -u target_username
  410. ```
  411. ```bash [Docker]
  412. cd /var/www/peertube-docker
  413. docker compose exec -u peertube peertube npm run reset-password -- -u target_username
  414. ```
  415. :::
  416. ### Install or uninstall plugins
  417. The difference with `peertube plugins` CLI is that these scripts can be used even if PeerTube is not running.
  418. If PeerTube is running, you need to restart it for the changes to take effect (whereas with `peertube plugins` CLI, plugins/themes are dynamically loaded on the server).
  419. To install/update a plugin or a theme from the disk:
  420. ::: code-group
  421. ```bash [Classic installation]
  422. cd /var/www/peertube/peertube-latest
  423. sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run plugin:install -- --plugin-path /local/plugin/path
  424. ```
  425. ```bash [Docker]
  426. cd /var/www/peertube-docker
  427. docker compose exec -u peertube peertube npm run plugin:install -- --plugin-path /local/plugin/path
  428. ```
  429. :::
  430. From NPM:
  431. ::: code-group
  432. ```bash
  433. cd /var/www/peertube/peertube-latest
  434. sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run plugin:install -- --npm-name peertube-plugin-myplugin
  435. ```
  436. ```bash [Docker]
  437. cd /var/www/peertube-docker
  438. docker compose exec -u peertube peertube npm run plugin:install -- --npm-name peertube-plugin-myplugin
  439. ```
  440. :::
  441. To uninstall a plugin or a theme:
  442. ::: code-group
  443. ```bash [Classic installation]
  444. cd /var/www/peertube/peertube-latest
  445. sudo -u peertube NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run plugin:uninstall -- --npm-name peertube-plugin-myplugin
  446. ```
  447. ```bash [Docker]
  448. cd /var/www/peertube-docker
  449. docker compose exec -u peertube peertube npm run plugin:uninstall -- --npm-name peertube-plugin-myplugin
  450. ```
  451. :::