]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - packages/peertube-runner/peertube-runner.ts
Enable external plugins to test the PR
[github/Chocobozzz/PeerTube.git] / packages / peertube-runner / peertube-runner.ts
1 import { Command, InvalidArgumentError } from '@commander-js/extra-typings'
2 import { listRegistered, registerRunner, unregisterRunner } from './register'
3 import { RunnerServer } from './server'
4 import { ConfigManager, logger } from './shared'
5
6 const program = new Command()
7 .option(
8 '--id <id>',
9 'Runner server id, so you can run multiple PeerTube server runners with different configurations on the same machine',
10 'default'
11 )
12 .option('--verbose', 'Run in verbose mode')
13 .hook('preAction', thisCommand => {
14 const options = thisCommand.opts()
15
16 ConfigManager.Instance.init(options.id)
17
18 if (options.verbose === true) {
19 logger.level = 'debug'
20 }
21 })
22
23 program.command('server')
24 .description('Run in server mode, to execute remote jobs of registered PeerTube instances')
25 .action(async () => {
26 try {
27 await RunnerServer.Instance.run()
28 } catch (err) {
29 logger.error('Cannot run PeerTube runner as server mode', err)
30 process.exit(-1)
31 }
32 })
33
34 program.command('register')
35 .description('Register a new PeerTube instance to process runner jobs')
36 .requiredOption('--url <url>', 'PeerTube instance URL', parseUrl)
37 .requiredOption('--registration-token <token>', 'Runner registration token (can be found in PeerTube instance administration')
38 .requiredOption('--runner-name <name>', 'Runner name')
39 .option('--runner-description <description>', 'Runner description')
40 .action(async options => {
41 try {
42 await registerRunner(options)
43 } catch (err) {
44 logger.error('Cannot register this PeerTube runner.', err)
45 process.exit(-1)
46 }
47 })
48
49 program.command('unregister')
50 .description('Unregister the runner from PeerTube instance')
51 .requiredOption('--url <url>', 'PeerTube instance URL', parseUrl)
52 .action(async options => {
53 try {
54 await unregisterRunner(options)
55 } catch (err) {
56 logger.error('Cannot unregister this PeerTube runner.', err)
57 process.exit(-1)
58 }
59 })
60
61 program.command('list-registered')
62 .description('List registered PeerTube instances')
63 .action(async () => {
64 try {
65 await listRegistered()
66 } catch (err) {
67 logger.error('Cannot list registered PeerTube instances.', err)
68 process.exit(-1)
69 }
70 })
71
72 program.parse()
73
74 // ---------------------------------------------------------------------------
75 // Private
76 // ---------------------------------------------------------------------------
77
78 function parseUrl (url: string) {
79 if (url.startsWith('http://') !== true && url.startsWith('https://') !== true) {
80 throw new InvalidArgumentError('URL should start with a http:// or https://')
81 }
82
83 return url
84 }