Shell启动脚本

在开发环境将启动脚本注册为系统服务步骤:

cd /etc/init.d/
cp /app/sh/mdp.sh /etc/init.d/mdp
chmod -x mdp

启动脚本如下

service_dir="/root/x-mdp-osp"
target_pre="service"
target_suffix="engine"
version=
service=
target=

function initParam(){
    if [ "$service" == "sc" ] ;then
        echo "true"
        target_pre="schedule"
        target_suffix="executor"
        service_dir="/root/x-mdp-saturn"
    fi
    target=${service_dir}/mdp-${target_pre}-${version}-SNAPSHOT-${target_suffix}
}

function start(){
    echo "begin start ${target} ......."
    ps -ef|grep mdp-${target_pre}|grep -v grep|cut -c 9-15|xargs kill -s 9
    sleep 1
    rm -rf ${target}
    sleep 1
    unzip -d ${target} ${target}.zip
    sleep 1
    if [ "$service" == "sc" ] ;then
        startSc
    else
        startOsp
    fi 
    echo "start ${target} over"
}

function startOsp(){
    chmod +x ${target}/bin/osp-default.sh
    ${target}/bin/osp-default.sh start -p 1080 -r 9090 -j 8060 -Xmx1g -Xms512m -Dspring.profiles.active=development -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5006
    sleep 1
}

function startSc(){
    chmod +x ${target}/saturn/bin/saturn-job-executor.sh
    ${target}/saturn/bin/saturn-job-executor.sh start --namespace vip.job.crm-mdp --executorName x-dev1 -jmx 8061 -Xms516m -Xmx2048m -Dspring.profiles.active=development
    sleep 1
}

if  [ ! -n "$1" ] || [ ! -n "$2" ] ;then
    echo $"Usage: $0 6.0 {osp|sc}"
    exit 1
else
    version=$1
    service=$2
    initParam
    start
fi

实际运行的过程发现会提示一下异常:
nohup: failed to run command `java': No such file or directory
原因是因为没有加载到环境变量导致。因此启动脚本第一行增加了以下配置:

. /etc/profile
nohup java -jar xxx.jar > nohup.log &

若有提示:command not founda,有可能是文件格式的问题;
需要vi 进入脚本的编辑界面,执行:set fileformat=unix

你可能感兴趣的:(Shell启动脚本)