启动脚本

目的:所有产品统一启动脚本

功能:

1.可以根据不同参数进行程序启动、停止、重启等操作;

2.自动判断程序是否具有启动权限,是否为该程序的所属用户,如果不是,则提示错误,不允许启动。


脚本内容(start.sh):

#!/bin/bash 
# start.sh
source ~/.bash_profile
PARM=$1
PORT=9010  #端口根据实际需要设置
#service_name需要根据实际jar包名做替换,不用考虑版本号,如:web-start,exchange-server,file-start等
service_name=evidence-start
tmp_dir="/home/dep/tmp"  #需要根据实际情况修改这个临时目录,且需要手动创建该临时目录
user=`whoami`
owner=`ls -l | grep ${service_name} | grep "jar$" | awk '{print $3}'` #程序所属的用户名称
PID=`ps -ef | grep -w $PORT | grep -v grep | awk '{print $2}'`
#检查是否是程序所属用户,如果不是程序所属用户则不让执行该脚本
if [[ $owner == "" ]];then
    echo -e "\033[31mERROR: The owner is empty and the [service_name] configuration may be wrong. \033[0m"
    exit 1
elif [[ $user != $owner ]];then   
    echo -e "\033[31mERROR: The current user is $user, please use $owner user to execute.\033[0m"
    exit 1
elif [[ $owner == "root" ]];then   
    echo -e "\033[31mERROR: The current user is root, root is not allowed to execute.\033[0m"
    exit 1
fi
 
case $PARM in
	'start')
	if [[ -z $PID ]];then
            echo "=================================================================="
            echo "|                 Application starting at `date`.                |"
            echo "=================================================================="
            java -Dserver.port=$PORT -Duser.timezone=Asia/Shanghai -Djava.io.tmpdir=${tmp_dir} -jar ${service_name}*.jar > stdout.log &
            echo "|     Application appears to still be running with PID $PID.     |"
            echo "=================================================================="
	else
            echo "=================================================================="
            echo "|             Application is running with PId $PID...            |"
            echo "=================================================================="
	fi
	;;
	'stop')
	if [[ $PID -ne 0 ]];then
	    kill -9 $PID
            echo "=================================================================="
            echo "|        Application is shutting down successfully !!!           |"
            echo "=================================================================="
        else
            echo "=================================================================="
            echo "|      Nothing been done,Application had been shutted down!      |"
            echo "=================================================================="
	fi
	;;
	'restart')
	if [[ $PID -ne 0 ]];then
            kill -9 $PID
            echo "=================================================================="
            echo "|          Application having being down,please wait...          |"
            echo "=================================================================="
            java -Dserver.port=$PORT -Duser.timezone=Asia/Shanghai -Djava.io.tmpdir=${tmp_dir} -jar ${service_name}*.jar & > stdout.log &
	fi
	if [[ $PID -eq 0 ]];then
            echo "=================================================================="
            echo "|    Application had been shutted down.please wait staring...    |"
            echo "=================================================================="
            java -Dserver.port=$PORT -Duser.timezone=Asia/Shanghai -Djava.io.tmpdir=${tmp_dir} -jar ${service_name}*.jar & > stdout.log &
	fi
        ;;
	'status')
	if [[ -z ${pid} ]];then
            echo "=================================================================="
            echo "|             Application is running with PId $PID...            |"
            echo "=================================================================="
	else
            echo "=================================================================="
            echo "|                     Application is stoped !!!                  |"
            echo "=================================================================="
	fi
	;;
	esac

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值