Linux java 通过shell脚本一键启动多个jar包

8 篇文章 0 订阅

这里使用shell脚本,按照我下面的稍微修改一下举行了

#!/bin/sh
export EUREKA=medicine-registry-1.0-SNAPSHOT.jar
export USER=medicine-user-service-1.0-SNAPSHOT.jar
export GATEWAY=medicine-gateway-1.0-SNAPSHOT.jar
export AUTH=medicine-auth-service-1.0-SNAPSHOT.jar

export COMMON=medicine-common-service-1.0-SNAPSHOT.jar
export ORDER=medicine-order-service-1.0-SNAPSHOT.jar
export TASK=medicine-task-service-1.0-SNAPSHOT.jar
export UPLOAD=medicine-upload-1.0-SNAPSHOT.jar
export PRODUCT=medicine-product-service-1.0-SNAPSHOT.jar
export QUALIFICATION=medicine-qualification-service-1.0-SNAPSHOT.jar
export SMS=medicine-sms-1.0-SNAPSHOT.jar


#qualification

export EUREKA_port=10086
export USER_port=8005
export GATEWAY_port=10010
export AUTH_port=8007

export COMMON_port=8084
export ORDER_port=8081
export TASK_port=8088
export UPLOAD_port=8002

export PRODUCT_port=8083
export QUALIFICATION_port=8006
export SMS_port=8009

case "$1" in
 
start)
        ## 启动eureka
        echo "--------eureka 开始启动--------------"
        nohup java -Xms256m -Xmx512m -jar $EUREKA >/www/wwwroot/medicine/log/eureka.out &
        EUREKA_pid=`lsof -i:$EUREKA_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$EUREKA_pid" ]
            do
              EUREKA_pid=`lsof -i:$EUREKA_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "EUREKA pid is $EUREKA_pid" 
        echo "--------eureka 启动成功--------------"

            ## 启动gateway
        echo "--------开始启动GATEWAY---------------"
        nohup java -Xms256m -Xmx512m -jar $GATEWAY >/www/wwwroot/medicine/log/gateway.out &
        GATEWAY_pid=`lsof -i:$GATEWAY_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$GATEWAY_pid" ]
            do
              GATEWAY_pid=`lsof -i:$GATEWAY_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "GATEWAY pid is $GATEWAY_pid"    
        echo "---------GATEWAY 启动成功-----------"


         ## 启动auth
        echo "--------开始启动AUTH---------------"
        nohup java -Xms256m -Xmx512m -jar $AUTH >/www/wwwroot/medicine/log/auth.out &
        AUTH_pid=`lsof -i:$AUTH_port|grep "LISTEN"|awk '{print $2}'`
        # until [ -n "$AUTH_pid" ]
        #     do
        #       AUTH_pid=`lsof -i:$AUTH_port|grep "LISTEN"|awk '{print $2}'`  
        #     done
        sleep 10
        echo "AUTH pid is $AUTH_pid"     
        echo "---------AUTH 启动成功-----------"

        
        ## 启动USER
        echo "--------开始启动USER---------------"
        nohup java -Xms512m -Xmx1024m -jar $USER >/www/wwwroot/medicine/log/user.out &
        USER_pid=`lsof -i:$USER_port|grep "LISTEN"|awk '{print $2}'` 
        # until [ -n "$USER_pid" ]
        #     do
        #       USER_pid=`lsof -i:$USER_port|grep "LISTEN"|awk '{print $2}'`  
        #     done
        sleep 10   
        echo "USER pid is $USER_pid"     
        echo "---------USER 启动成功-----------"     
        

         ## 启动common
        echo "--------common 开始启动--------------"
        nohup java -Xms256m -Xmx512m -jar $COMMON >/www/wwwroot/medicine/log/common.out &
        COMMON_pid=`lsof -i:$COMMON_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$EUREKA_pid" ]
            do
              COMMON_pid=`lsof -i:$COMMON_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "COMMON pid is $COMMON_pid" 
        echo "--------common 启动成功--------------"

        ## 启动order
        echo "--------开始启动order---------------"
        nohup java -Xms512m -Xmx1024m -jar $ORDER >/www/wwwroot/medicine/log/order.out &
        ORDER_pid=`lsof -i:$ORDER_port|grep "LISTEN"|awk '{print $2}'`
        until [ -n "$ORDER_pid" ]
            do
              ORDER_pid=`lsof -i:$ORDER_port|grep "LISTEN"|awk '{print $2}'`  
            done
        echo "ORDER pid is $ORDER_pid"    
        echo "---------ORDER 启动成功-----------"


         ## 启动task
        echo "--------开始启动TASK---------------"
        nohup java -Xms512m -Xmx1024m -jar $TASK >/www/wwwroot/medicine/log/task.out &
        TASK_pid=`lsof -i:$TASK_port|grep "LISTEN"|awk '{print $2}'`
        # until [ -n "$AUTH_pid" ]
        #     do
        #       AUTH_pid=`lsof -i:$AUTH_port|grep "LISTEN"|awk '{print $2}'`  
        #     done
        sleep 10
        echo "TASK pid is $TASK_pid"     
        echo "---------TASK 启动成功-----------"

        
     
        ## 启动UPLOAD
        echo "--------开始启动UPLOAD---------------"
        nohup java -Xms256m -Xmx512m -jar $UPLOAD >/www/wwwroot/medicine/log/upload.out &
        UPLOAD_pid=`lsof -i:$UPLOAD_port|grep "LISTEN"|awk '{print $2}'` 
        # until [ -n "$USER_pid" ]
        #     do
        #       USER_pid=`lsof -i:$USER_port|grep "LISTEN"|awk '{print $2}'`  
        #     done
        sleep 10   
        echo "USER pid is $UPLOAD_pid"     
        echo "---------UPLOAD 启动成功-----------"     
   

        ## 启动PRODUCT
        echo "--------开始启动PRODUCT---------------"
        nohup java -Xms256m -Xmx512m -jar $PRODUCT >/www/wwwroot/medicine/log/product.out &
        PRODUCT_pid=`lsof -i:$PRODUCT_port|grep "LISTEN"|awk '{print $2}'` 
        # until [ -n "$USER_pid" ]
        #     do
        #       USER_pid=`lsof -i:$USER_port|grep "LISTEN"|awk '{print $2}'`  
        #     done
        sleep 10    
        echo "PRODUCT pid is $PRODUCT_pid"     
        echo "---------PRODUCT 启动成功-----------"     

      
        ## 启动qualification
        echo "--------开始启动QUALIFICATION---------------"
        nohup java -Xms256m -Xmx512m -jar $QUALIFICATION >/www/wwwroot/medicine/log/qualification.out &
        QUALIFICATION_pid=`lsof -i:$QUALIFICATION_port|grep "LISTEN"|awk '{print $2}'` 
        # until [ -n "$USER_pid" ]
        #     do
        #       USER_pid=`lsof -i:$USER_port|grep "LISTEN"|awk '{print $2}'`  
        #     done
        sleep 10    
        echo "QUALIFICATION pid is $QUALIFICATION_pid"     
        echo "---------QUALIFICATION 启动成功-----------" 

         ## 启动sms
        echo "--------开始启动QUALIFICATION---------------"
        nohup java -Xms256m -Xmx512m -jar $SMS >/www/wwwroot/medicine/log/sms.out &
        SMS_pid=`lsof -i:$SMS_port|grep "LISTEN"|awk '{print $2}'` 
        # until [ -n "$USER_pid" ]
        #     do
        #       USER_pid=`lsof -i:$USER_port|grep "LISTEN"|awk '{print $2}'`  
        #     done
        sleep 10    
        echo "SMS pid is $SMS_pid"     
        echo "---------SMS 启动成功-----------" 


        echo "===startAll success==="  
        ;;
 
 stop)
        P_ID=`ps -ef | grep -w $EUREKA | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===EUREKA process not exists or stop success"
        else
            kill -9 $P_ID
            echo "EUREKA killed success"
        fi
		P_ID=`ps -ef | grep -w $USER | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===USER process not exists or stop success"
        else
            kill -9 $P_ID
            echo "USER killed success"
        fi
		 P_ID=`ps -ef | grep -w $GATEWAY | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===GATEWAY process not exists or stop success"
        else
            kill -9 $P_ID
            echo "GATEWAY killed success"
        fi
		 P_ID=`ps -ef | grep -w $AUTH | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===AUTH process not exists or stop success"
        else
            kill -9 $P_ID
            echo "AUTH killed success"
        fi

         P_ID=`ps -ef | grep -w $COMMON | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===COMMON process not exists or stop success"
        else
            kill -9 $P_ID
            echo "COMMON killed success"
        fi

         P_ID=`ps -ef | grep -w $ORDER | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===ORDER process not exists or stop success"
        else
            kill -9 $P_ID
            echo "ORDER killed success"
        fi
         P_ID=`ps -ef | grep -w $TASK | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===TASK process not exists or stop success"
        else
            kill -9 $P_ID
            echo "TASK killed success"
        fi
         P_ID=`ps -ef | grep -w $UPLOAD | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===UPLOAD process not exists or stop success"
        else
            kill -9 $P_ID
            echo "UPLOAD killed success"
        fi
         P_ID=`ps -ef | grep -w $PRODUCT | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===PRODUCT process not exists or stop success"
        else
            kill -9 $P_ID
            echo "PRODUCT killed success"
        fi
         P_ID=`ps -ef | grep -w $QUALIFICATION | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===QUALIFICATION process not exists or stop success"
        else
            kill -9 $P_ID
            echo "QUALIFICATION killed success"
        fi
         P_ID=`ps -ef | grep -w $SMS | grep -v "grep" | awk '{print $2}'`
        if [ "$P_ID" == "" ]; then
            echo "===SMS process not exists or stop success"
        else
            kill -9 $P_ID
            echo "SMS killed success"
        fi

        echo "===stop success==="
        ;;   
 
restart)
        $0 stop
        sleep 2
        $0 start
        echo "===restart success==="
        ;;   
esac	
exit 0

LINUX重启MYSQL的命令 . 分类: Linux 2010-06-25 10:21 6367人阅读 评论(0) 收藏 举报 如何启动/停止/重启MySQL 一、启动方式 1、使用 service 启动:service mysqld start 2、使用 mysqld 脚本启动:/etc/inint.d/mysqld start 3、使用 safe_mysqld 启动:safe_mysqld& 二、停止 1、使用 service 启动:service mysqld stop 2、使用 mysqld 脚本启动:/etc/inint.d/mysqld stop 3、 mysqladmin shutdown 三、重启 1、使用 service 启动:service mysqld restart 2、使用 mysqld 脚本启动:/etc/inint.d/mysqld restart 提问 编辑摘要 如何启动/停止/重启MySQL 一、启动方式 1、使用 service 启动:service mysqld start 2、使用 mysqld 脚本启动:/etc/inint.d/mysqld start 3、使用 safe_mysqld 启动:safe_mysqld& 二、停止 1、使用 service 启动:service mysqld stop 2、使用 mysqld 脚本启动:/etc/inint.d/mysqld stop 3、 mysqladmin shutdown 三、重启 1、使用 service 启动:service mysqld restart 2、使用 mysqld 脚本启动:/etc/inint.d/mysqld restart 刚开始学 mysql时都是用redhat自带的。启动是什么 /rc.d/init.d/ start 这很简单,但是后来越学越多,系统自带的 mysql,有的是版本太低,有的是与 自己想要装的web服务需要的低版本的mysql 后来自己学着以tar的方式安装 mysql,我的mysql装在/usr/local/mysql目录下启 动碰到过很多问题。最常见的是: ERROR 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111) 解决办法: [root@test mysql]# /usr/local/mysql/bin/mysqladmin -u root / > -S /var/lib/mysql/mysql.sock password 'your.passwd' 或者做个连接 ln -s /var/lib/mysql/mysql.sock /tmp 其实提示找不到 /tmp/mysql.sock有时也并不是/tmp目录下没这个文件,是启动 命令不对,我碰到过 常见的几种启动方式,自己也不是记得很清楚,如果你确定tmp下有mysql.sock这 个文件不妨试试另外的几个命令 /usr/local/mysql/bin/mysql -u root -p /usr/local/mysql/bin/mysqld --user=mysql& /usr/local/mysql/bin/mysqld --user=root& /usr/local/mysql/bin/mysqld_safe --user=root& /usr/local/mysql/bin/mysqld_safe --user=mysql& /usr/local/mysql/bin/safe_mysqld--uer=root&(注意 safe_mysqld与mysqld_safe是不同的,&表示mysql在后台运行)我的就会报错了 STOPPING server from pid file /usr/local/mysql/data/localhost.localdomain.pid 060304 11:46:21 mysqld ended 这是权限问题,我的mysql目录属于root用户,也属于root群组,改用 mysqld_safe启动就没问题了, 大家只要注意这几个 mysql,safe_mysqld,mysqld_safe,mysqld,mysqladmin.多试 几次 其实有时mysql已经正常启动了,查看mysql是否启动命令 ps -aux | grep mysqld 会看到如下类似内容 mysql 6394 0.0 1.5 10528 992 pts/3 S 16:16 0:00 /usr/local/mysql/ mysql 6395 0.0 1.5 10528 992 pts/3 S 16:16 0:00 /usr/local/mysql/ mysql 6396 0.0 1.5 10528 992 pts/3 S 16:16 0:00 /usr/local/mysql/ root 6422 0.0 1.1 2408 732 pts/3 S 16:20 0:00 grep mysql 查看mysql是否在监听端口命令 netstat -tl | grep mysql 会看到如下类似内容 tcp 0 0 *:mysql *:* LISTEN
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值