|
@@ -1,141 +0,0 @@
|
|
-package cn.com.qmth.examcloud.config.center;
|
|
|
|
-
|
|
|
|
-import cn.com.qmth.examcloud.commons.helpers.BlackHolePrintStreamBuilder;
|
|
|
|
-import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
|
|
|
|
-import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
|
|
|
|
-import cn.com.qmth.examcloud.config.center.core.BootstrapSecurityManager;
|
|
|
|
-import cn.com.qmth.examcloud.config.center.core.CommandInterpreter;
|
|
|
|
-import cn.com.qmth.examcloud.config.center.core.ConfigCenterBootstrap;
|
|
|
|
-import org.apache.commons.compress.utils.IOUtils;
|
|
|
|
-import org.apache.commons.lang3.ArrayUtils;
|
|
|
|
-import org.apache.logging.log4j.ThreadContext;
|
|
|
|
-import org.jline.reader.LineReader;
|
|
|
|
-import org.jline.reader.LineReaderBuilder;
|
|
|
|
-import org.jline.terminal.Terminal;
|
|
|
|
-import org.jline.terminal.TerminalBuilder;
|
|
|
|
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
|
|
-import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
|
|
-import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
|
|
|
-import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
|
|
|
-import org.springframework.context.annotation.ComponentScan;
|
|
|
|
-import org.springframework.context.annotation.Configuration;
|
|
|
|
-
|
|
|
|
-import java.io.IOException;
|
|
|
|
-import java.io.PrintStream;
|
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * 配置中心启动类
|
|
|
|
- *
|
|
|
|
- * @author WANGWEI
|
|
|
|
- * @date 2019年3月29日
|
|
|
|
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
|
|
|
|
- */
|
|
|
|
-@SpringBootApplication(exclude = {RedisAutoConfiguration.class, DataSourceAutoConfiguration.class})
|
|
|
|
-@ComponentScan(basePackages = {"cn.com.qmth"})
|
|
|
|
-public class ConfigCenterStarter {
|
|
|
|
-
|
|
|
|
- private static PrintStream stdOut = null;
|
|
|
|
-
|
|
|
|
- private static PrintStream stdErrOut = null;
|
|
|
|
-
|
|
|
|
- private static PrintStream blackHoleOut = null;
|
|
|
|
-
|
|
|
|
- private static Long action = System.currentTimeMillis();
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 启动方法
|
|
|
|
- */
|
|
|
|
- public static void run(String[] args) {
|
|
|
|
- ExamCloudLog log = ExamCloudLogFactory.getLog(ConfigCenterStarter.class);
|
|
|
|
- ThreadContext.put("TRACE_ID", Thread.currentThread().getName());
|
|
|
|
- log.info("Starting...");
|
|
|
|
-
|
|
|
|
- blackHoleOut = BlackHolePrintStreamBuilder.build();
|
|
|
|
- stdOut = System.out;
|
|
|
|
- stdErrOut = System.err;
|
|
|
|
-
|
|
|
|
- Terminal terminal = null;
|
|
|
|
- LineReader reader = null;
|
|
|
|
- try {
|
|
|
|
- System.setOut(blackHoleOut);
|
|
|
|
- System.setErr(blackHoleOut);
|
|
|
|
- terminal = TerminalBuilder.terminal();
|
|
|
|
- reader = LineReaderBuilder.builder().terminal(terminal).build();
|
|
|
|
- System.setOut(stdOut);
|
|
|
|
- System.setErr(stdErrOut);
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- System.setOut(stdOut);
|
|
|
|
- System.setErr(stdErrOut);
|
|
|
|
- IOUtils.closeQuietly(terminal);
|
|
|
|
- e.printStackTrace();
|
|
|
|
- System.exit(-1);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- int errCount = 1;
|
|
|
|
-
|
|
|
|
- String secretKey;
|
|
|
|
- while (true) {
|
|
|
|
- try {
|
|
|
|
- secretKey = reader.readLine("Enter secret key>", (char) 0);
|
|
|
|
- System.setOut(blackHoleOut);
|
|
|
|
- System.setErr(blackHoleOut);
|
|
|
|
- args = ArrayUtils.add(args, "--examcloud.startup.secretKey=" + secretKey);
|
|
|
|
-
|
|
|
|
- ConfigCenterBootstrap.run(ConfigCenterStarter.class, args);
|
|
|
|
- System.setOut(stdOut);
|
|
|
|
- System.setErr(stdErrOut);
|
|
|
|
- break;
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- System.setOut(stdOut);
|
|
|
|
- System.setErr(stdErrOut);
|
|
|
|
- System.out.println(e.getMessage());
|
|
|
|
-
|
|
|
|
- if (errCount > 5) {
|
|
|
|
- System.out.println("Too many wrong, exit!");
|
|
|
|
- System.exit(0);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- System.out.println("Try again...");
|
|
|
|
- errCount++;
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- System.out.println("Ok, running...");
|
|
|
|
- String active = BootstrapSecurityManager.getInstance().getActive();
|
|
|
|
- System.out.println("Env active = " + active);
|
|
|
|
-
|
|
|
|
- new Thread(() -> {
|
|
|
|
- while (true) {
|
|
|
|
- if (System.currentTimeMillis() - action > CommandInterpreter.getInstance()
|
|
|
|
- .getSessionTimeout()) {
|
|
|
|
- System.exit(0);
|
|
|
|
- }
|
|
|
|
- try {
|
|
|
|
- TimeUnit.SECONDS.sleep(5);
|
|
|
|
- } catch (InterruptedException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }).start();
|
|
|
|
-
|
|
|
|
- IOUtils.closeQuietly(blackHoleOut);
|
|
|
|
- action = System.currentTimeMillis();
|
|
|
|
-
|
|
|
|
- while (true) {
|
|
|
|
- action = System.currentTimeMillis();
|
|
|
|
- String cmd = reader.readLine("$>");
|
|
|
|
- if (cmd.equals("exit") || cmd.equals("quit")) {
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- CommandInterpreter.getInstance().interpret(cmd);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- IOUtils.closeQuietly(terminal);
|
|
|
|
- System.exit(0);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|