-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbin.js
executable file
·63 lines (53 loc) · 1.42 KB
/
bin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#! /usr/bin/env node
'use strict'
const control = require('.')
const UpRing = require('upring')
const args = require('minimist')(process.argv.slice(2), {
alias: {
timeout: 't',
port: 'p',
points: 'P',
help: 'h',
version: 'V',
verbose: 'v'
},
default: {
points: 100,
timeout: 200,
port: 8008
}
})
if (args.help) {
console.log(`Usage: upring-control [OPTS] [BASE]
Options:
-t/--timeout MILLIS milliseconds to wait to join the ring, default 200
-p/--port PORT the port on which the control panel will be exposes, default 8008
-P/--points the number of points for each peer, default 100
-v/--verbose enable debug logs
-V/--version print the version number
-h/--help shows this help
`)
process.exit(1)
}
if (args.version) {
console.log('v' + require('./package').version)
process.exit(1)
}
const pinoHttp = require('pino-http')
const upring = UpRing({
client: true, // this does not provides services to the ring
logLevel: args.verbose ? 'debug' : 'info',
hashring: {
replicaPoints: args.points,
joinTimeout: args.timeout,
base: args._
}
})
const logger = pinoHttp({ logger: upring.logger })
const server = control(upring)
upring.on('up', () => {
server.on('request', logger)
server.listen(args.port, function () {
logger.logger.info('server listening on port %d', this.address().port)
})
})