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'
6 const program = new Command()
9 'Runner server id, so you can run multiple PeerTube server runners with different configurations on the same machine',
12 .option('--verbose', 'Run in verbose mode')
13 .hook('preAction', thisCommand => {
14 const options = thisCommand.opts()
16 ConfigManager.Instance.init(options.id)
18 if (options.verbose === true) {
19 logger.level = 'debug'
23 program.command('server')
24 .description('Run in server mode, to execute remote jobs of registered PeerTube instances')
27 await RunnerServer.Instance.run()
29 console.error('Cannot run PeerTube runner as server mode', err)
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 => {
42 await registerRunner(options)
44 console.error('Cannot register this PeerTube runner.', err)
49 program.command('unregister')
50 .description('Unregister the runner from PeerTube instance')
51 .requiredOption('--url <url>', 'PeerTube instance URL', parseUrl)
52 .action(async options => {
54 await unregisterRunner(options)
56 console.error('Cannot unregister this PeerTube runner.', err)
61 program.command('list-registered')
62 .description('List registered PeerTube instances')
65 await listRegistered()
67 console.error('Cannot list registered PeerTube instances.', err)
74 // ---------------------------------------------------------------------------
76 // ---------------------------------------------------------------------------
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://')