This repository has been archived by the owner on Nov 14, 2019. It is now read-only.
/
start.ts
63 lines (56 loc) · 1.71 KB
/
start.ts
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
import {flags} from '@oclif/command'
import Command from '../../docker-command'
import version from '../../version'
import Status, {ServiceStatus} from './status'
export default class Start extends Command {
static description = 'Start the MESG Engine\'s daemon'
static flags = {
...Command.flags,
version: flags.string({
description: 'Version of the engine to run',
required: true,
default: version.engine
}),
'log-force-colors': flags.boolean({
description: 'log force colors',
default: false
}),
'log-format': flags.enum({
description: 'log format',
default: 'text',
options: ['text', 'json']
}),
'log-level': flags.enum({
description: 'log level',
default: 'info',
options: ['debug', 'info', 'warn', 'error', 'fatal', 'panic']
}),
}
async run() {
const {flags} = this.parse(Start)
const status = await Status.run(['--name', flags.name])
if (status === ServiceStatus.STARTED) {
return false
}
this.spinner.start('MESG Engine')
const eventPromise = this.waitForEvent(({Action, Type, from}) =>
Type === 'container' &&
Action === 'start' &&
from === `mesg/engine:${flags.version}`
)
this.spinner.status = 'Creating network'
const network = await this.getOrCreateNetwork({name: flags.name})
this.spinner.status = 'Creating service'
await this.createService(network, {
name: flags.name,
version: flags.version,
colors: flags['log-force-colors'],
format: flags['log-format'],
level: flags['log-level']
})
this.spinner.status = 'Waiting service to start'
await eventPromise
this.spinner.stop('Started')
return true
}
}