]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - packages/peertube-runner/peertube-runner.ts
Fix dropdown item in RTL
[github/Chocobozzz/PeerTube.git] / packages / peertube-runner / peertube-runner.ts
CommitLineData
8d5ffb01
C
1#!/usr/bin/env node
2
1772b383
C
3import { Command, InvalidArgumentError } from '@commander-js/extra-typings'
4import { listRegistered, registerRunner, unregisterRunner } from './register'
5import { RunnerServer } from './server'
6import { ConfigManager, logger } from './shared'
7
5b2ee4e6
C
8const packageJSON = require('./package.json')
9
1772b383 10const 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
28program.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) {
3a0c2a77 34 logger.error('Cannot run PeerTube runner as server mode', err)
1772b383
C
35 process.exit(-1)
36 }
37 })
38
39program.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) {
3a0c2a77 49 logger.error('Cannot register this PeerTube runner.', err)
1772b383
C
50 process.exit(-1)
51 }
52 })
53
54program.command('unregister')
55 .description('Unregister the runner from PeerTube instance')
56 .requiredOption('--url <url>', 'PeerTube instance URL', parseUrl)
57 .action(async options => {
58 try {
59 await unregisterRunner(options)
60 } catch (err) {
3a0c2a77 61 logger.error('Cannot unregister this PeerTube runner.', err)
1772b383
C
62 process.exit(-1)
63 }
64 })
65
66program.command('list-registered')
67 .description('List registered PeerTube instances')
68 .action(async () => {
69 try {
70 await listRegistered()
71 } catch (err) {
3a0c2a77 72 logger.error('Cannot list registered PeerTube instances.', err)
1772b383
C
73 process.exit(-1)
74 }
75 })
76
77program.parse()
78
79// ---------------------------------------------------------------------------
80// Private
81// ---------------------------------------------------------------------------
82
83function parseUrl (url: string) {
84 if (url.startsWith('http://') !== true && url.startsWith('https://') !== true) {
85 throw new InvalidArgumentError('URL should start with a http:// or https://')
86 }
87
88 return url
89}