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