diff --git a/src/commands/server/start.ts b/src/commands/server/start.ts new file mode 100644 index 000000000..7fc5fa88b --- /dev/null +++ b/src/commands/server/start.ts @@ -0,0 +1,105 @@ +/********************************************************************* + * Copyright (c) 2019 Red Hat, Inc. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + **********************************************************************/ + +import { Command, flags } from '@oclif/command' +import { string } from '@oclif/parser/lib/flags' +import { cli } from 'cli-ux' +import * as Listr from 'listr' +import * as notifier from 'node-notifier' + +import { DEFAULT_K8S_POD_ERROR_RECHECK_TIMEOUT, DEFAULT_K8S_POD_TIMEOUT } from '../../api/kube' +import { cheDeployment, cheNamespace, listrRenderer, skipKubeHealthzCheck as skipK8sHealthCheck } from '../../common-flags' +import { CheTasks } from '../../tasks/che' +import { getPrintHighlightedMessagesTask } from '../../tasks/installers/common-tasks' +import { ApiTasks } from '../../tasks/platforms/api' +import { getCommandFailMessage, getCommandSuccessMessage, initializeContext } from '../../util' + +export default class Start extends Command { + static description = 'start Eclipse Che server' + + static flags: flags.Input = { + help: flags.help({ char: 'h' }), + chenamespace: cheNamespace, + 'listr-renderer': listrRenderer, + 'deployment-name': cheDeployment, + k8spodwaittimeout: string({ + description: 'Waiting time for Pod scheduled condition (in milliseconds)', + default: `${DEFAULT_K8S_POD_TIMEOUT}` + }), + k8spoddownloadimagetimeout: string({ + description: 'Waiting time for Pod downloading image (in milliseconds)', + default: `${DEFAULT_K8S_POD_TIMEOUT}` + }), + k8spodreadytimeout: string({ + description: 'Waiting time for Pod Ready condition (in milliseconds)', + default: `${DEFAULT_K8S_POD_TIMEOUT}` + }), + k8spoderrorrechecktimeout: string({ + description: 'Waiting time for Pod rechecking error (in milliseconds)', + default: `${DEFAULT_K8S_POD_ERROR_RECHECK_TIMEOUT}` + }), + directory: string({ + char: 'd', + description: 'Directory to store logs into', + env: 'CHE_LOGS' + }), + 'skip-kubernetes-health-check': skipK8sHealthCheck, + } + + async run() { + const { flags } = this.parse(Start) + const ctx = await initializeContext(flags) + + const cheTasks = new CheTasks(flags) + const apiTasks = new ApiTasks() + + // Checks if Eclipse Che is already deployed + const preInstallTasks = new Listr([ + apiTasks.testApiTasks(flags, this), + { + title: '👀 Looking for an already existing Eclipse Che instance', + task: () => new Listr(cheTasks.checkIfCheIsInstalledTasks(flags, this)) + }], ctx.listrOptions) + + const logsTasks = new Listr([{ + title: 'Start following Eclipse Che logs', + task: () => new Listr(cheTasks.serverLogsTasks(flags, true)) + }], ctx.listrOptions) + + const startDeployedCheTasks = new Listr([{ + title: 'Starting already deployed Eclipse Che', + task: () => new Listr(cheTasks.scaleCheUpTasks()) + }], ctx.listrOptions) + + try { + await preInstallTasks.run(ctx) + + if (!ctx.isCheDeployed) { + cli.warn('Eclipse Che has not been deployed yet. Use server:deploy command to deploy a new Eclipse Che instance.') + } else if (ctx.isCheReady) { + cli.info('Eclipse Che has been already started.') + } else { + await logsTasks.run(ctx) + await startDeployedCheTasks.run(ctx) + this.log(getCommandSuccessMessage(this, ctx)) + } + } catch (err) { + this.error(`${err}\n${getCommandFailMessage(this, ctx)}`) + } + + notifier.notify({ + title: 'chectl', + message: getCommandSuccessMessage(this, ctx) + }) + + this.exit(0) + } + +}