mirror of
https://gitee.com/dromara/Jpom.git
synced 2024-12-02 11:58:01 +08:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
e8e30a8b5d
38
boot-line/command/run_boot.sh
Normal file → Executable file
38
boot-line/command/run_boot.sh
Normal file → Executable file
@ -4,17 +4,34 @@ Tag="$2"
|
||||
MainClass="$3"
|
||||
Lib="$4"
|
||||
Log="$5"
|
||||
Port="$6"
|
||||
#Token="$7"
|
||||
JVM="$7"
|
||||
|
||||
ARGS=""
|
||||
|
||||
for ((i=8; i<=$#; i++))
|
||||
do
|
||||
ARGS=${ARGS}" "${!i}
|
||||
done
|
||||
|
||||
|
||||
LogBack=$Log"../log/"
|
||||
|
||||
RETVAL="0"
|
||||
# See how we were called.
|
||||
start()
|
||||
{
|
||||
echo $Log
|
||||
|
||||
if [ ! -f $Log ]; then
|
||||
if [ ! -d $LogBack ];then
|
||||
mkdir $LogBack
|
||||
fi
|
||||
cur_dateTime="`date +%Y-%m-%d_%H:%M:%S`.log"
|
||||
mv $Log $LogBack$cur_dateTime
|
||||
echo "mv to $LogBack$cur_dateTime"
|
||||
touch $Log
|
||||
fi
|
||||
nohup java -Dappliction=$Tag -Djava.ext.dirs=$Lib":${JAVA_HOME}/jre/lib/ext" $MainClass > $Log 2>&1 & sleep 1s & status
|
||||
nohup java $JVM -Dappliction=$Tag -Djava.ext.dirs=$Lib":${JAVA_HOME}/jre/lib/ext" $MainClass $ARGS > $Log 2>&1 & sleep 1s & status
|
||||
}
|
||||
|
||||
stop()
|
||||
@ -22,13 +39,14 @@ stop()
|
||||
pid=$(ps -ef | grep "Dappliction=$Tag" | grep -v 'grep' | awk '{printf $2 " "}')
|
||||
if [ "$pid" != "" ]; then
|
||||
|
||||
# wget http://127.0.0.1:$Port/sys/shutdown?token=$Token
|
||||
if ["$6"!="no"]; then
|
||||
wget "$6"
|
||||
fi
|
||||
|
||||
pid=$(ps -ef | grep "Dappliction=$Tag" | grep -v 'grep' | awk '{printf $2 " "}')
|
||||
if [ "$pid" != "" ]; then
|
||||
|
||||
kill -9 "$pid"
|
||||
fi
|
||||
pid=$(ps -ef | grep "Dappliction=$Tag" | grep -v 'grep' | awk '{printf $2 " "}')
|
||||
if [ "$pid" != "" ]; then
|
||||
kill -9 "$pid"
|
||||
fi
|
||||
fi
|
||||
status
|
||||
}
|
||||
@ -48,7 +66,7 @@ status()
|
||||
|
||||
usage()
|
||||
{
|
||||
echo "Usage: $0 {start|stop|restart|status} tag mainclass lib log port token"
|
||||
echo "Usage: $0 {start|stop|restart|status} tag mainclass lib log token JVM args"
|
||||
RETVAL="2"
|
||||
}
|
||||
|
||||
|
4
pom.xml
4
pom.xml
@ -14,12 +14,14 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
|
||||
<common-boot.version>1.2.5</common-boot.version>
|
||||
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.jiangzeyin.fast-boot</groupId>
|
||||
<artifactId>common-boot</artifactId>
|
||||
<version>1.2.3</version>
|
||||
<version>${common-boot.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
@ -7,6 +7,7 @@ import org.springframework.boot.web.servlet.ServletComponentScan;
|
||||
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Created by jiangzeyin on 2017/9/14.
|
||||
@ -24,6 +25,7 @@ public class BootOnLineApplication {
|
||||
* @param args 参数
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.out.println("main 参数" + Arrays.toString(args));
|
||||
ApplicationBuilder.createBuilder(BootOnLineApplication.class)
|
||||
.addHttpMessageConverter(new StringHttpMessageConverter(Charset.forName("UTF-8")))
|
||||
.run(args);
|
||||
|
@ -88,21 +88,13 @@ public class LogWebSocketHandle implements TailLogThread.Evn {
|
||||
JSONObject json = JSONObject.parseObject(message);
|
||||
JSONObject projectInfo = json.getJSONObject("projectInfo");
|
||||
|
||||
String str_result = "";
|
||||
|
||||
// 项目启动信息
|
||||
String tag = projectInfo.getString("tag");
|
||||
String mainClass = projectInfo.getString("mainClass");
|
||||
String lib = projectInfo.getString("lib");
|
||||
String log = projectInfo.getString("log");
|
||||
int port = projectInfo.getInteger("port");
|
||||
String token = projectInfo.getString("token");
|
||||
String str_result;
|
||||
|
||||
// 执行相应命令
|
||||
switch (json.getString("op")) {
|
||||
case "start":
|
||||
// 启动项目
|
||||
str_result = execCommand(session, "start", tag, mainClass, lib, log, port, token);
|
||||
str_result = execCommand(session, "start", projectInfo);
|
||||
if (str_result.startsWith("running")) {
|
||||
sendMsg(session, JsonMessage.getString(200, "启动成功", json));
|
||||
} else {
|
||||
@ -112,12 +104,12 @@ public class LogWebSocketHandle implements TailLogThread.Evn {
|
||||
|
||||
case "restart":
|
||||
// 重启项目
|
||||
execCommand(session, "restart", tag, mainClass, lib, log, port, token);
|
||||
execCommand(session, "restart", projectInfo);
|
||||
break;
|
||||
|
||||
case "stop":
|
||||
// 停止项目
|
||||
str_result = execCommand(session, "stop", tag, mainClass, lib, log, port, token);
|
||||
str_result = execCommand(session, "stop", projectInfo);
|
||||
if (str_result.startsWith("stopped")) {
|
||||
sendMsg(session, JsonMessage.getString(200, "已停止", json));
|
||||
thread.stop();
|
||||
@ -128,7 +120,7 @@ public class LogWebSocketHandle implements TailLogThread.Evn {
|
||||
|
||||
case "status":
|
||||
// 获取项目状态
|
||||
str_result = execCommand(session, "status", tag, mainClass, lib, log, port, token);
|
||||
str_result = execCommand(session, "status", projectInfo);
|
||||
json.put("result", str_result);
|
||||
if (str_result.startsWith("running")) {
|
||||
sendMsg(session, JsonMessage.getString(200, "运行中", json));
|
||||
@ -139,6 +131,7 @@ public class LogWebSocketHandle implements TailLogThread.Evn {
|
||||
break;
|
||||
case "showlog":
|
||||
// 进入管理页面后需要实时加载日志
|
||||
String log = projectInfo.getString("log");
|
||||
try {
|
||||
// 执行tail -f命令
|
||||
process = Runtime.getRuntime().exec(String.format("tail -f %s", log));
|
||||
@ -163,21 +156,28 @@ public class LogWebSocketHandle implements TailLogThread.Evn {
|
||||
/**
|
||||
* 执行shell命令
|
||||
*
|
||||
* @param session 用于输出的websocket会话
|
||||
* @param op 执行的操作
|
||||
* @param tag
|
||||
* @param mainClass
|
||||
* @param lib
|
||||
* @param log
|
||||
* @param port
|
||||
* @param token
|
||||
* @param session 用于输出的websocket会话
|
||||
* @param op 执行的操作
|
||||
* @param projectInfo 项目信息
|
||||
*/
|
||||
private String execCommand(Session session, String op, String tag, String mainClass, String lib, String log, int port, String token) {
|
||||
private String execCommand(Session session, String op, JSONObject projectInfo) {
|
||||
InputStream is;
|
||||
String result = "error";
|
||||
String commandPath = SpringUtil.getEnvironment().getProperty("command.conf");
|
||||
|
||||
|
||||
// 项目启动信息
|
||||
String tag = projectInfo.getString("tag");
|
||||
String mainClass = projectInfo.getString("mainClass");
|
||||
String lib = projectInfo.getString("lib");
|
||||
String log = projectInfo.getString("log");
|
||||
|
||||
String token = projectInfo.getString("token");
|
||||
String jvm = projectInfo.getString("jvm");
|
||||
String args = projectInfo.getString("args");
|
||||
try {
|
||||
// 执行命令
|
||||
String command = String.format("%s %s %s %s %s %s %s", SpringUtil.getEnvironment().getProperty("command.conf"), op, tag, mainClass, lib, log, port);
|
||||
String command = String.format("%s %s %s %s %s %s %s %s %s", commandPath, op, tag, mainClass, lib, log, token, jvm, args);
|
||||
DefaultSystemLog.LOG().info(command);
|
||||
Process process = Runtime.getRuntime().exec(command);
|
||||
is = process.getInputStream();
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cn.jiangzeyin.system.log.aop;
|
||||
package cn.jiangzeyin.system;
|
||||
|
||||
import cn.jiangzeyin.common.DefaultSystemLog;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
@ -17,7 +17,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
public class WebLog {
|
||||
public class WebAopLog {
|
||||
private static final ThreadLocal<Boolean> IS_LOG = new ThreadLocal<>();
|
||||
|
||||
@Pointcut("execution(public * cn.jiangzeyin.controller..*.*(..))")
|
Loading…
Reference in New Issue
Block a user