nginx+tomcat+resin+jdk一键自动化安装脚本(4--resin安装脚本)

#!/bin/bash
# this shell will be installed resin*.tar.gz
#author: wangjiulong

#global variables
resin_pkg=`cat $tmp_resin`
resin_tar=`cat $tmp_resin | awk -F.tar.gz '{print $1}'`
resin_num=`cat $tmp_resin | awk -F.tar.gz '{print $1}' | awk -F- '{print $2}'`
resin_path=/usr/local/resin

datef(){ date "+%Y/%m/%d %H:%M" ; }

#custom log
print_log(){
        if [[ -d $log_dir  ]];then
                echo "[$(datef)]  $1" >> $log
        else
                echo "[$(datef)] log path does not exist,created first" >>$log
                mkdir -p $log_dir
                echo "[$(datef)]  $1" >> $log
        fi
}

#检查本机是否安装了jdk,如果已经安装了,则继续安装tomcat,不然先安装jdk,再去安装tomcat
check_jdk_install(){

        jdk_local_path=/data/java
        jdk_local_version=`java -version > /dev/null 2>&1;echo $?`

        if [ $jdk_local_version -eq 0  ];then
                print_log "本机jdk已经安装,可以安装继续安装resin"
                install_resin
        else
                #不管是否之前安装了jdk,默认安装jdk1.7的
                echo "jdk-1.7.0_17.tar.gz" > $tmp_jdk
                source ./install_jdk.sh
                source /etc/profile
                print_log "jdk-1.7已经安装,接下来安装resin"
                install_resin
        fi
}

install_resin(){

        #resin安装时的参数,请根据自己业务的需求,做相应的修改
        cd $tar_dir
        tar zxf $resin_pkg
        cd $resin_tar
        ./configure --prefix=/usr/local/resin --enable-jni --enable-64bit --enable-linux-smp --with-java-home=/data/java/jdk && make && make install

        if [[ $? != "0" ]];then
                echo "[$(datef)] ins_resin(): install error!"
                exit
        fi
        #判断用户安装的resin的版本,不同的版本,替换不同的配置文件。
        case $resin_num in
                4.0.23)
                print_log "复制替换4.0.23版的resin文件"
                cp -fv $file_dir/resin_pro_4.0.23.xml /usr/local/resin/conf/resin.xml
                cp -fv $file_dir/resin_pro_4.0.23 /etc/init.d/resin
                ;;
                3.0.21)
                print_log "复制替换3.0.21版的resin文件"
                cp -fv $file_dir/resin.conf /usr/local/resin/conf/resin.conf
                cp -fv $file_dir/resin /etc/init.d/resin
                ;;
                *)
                ;;
        esac
        cp -fv $file_dir/license.jar /usr/local/resin/lib
        chkconfig --add resin
        chmod 755 /etc/init.d/resin

        [ ! -d  /data/log/resin ] && mkdir -m777 -p /data/log/resin
        add_user
}

add_user(){
        print_log "**************** Begin change www user mode *********************"
        if ! grep "^www" /etc/passwd
        then
                groupadd www
                useradd -g www -s /bin/bash -d /data/www www
        fi
                [[ -d /usr/local/resin ]] && chown -R www:www /usr/local/resin
        print_log "*************** End change www user mode ************************"
        finished
}

finished(){
        # install complete
        print_log ""
        print_log "###########################################################"
        print_log "# [$(datef)] congratulagions!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        print_log "# [$(datef)] don't forget to modify configuration files!!!"
        print_log "# [$(datef)] based on your system resources like mem size "
        print_log "###########################################################"
        print_log ""
}

check_jdk_install

    

你可能感兴趣的:(nginx+tomcat+resin+jdk一键自动化安装脚本(4--resin安装脚本))