Browse Source

服务器启动通用脚本

yq 3 years ago
parent
commit
7323fa79ae
2 changed files with 108 additions and 1 deletions
  1. 1 1
      技术分享/MybatisGeneratorUtils.java
  2. 107 0
      技术分享/bash.sh

+ 1 - 1
技术分享/MybatisGeneratorUtils.java

@@ -15,7 +15,7 @@ import java.util.List;
  * @author yq
  * @date 2021/7/6 11:42
  */
-public class TestUtils {
+public class MybatisGeneratorUtils {
     public static void main(String[] args) {
         //修改成自己的模块名称
         String[] models = {"test-controller", "test-service", "test-model", "test-persistence"};

+ 107 - 0
技术分享/bash.sh

@@ -0,0 +1,107 @@
+APP_NAME=/usr/local/service/$2/$2.jar
+TARGET_PATH=/apps/intelligent-family
+source /etc/profile
+BUILD_ID=dontKillMe
+
+#启动方法
+
+start(){
+
+        pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}'`
+
+        if [ "$pid" ]; then
+
+                echo "$APP_NAME is already running. pid=$pid ."
+
+        else
+
+
+                setsid java -jar $APP_NAME --spring.profiles.active=dev >> out.log 2>&1 &
+
+                sleep 10
+
+                echo "$APP_NAME now is running"
+
+        fi
+
+}
+
+#停止方法
+
+stop(){
+
+        pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}'`
+
+        if [ "$pid" ]; then
+
+                kill -9 $pid
+
+                echo "Pid:$pid stopped"
+
+        else
+
+                echo "$APP_NAME is not running"
+
+        fi
+
+}
+
+#输出运行状态
+
+status(){
+
+        pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}'`
+
+        if [ "$pid" ]; then
+
+                echo "$APP_NAME is running. Pid is ${pid}"
+
+        else
+
+                echo "$APP_NAME is NOT running."
+
+        fi
+
+}
+
+#根据输入参数,选择执行对应方法,不输入则执行使用说明
+
+case "$1" in
+
+        start)
+
+                start
+
+                ;;
+
+        stop)
+
+                stop
+
+                ;;
+
+        status)
+
+                status
+
+                ;;
+
+        restart)
+
+                stop
+
+                sleep 5
+
+                start
+
+                ;;
+
+      *)
+
+                echo "Usage:{start|stop|status|restart}"
+
+                ;;
+
+esac
+
+exit 0