Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3677 from LiskHQ/3676-commander_bug_fix
Browse files Browse the repository at this point in the history
commander core:install command hangs after installation - Closes #3676
  • Loading branch information
shuse2 authored May 21, 2019
2 parents a659220 + 2fda8c2 commit f085ad0
Show file tree
Hide file tree
Showing 17 changed files with 226 additions and 66 deletions.
36 changes: 22 additions & 14 deletions commander/src/commands/core/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ const installOptions = async (
const installVersion: string = await getVersionToInstall(
network,
liskVersion,
releaseUrl,
);

const { version, liskTarUrl, liskTarSHA256Url } = await getReleaseInfo(
Expand Down Expand Up @@ -292,22 +293,29 @@ export default class InstallCommand extends BaseCommand {

try {
const instance = await describeApplication(name);
this.log(`\n Lisk Core instance ${name} already installed: `);
this.print(instance);
} catch (error) {
try {
await tasks.run();
if (!noStart) {
return StartCommand.run([name]);
}
} catch (error) {
const { installDir }: Options = error.context.options;
const dirPath = installDir.substr(0, installDir.length - 1);
if (instance) {
this.log(`\n Lisk Core instance ${name} already installed: `);
this.print(instance);

fsExtra.emptyDirSync(installDir);
fsExtra.rmdirSync(dirPath);
this.error(JSON.stringify(error));
return;
}

await tasks.run();
if (!noStart) {
// tslint:disable-next-line await-promise
await StartCommand.run([name]);
const newInstance = await describeApplication(name);
this.print(newInstance);

return;
}
} catch (error) {
this.error(JSON.stringify(error));
const { installDir }: Options = error.context.options;
const dirPath = installDir.substr(0, installDir.length - 1);

fsExtra.emptyDirSync(installDir);
fsExtra.rmdirSync(dirPath);
}
}
}
14 changes: 12 additions & 2 deletions commander/src/commands/core/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import { flags as flagParser } from '@oclif/command';
import * as childProcess from 'child_process';
import BaseCommand from '../../base';
import { describeApplication } from '../../utils/core/pm2';
import { describeApplication, PM2ProcessInstance } from '../../utils/core/pm2';

interface Args {
readonly name: string;
Expand Down Expand Up @@ -50,7 +50,17 @@ export default class LogsCommand extends BaseCommand {
const { args } = this.parse(LogsCommand);
const { name } = args as Args;

const { installationPath, network } = await describeApplication(name);
const instance = await describeApplication(name);

if (!instance) {
this.log(
`Lisk Core instance: ${name} doesn't exists, Please install using lisk core:install`,
);

return;
}

const { installationPath, network } = instance as PM2ProcessInstance;
const fileName = `${installationPath}/logs/${network}/lisk.log`;

const tail = childProcess.spawn('tail', ['-f', fileName]);
Expand Down
19 changes: 12 additions & 7 deletions commander/src/commands/core/restart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
import { flags as flagParser } from '@oclif/command';
import BaseCommand from '../../base';
import { describeApplication } from '../../utils/core/pm2';
import StartCommand from './start';
import StopCommand from './stop';

Expand Down Expand Up @@ -49,14 +50,18 @@ export default class RestartCommand extends BaseCommand {
async run(): Promise<void> {
const { args } = this.parse(RestartCommand);
const { name } = args as Args;
const instance = await describeApplication(name);

try {
// tslint:disable-next-line await-promise
await StopCommand.run([name]);
// tslint:disable-next-line await-promise
await StartCommand.run([name]);
} catch (error) {
this.error(error);
if (!instance) {
this.log(
`Lisk Core instance: ${name} doesn't exists, Please install using lisk core:install`,
);

return;
}
// tslint:disable-next-line await-promise
await StopCommand.run([name]);
// tslint:disable-next-line await-promise
await StartCommand.run([name]);
}
}
17 changes: 15 additions & 2 deletions commander/src/commands/core/start/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import {
isCacheRunning,
startCache,
} from '../../../utils/core/cache';
import { describeApplication } from '../../../utils/core/pm2';
import {
describeApplication,
PM2ProcessInstance,
} from '../../../utils/core/pm2';

interface Args {
readonly name: string;
Expand Down Expand Up @@ -54,7 +57,17 @@ export default class CacheCommand extends BaseCommand {
async run(): Promise<void> {
const { args } = this.parse(CacheCommand);
const { name } = args as Args;
const { installationPath, network } = await describeApplication(name);
const instance = await describeApplication(name);

if (!instance) {
this.log(
`Lisk Core instance: ${name} doesn't exists, Please install using lisk core:install`,
);

return;
}

const { installationPath, network } = instance as PM2ProcessInstance;

const tasks = new Listr([
{
Expand Down
17 changes: 15 additions & 2 deletions commander/src/commands/core/start/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import { flags as flagParser } from '@oclif/command';
import Listr from 'listr';
import BaseCommand from '../../../base';
import { startDatabase } from '../../../utils/core/database';
import { describeApplication } from '../../../utils/core/pm2';
import {
describeApplication,
PM2ProcessInstance,
} from '../../../utils/core/pm2';

interface Args {
readonly name: string;
Expand Down Expand Up @@ -50,7 +53,17 @@ export default class DatabaseCommand extends BaseCommand {
async run(): Promise<void> {
const { args } = this.parse(DatabaseCommand);
const { name } = args as Args;
const { installationPath } = await describeApplication(name);
const instance = await describeApplication(name);

if (!instance) {
this.log(
`Lisk Core instance: ${name} doesn't exists, Please install using lisk core:install`,
);

return;
}

const { installationPath } = instance as PM2ProcessInstance;

const tasks = new Listr([
{
Expand Down
15 changes: 14 additions & 1 deletion commander/src/commands/core/start/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
import { flags as flagParser } from '@oclif/command';
import Listr from 'listr';
import BaseCommand from '../../../base';
import { restartApplication } from '../../../utils/core/pm2';
import {
describeApplication,
restartApplication,
} from '../../../utils/core/pm2';
import CacheCommand from './cache';
import DatabaseCommand from './database';

Expand Down Expand Up @@ -51,6 +54,15 @@ export default class StartCommand extends BaseCommand {
async run(): Promise<void> {
const { args } = this.parse(StartCommand);
const { name } = args as Args;
const instance = await describeApplication(name);

if (!instance) {
this.log(
`Lisk Core instance: ${name} doesn't exists, Please install using lisk core:install`,
);

return;
}

// tslint:disable-next-line await-promise
await CacheCommand.run([name]);
Expand All @@ -65,6 +77,7 @@ export default class StartCommand extends BaseCommand {
},
},
]);

await tasks.run();
}
}
7 changes: 7 additions & 0 deletions commander/src/commands/core/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ export default class StatusCommand extends BaseCommand {
if (name) {
const instance = await describeApplication(name);

if (!instance) {
this.log(
`Lisk Core instance: ${name} doesn't exists, Please install using lisk core:install`,
);

return;
}
this.print(instance);
} else {
const instances = await listApplication();
Expand Down
17 changes: 15 additions & 2 deletions commander/src/commands/core/stop/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import {
isCacheRunning,
stopCache,
} from '../../../utils/core/cache';
import { describeApplication } from '../../../utils/core/pm2';
import {
describeApplication,
PM2ProcessInstance,
} from '../../../utils/core/pm2';

interface Args {
readonly name: string;
Expand Down Expand Up @@ -54,7 +57,17 @@ export default class CacheCommand extends BaseCommand {
async run(): Promise<void> {
const { args } = this.parse(CacheCommand);
const { name } = args as Args;
const { installationPath, network } = await describeApplication(name);
const instance = await describeApplication(name);

if (!instance) {
this.log(
`Lisk Core instance: ${name} doesn't exists, Please install using lisk core:install`,
);

return;
}

const { installationPath, network } = instance as PM2ProcessInstance;

const tasks = new Listr([
{
Expand Down
17 changes: 15 additions & 2 deletions commander/src/commands/core/stop/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import { flags as flagParser } from '@oclif/command';
import Listr from 'listr';
import BaseCommand from '../../../base';
import { stopDatabase } from '../../../utils/core/database';
import { describeApplication } from '../../../utils/core/pm2';
import {
describeApplication,
PM2ProcessInstance,
} from '../../../utils/core/pm2';

interface Args {
readonly name: string;
Expand Down Expand Up @@ -50,7 +53,17 @@ export default class DatabaseCommand extends BaseCommand {
async run(): Promise<void> {
const { args } = this.parse(DatabaseCommand);
const { name } = args as Args;
const { installationPath } = await describeApplication(name);
const instance = await describeApplication(name);

if (!instance) {
this.log(
`Lisk Core instance: ${name} doesn't exists, Please install using lisk core:install`,
);

return;
}

const { installationPath } = instance as PM2ProcessInstance;

const tasks = new Listr([
{
Expand Down
11 changes: 10 additions & 1 deletion commander/src/commands/core/stop/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import { flags as flagParser } from '@oclif/command';
import Listr from 'listr';
import BaseCommand from '../../../base';
import { stopApplication } from '../../../utils/core/pm2';
import { describeApplication, stopApplication } from '../../../utils/core/pm2';
import CacheCommand from './cache';
import DatabaseCommand from './database';

Expand Down Expand Up @@ -51,6 +51,15 @@ export default class StopCommand extends BaseCommand {
async run(): Promise<void> {
const { args } = this.parse(StopCommand);
const { name } = args as Args;
const instance = await describeApplication(name);

if (!instance) {
this.log(
`Lisk Core instance: ${name} doesn't exists, Please install using lisk core:install`,
);

return;
}

// tslint:disable-next-line await-promise
await CacheCommand.run([name]);
Expand Down
19 changes: 17 additions & 2 deletions commander/src/commands/core/uninstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import { flags as flagParser } from '@oclif/command';
import * as fsExtra from 'fs-extra';
import Listr from 'listr';
import BaseCommand from '../../base';
import { describeApplication } from '../../utils/core/pm2';
import {
describeApplication,
PM2ProcessInstance,
unRegisterApplication,
} from '../../utils/core/pm2';
import StopCommand from './stop';

interface Args {
Expand Down Expand Up @@ -51,16 +55,27 @@ export default class UnInstallCommand extends BaseCommand {
async run(): Promise<void> {
const { args } = this.parse(UnInstallCommand);
const { name } = args as Args;
const { installationPath, network } = await describeApplication(name);

try {
const instance = await describeApplication(name);

if (!instance) {
this.log(
`Lisk Core instance: ${name} doesn't exists, Please install using lisk core:install`,
);

return;
}
// tslint:disable-next-line await-promise
await StopCommand.run([name]);

const { installationPath, network } = instance as PM2ProcessInstance;

const tasks = new Listr([
{
title: `Uninstall Lisk Core ${network} instance Installed as ${name}`,
task: async () => {
await unRegisterApplication(name);
fsExtra.removeSync(installationPath);
},
},
Expand Down
15 changes: 14 additions & 1 deletion commander/src/commands/core/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
import { startDatabase, stopDatabase } from '../../utils/core/database';
import {
describeApplication,
PM2ProcessInstance,
registerApplication,
restartApplication,
stopApplication,
Expand Down Expand Up @@ -90,14 +91,26 @@ export default class UpgradeCommand extends BaseCommand {
'lisk-version': liskVersion,
'release-url': releaseUrl,
} = flags as Flags;
const instance = await describeApplication(name);

if (!instance) {
this.log(
`Lisk Core instance: ${name} doesn't exists.\nTo upgrade first install using lisk core:install and then run lisk core:upgrade`,
);

return;
}

const {
installationPath,
network,
version: currentVersion,
} = await describeApplication(name);
} = instance as PM2ProcessInstance;

const upgradeVersion: string = await getVersionToInstall(
network,
liskVersion,
releaseUrl,
);
const { cacheDir } = this.config;
// TODO: Commander not creating cache directory
Expand Down
Loading

0 comments on commit f085ad0

Please sign in to comment.