Skip to content

Commit

Permalink
Crust command line (#65)
Browse files Browse the repository at this point in the history
* use cmd to replace service

* better help

* put karst into crust cmd

* change default port

* change launch order

* add is running flag

* new start and stop cmd

* fix base path error

* remove some extra logs

* change some logs

* realize status cmd

* add yes in apt install
  • Loading branch information
LowEntropyBody authored Sep 25, 2020
1 parent aa9a305 commit 59b5a94
Show file tree
Hide file tree
Showing 15 changed files with 374 additions and 203 deletions.
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,24 @@ sudo ./install.sh
sudo vim /opt/crust/crust-node/config.yaml
```

### Run crust service and karst service
### Run service

- Please make sure the following ports are not occupied before starting:
- 30333 9933 9944 (for crust chain)
- 30888 19933 19944 (for crust chain)
- 56666 (for crust API)
- 12222 (for crust sWorker)
- 17000 (for karst)


```shell
sudo systemctl start karst # if you set karst 'enable' in config.yaml
sudo systemctl start crust
sudo crust start
sudo crust status
```

### Stop crust service and karst service
- Need to stop crust first, then stop karst
### Stop service

```shell
sudo systemctl stop crust
sudo systemctl stop karst # if you set karst 'enable' in config.yaml
sudo crust stop
```

## License
Expand Down
5 changes: 2 additions & 3 deletions generator/config-gen/api-config.gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ async function genApiConfig(config, outputCfg) {
async function genApiComposeConfig(config) {
const args = [
'56666',
`ws://127.0.0.1:9944`,
`ws://127.0.0.1:19944`,
].join(' ')
return {
image: 'crustio/crust-api:latest',
network_mode: 'host',
environment: {
ARGS: args,
},
depends_on: ['crust']
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions generator/config-gen/chain-config.gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ async function genChainComposeConfig(config) {
'--chain',
'maxwell',
'--port',
'30333',
'30888',
'--name',
`${config.chain.name}`,
'--rpc-port',
'9933',
'19933',
'--ws-port',
'9944',
'19944',
]

if (config.node.chain == "authority") {
Expand Down
8 changes: 4 additions & 4 deletions generator/config-gen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ async function genConfig(config, outputOpts) {
if (!config[cg.name]) {
continue
}
logger.info('generating config for %s', cg.name)
const ret = await cg.configFunc(config, outputOpts)
await writeConfig(path.join(baseDir, cg.to), ret.config)
outputs.push({
generator: cg.name,
...ret,
})
}
logger.info('done generating application configs')

logger.info('Generating configurations done')
return outputs
}

Expand All @@ -88,7 +88,6 @@ async function genComposeConfig(config) {
if (!config[cg.name]) {
continue
}
logger.info('generating compose config for %s', cg.name)
const cfg = await cg.composeFunc(config)
cfg["container_name"] = cg.composeName
output = {
Expand All @@ -100,7 +99,8 @@ async function genComposeConfig(config) {
}
}

logger.info('done generating compose configs')
logger.info('Generating docker compose file done')

return output
}

Expand Down
1 change: 1 addition & 0 deletions generator/config-gen/sworker-config.gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { getSharedChainConfig } = require('./chain-config.gen')
async function genSworkerConfig(config, outputCfg) {
const sworkerConfig = {
..._.omit(config.sworker, ['port']),
base_path: `/opt/crust/data/sworker`,
base_url: `http://0.0.0.0:12222/api/v0`,
karst_url: `ws://127.0.0.1:17000/api/v0/node/data`,
chain: getSharedChainConfig(config),
Expand Down
14 changes: 3 additions & 11 deletions generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,39 @@ const { logger } = require('./logger')
const { inspectKey } = require('./key-utils')
const { writeYaml } = require('./utils')

console.log('crust config generator')
console.log('Crust config generator')

async function loadConfig(file) {
logger.debug('loading config file: %s', file)
logger.debug('Loading config file: %s', file)
const c = await fs.readFile('config.yaml', 'utf8')
const config = yaml.safeLoad(c)
const configSchema = getConfigSchema(config)
const value = await configSchema.validateAsync(config, {
allowUnknown: true,
stripUnknown: true,
})
logger.debug('get config: %o', value)

if (value.node.sworker == "enable") {
const keyInfo = await inspectKey(value.identity.backup.address)
logger.info('key info: %o', keyInfo)
value.identity.account_id = keyInfo.accountId
}

const data = await genConfig(value, {
baseDir: '.tmp',
})
logger.info('application configs generated, %o', data)
const composeConfig = await genComposeConfig(value)
logger.info('compose config generated: %o', composeConfig)
logger.info('writing compose config')
await writeYaml(path.join('.tmp','docker-compose.yaml'), composeConfig)
logger.info('compose config generated')
await dumpConfigPaths(path.join('.tmp', '.paths'), data)
}

async function dumpConfigPaths(toFile, data) {
logger.info("data", data)
const paths = _(data).map(d => _.get(d, 'paths', [])).flatten().map(p => {
let mark = '|'
if (p.required) {
mark = '+'
}
return `${mark} ${p.path}`
}).uniq()
logger.debug('paths to validate', paths.value())

await fs.outputFile(toFile, paths.join('\n'))
}
Expand All @@ -67,7 +59,7 @@ async function main(){
try {
await loadConfig(getConfigFileName())
} catch(e) {
logger.error('failed to load config: %o', e)
logger.error('failed to load config: %o', e.message)
process.exit(1)
}
}
Expand Down
5 changes: 1 addition & 4 deletions generator/key-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ async function inspectKey(address) {
if (!keyTool) {
throw 'key tool path not specified'
}
logger.info('checking identity information, using keytool: %s', keyTool)
const {stdout} = await execa(keyTool, ['inspect', address]);
logger.debug('keytool output: %s', stdout)

const rows = _.chain(stdout).split('\n').map(_.trim)
const accountId = extractAccountId(rows)
logger.info('accountId: %s', accountId)
if (!accountId) {
logger.warn('invalid address: %s!', address)
logger.warn('Invalid address: %s!', address)
throw `address is invalid ${address}`
}
return {
Expand Down
7 changes: 3 additions & 4 deletions generator/schema/identity.schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const backupSchema = Joi.object({
version: Joi.string().required(),
}).required(),
meta: Joi.object({
genesisHash: Joi.string().length(66).regex(/^0x[0-9a-f]+$/).required(),
genesisHash: Joi.string().length(66).regex(/^0x[0-9a-f]+$/).allow(null),
name: Joi.string().required(),
tags: Joi.array().items(Joi.string()),
whenCreated: Joi.date().timestamp().raw(),
Expand All @@ -21,15 +21,14 @@ const backupSchema = Joi.object({
const identitySchema = Joi.object({
backup: Joi.string().custom((value, helpers) => {
try {
logger.info('value: %s', value)
const result = backupSchema.validate(JSON.parse(value))
if (result.error) {
return helpers.error(result.error)
}
return result.value
} catch(ex) {
logger.error('failed to parse json: %s', ex)
return helpers.error('backup is not a valid json string')
logger.error('Failed to parse json: %s', ex)
return helpers.error('Backup is not a valid json string')
}
}).required(),
password: Joi.string().min(1).required(),
Expand Down
8 changes: 3 additions & 5 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if [ $? -ne 0 ]; then
log_err "Install docker failed"
exit 1
fi
apt install docker-compose
apt install -y docker-compose
if [ $? -ne 0 ]; then
log_err "Install docker compose failed"
exit 1
Expand Down Expand Up @@ -67,9 +67,7 @@ cp -r $basedir/scripts $installdir/
cp -r $basedir/etc $installdir/
cp $basedir/config.yaml $installdir/

echo "Install crust and karst service"
cp $basedir/services/crust.service /lib/systemd/system/
cp $basedir/services/karst.service /lib/systemd/system/
systemctl daemon-reload
echo "Install crust command line tool"
cp $scriptdir/crust.sh /usr/bin/crust

log_success "------------Install success-------------"
Loading

0 comments on commit 59b5a94

Please sign in to comment.