diff --git a/.gitignore b/.gitignore index 89c323cd..00ab9cab 100644 --- a/.gitignore +++ b/.gitignore @@ -116,3 +116,4 @@ buildNumber.properties basedir/ /.idea/ /phoenix_ddos_handle.iml +/src/main/resources/git.properties diff --git a/bin/log_clean.sh b/bin/log_clean.sh new file mode 100644 index 00000000..5a3fedc8 --- /dev/null +++ b/bin/log_clean.sh @@ -0,0 +1,3 @@ +# 把下面语句编辑到crontab里,定时清理日志,每天凌晨1点清理日志,保留7天日志 + +0 1 * * * find /apprun/phoenix_ddos_handle/logs -mtime +7 -name "*.log.*" -exec rm -rf {} \; \ No newline at end of file diff --git a/bin/processor_check.sh b/bin/processor_check.sh new file mode 100644 index 00000000..41eb310b --- /dev/null +++ b/bin/processor_check.sh @@ -0,0 +1,26 @@ +# crontab里加上进程自动拉起任务,做个简单的监控 +# */1 * * * * source /etc/profile;sh /apprun/${YOUR_APP_NAME}/bin/processor_check.sh +# processor_check.sh脚本内容如下 + +#!/bin/bash +APP_NAME=phoenix_ddos_handle.jar +WORK_PATH=$(cd `dirname $0`; pwd) + +pids=`ps -ef | grep $APP_NAME | grep -v grep | wc -l` +if [ "$pids" -le 0 ] +then + echo "start $APP_NAME processor ......" + cd $WORK_PATH + cd .. + nohup sh bin/start.sh >/dev/null 2>&1 & + sleep 5 + pids=`ps -ef | grep $APP_NAME | grep -v grep | wc -l` + if [ "$pids" -gt 0 ] + then + echo "$APP_NAME processor started" + else + echo "Failed to start $APP_NAME processor" + fi +else + echo "$APP_NAME processor is running ......" +fi \ No newline at end of file diff --git a/bin/start.sh b/bin/start.sh new file mode 100644 index 00000000..b32993d2 --- /dev/null +++ b/bin/start.sh @@ -0,0 +1,8 @@ +#!/bin/bash +JAVA_DEBUG_OPTS=" -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=n " +JAVA_JMX_OPTS=" -Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false " +JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom -server -Xms512M -Xmx512M -Xss256K -XX:MetaspaceSize=16M -XX:MaxMetaspaceSize=128M -XX:MaxDirectMemorySize=1g -XX:SurvivorRatio=8 -XX:+UseG1GC -XX:+ExplicitGCInvokesConcurrentAndUnloadsClasses -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp/heapdump.hprof" +WORK_PATH=$(cd `dirname $0`; pwd) +cd $WORK_PATH +cd .. +$JAVA_HOME/bin/java $JAVA_DEBUG_OPTS $JAVA_JMX_OPTS $JAVA_OPTS -jar phoenix_ddos_handle.jar diff --git a/bin/stop.sh b/bin/stop.sh new file mode 100644 index 00000000..b40b9cd8 --- /dev/null +++ b/bin/stop.sh @@ -0,0 +1,15 @@ +#!/bin/bash +APP_NAME=phoenix_ddos_handle.jar + +pids=`ps -ef | grep $APP_NAME | grep -v grep | awk '{print $2}'` +for pid in $pids +do + echo stop $APP_NAME java process: $pid + kill -9 $pid +done + +nr_pids=`ps -ef | grep $APP_NAME | grep -v grep | wc -l` +while [ $nr_pids -gt 0 ] +do + nr_pids=`ps -ef | grep $APP_NAME | grep -v grep | wc -l` +done \ No newline at end of file diff --git a/src/main/java/com/dispose/manager/impl/UserAccountCacheManagerImpl.java b/src/main/java/com/dispose/manager/impl/UserAccountCacheManagerImpl.java index df3883d0..85d7b73a 100644 --- a/src/main/java/com/dispose/manager/impl/UserAccountCacheManagerImpl.java +++ b/src/main/java/com/dispose/manager/impl/UserAccountCacheManagerImpl.java @@ -127,6 +127,7 @@ public class UserAccountCacheManagerImpl implements UserAccountCacheManager { // 用户不存在 if (!findRet.isPresent()) { + log.error("User {} not exists", username); return ErrorCode.ERR_LOGOUT; } @@ -134,17 +135,21 @@ public class UserAccountCacheManagerImpl implements UserAccountCacheManager { // 如果token为空说明用户没有登录 if (uc.getToken().length() == 0) { + log.error("User {} token is empty", username); return ErrorCode.ERR_LOGOUT; } // 判断用户访问时间间隔是否超时 if ((System.currentTimeMillis() - uc.getLastAccess()) >= ConstValue.GlobalConfigure.TOKEN_TIMEOUT_MS) { + log.error("User {} token is timeout: current {}, last access {}, timeout setting {}", + username, System.currentTimeMillis(), uc.getLastAccess(), ConstValue.GlobalConfigure.TOKEN_TIMEOUT_MS); return ErrorCode.ERR_TOKENTIMEOUT; } // 判断token是否正确 if (!uc.getToken().equals(token)) { + log.error("User {} token {} is error", username, token); return ErrorCode.ERR_TOKENNOTFOUND; } diff --git a/src/main/java/com/dispose/service/impl/UserAccountServiceImpl.java b/src/main/java/com/dispose/service/impl/UserAccountServiceImpl.java index 08c67e39..c6cda2b9 100644 --- a/src/main/java/com/dispose/service/impl/UserAccountServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/UserAccountServiceImpl.java @@ -124,9 +124,7 @@ public class UserAccountServiceImpl implements UserAccountService { // 注销 ErrorCode err = userAccountCacheManager.verifyUserLogin(username, token); - if (err == ErrorCode.ERR_OK) { - userAccountCacheManager.cleanUserToken(username); - } + userAccountCacheManager.cleanUserToken(username); return err; } diff --git a/src/test/java/com/dispose/controller/TaskControllerTest.java b/src/test/java/com/dispose/controller/TaskControllerTest.java index 80c88028..bfdd9d8e 100644 --- a/src/test/java/com/dispose/controller/TaskControllerTest.java +++ b/src/test/java/com/dispose/controller/TaskControllerTest.java @@ -3,6 +3,7 @@ package com.dispose.controller; import com.dispose.Global.InitTestEnvironment; import com.dispose.common.ConstValue; import com.dispose.common.DeviceCapacity; +import com.dispose.common.ErrorCode; import com.dispose.common.IPAddrType; import com.dispose.manager.TaskCacheManager; import com.dispose.mapper.DisposeDeviceMapper; @@ -38,6 +39,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; @@ -335,7 +337,6 @@ public class TaskControllerTest extends InitTestEnvironment { .getResponse() .getContentAsString(); - String regex = "\\A(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}\\z"; String msgContent = verifyRep(taskStopByIp, reqTimeStamp); System.out.print("msgContent=" + msgContent); @@ -345,29 +346,16 @@ public class TaskControllerTest extends InitTestEnvironment { List taskInfoList = taskStopByIpRsp.getItems(); for (TaskInfoData task : taskInfoList ) { - Assert.assertNotNull(task.getId()); - Assert.assertNotNull(task.getTaskId()); - Assert.assertNotNull(task.getStatus()); - Assert.assertNotNull(task.getMessage()); + if (task.getStatus() == ErrorCode.ERR_OK.getCode()) { + Assert.assertEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode()); + Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg()); - if (task.getStatus() == 0) { - Assert.assertEquals(String.valueOf(task.getStatus()), "0"); - Assert.assertEquals(task.getMessage(), "成功"); + Assert.assertNotNull(task.getId()); + Assert.assertNotNull(task.getTaskId()); + Assert.assertNotNull(task.getStatus()); + Assert.assertNotNull(task.getMessage()); } else { - Assert.assertNotEquals(String.valueOf(task.getStatus()), "0"); - Assert.assertNotEquals(task.getMessage(), "成功"); - } - - if (task.getType() != null) { - Assert.assertNotEquals(String.valueOf(task.getType()), -1); - } - - if (task.getDisposeIp() != null) { - Assert.assertTrue(task.getDisposeIp().matches(regex)); - } - - if (task.getDisposeTime() != null) { - Assert.assertNotEquals(String.valueOf(task.getDisposeTime()), -1); + Assert.assertNotEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode()); } } }