diff options
author | Chocobozzz <me@florianbigard.com> | 2023-04-21 15:05:27 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2023-05-09 08:57:34 +0200 |
commit | 1772b383de490cf406fe93ef3aa3a941f6db513c (patch) | |
tree | 7cecc404c8d71951c22079e9bf5180095981b7f9 /packages/peertube-runner/peertube-runner.ts | |
parent | 118626c8752bee7b05c4e0b668852e1aba2416f1 (diff) | |
download | PeerTube-1772b383de490cf406fe93ef3aa3a941f6db513c.tar.gz PeerTube-1772b383de490cf406fe93ef3aa3a941f6db513c.tar.zst PeerTube-1772b383de490cf406fe93ef3aa3a941f6db513c.zip |
Add peertube runner cli
Diffstat (limited to 'packages/peertube-runner/peertube-runner.ts')
-rw-r--r-- | packages/peertube-runner/peertube-runner.ts | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/packages/peertube-runner/peertube-runner.ts b/packages/peertube-runner/peertube-runner.ts new file mode 100644 index 000000000..6bfd9ac0f --- /dev/null +++ b/packages/peertube-runner/peertube-runner.ts | |||
@@ -0,0 +1,84 @@ | |||
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 | console.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 | console.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 | console.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 | console.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 | } | ||