#!/usr/bin/env	bash
# author: Edison Y
# PATH设置

export PATH=/sbin:/bin:/usr/sbin:/usr/bin

export packagepath=$PWD

export webpath=/usr/local

#存放外部依赖包
export pkgpath=$PWD/pkg

export logpath=/tmp

#修改部署脚本中的默认路径
#sed -i 's#/usr/local#'$webpath'#' $packapgepath/deployWeb.sh
#sed -i 's#/usr/local#'$webpath'#' $packapgepath/deployTomcat.sh
sedDbPath() {

	sed -i 's#/usr/local#'$dbpath'#' $packagepath/deployPostgres.sh

	sed -i 's#/usr/local#'$dbpath'#' $packagepath/deployMongodb.sh
}

#定义文本颜色函数
#Color() {
#	RED_COLOR='\E[1;31m'
#	GREEN_COLOR='\E[1;32m'
#	YELLOW_COLOR='\E[1;33m'
#	BLUE_COLOR='\E[1;34m'
#	PINK_COLOR='\E[1;35m'
#	RES='\E[0m'
	#这里判断传入的参数是否不等于2个，如果不等于2个就提示并退出
#	if [ $# -ne 2 ];then
#		echo "Usage $0 content {red|yellow|blue|green|pink}"
#		exit
#	fi
#
#	case "$2" in
#	red|RED)
#			echo -e "${RED_COLOR}$1${RES}"
#			;;
#	yellow|YELLOW)
#			echo -e "${YELLOW_COLOR}$1${RES}"
#			;;
#	green|GREEN)
#			echo -e "${GREEN_COLOR}$1${RES}"
#			;;
#	blue|BLUE)
#			echo -e "${BLUE_COLOR}$1${RES}"
#			;;
#	pink|PINK)
#			echo -e "${PINK_COLOR}$1${RES}"
#			;;
#			*)
#			echo -e "请输入指定的颜色代码：{red|yellow|blue|green|pink}"
#	esac
#}

# 定义颜色变量
red='\033[0;31m'
yellow='\033[1;33m'
blue='\033[0;34m'
green='\033[0;32m'
pink='\E[1;35m'
NC='\033[0m' # No Color

# 彩色文字输出函数
echoColor()
{
    # 循环读取参数
    for ((i=1; i<=$#; i+=2)); do
        color=${!i}
        content=$(($i + 1))
        echo -e -n "${!color}${!content}${NC} "
    done
    echo;
}

printDHR() 
{
	echoColor pink "Start" blue "deploying" red "DHR"	yellow "services" pink ">>>>>>"
	sleep 1
	echoColor red "   ___   " yellow "  _  _  " green "  ___  "
	echoColor red "  |   \  " yellow " | || | " green " | _ \ "
	echoColor red "  | |) | " yellow " | __ | " green " |   / "
	echoColor red "  |___/  " yellow " |_||_| " green " |_|_\ "
	sleep 1
	echoColor pink "Shell" green "script"  red "disigned" yellow "by" blue "EdisonY"
}

printDHR

#三个服务进程状态判断函数
pidCheck() {
	Tomcat="dhr.war"
	PGSQL="postgres"
	MongoDB="mongod"
	#这里判断传入的参数是否不等于1个
	if [ $# -ne 1 ];then
		echo "Usage $0 content {tomcat|postgres|mongod}"
		exit
	fi

	case "$1" in
	tomcat|TOMCAT)
			count=`ps -ef | grep $Tomcat | grep -v grep | wc -l`
			if [[ $count == 0 ]];then
				echoColor green "$Tomcat process not exist"
				return 1
			else
				echoColor red "$Tomcat process exist"
			fi
			;;
	postgres|POSTGRES)
			count=`ps -ef | grep $PGSQL | grep -v grep | wc -l`
			if [[ $count == 0 ]];then
				echoColor green "$PGSQL process not exist"
				return 1
			else
				echoColor red "$PGSQL process exist"
			fi
			;;
	mongod|MONGOD)
			count=`ps -ef | grep $MongoDB | grep -v grep | wc -l`
			if [[ $count == 0 ]];then
				echoColor green "$MongoDB process not exist"
				return 1
			else
				echoColor red "$MongoDB process exist"
			fi
			;;
			*)
			echo -e "请输入指定的服务名称：{tomcat|postgres|mongod}"
	esac
}

createUserAndGroup() {
	#创建postgres用户组和用户
	#useradd -g postgres postgres
	name="postgres"
	groupname="postgres"
	passwd="ehr@123"

	#create group if nost exists
	egrep "^$groupname" /etc/group >& /dev/null
	if [ $? -ne 0 ]
	then
	        groupadd $groupname && >> $logpath/install.log
	else
	        echoColor red "用户组$groupname已存在" && >> $logpath/install.log
	fi
	#create user if not exists
	egrep "^$name" /etc/passwd >& /dev/null
	if [ $? -ne 0 ]
	then
	        useradd -g $groupname -r -m -s /bin/bash $name \
	      	&& echo "$passwd" | passwd --stdin $name >& /dev/null \
	        && echoColor green "用户$name 创建完成,默认密码是$passwd " && >> $logpath/install.log
	else
	        echoColor red "用户 $name 已存在" && >> $logpath/install.log
	fi

	sleep 2
}

installNetsnmp() {
	echoColor green "start install net-snmp ......"

	\cp -r $pkgpath/so/* /usr/lib64

	sleep 1

	rpm -ivh $pkgpath/net-snmp/1lm_sensors-libs.rpm --nodeps --force
	rpm -ivh $pkgpath/net-snmp/2perl-libs.rpm --nodeps --force
	rpm -ivh $pkgpath/net-snmp/3perl-Module-Install.rpm --nodeps --force
	rpm -ivh $pkgpath/net-snmp/4net-snmp-libs.rpm --nodeps --force
	rpm -ivh $pkgpath/net-snmp/5net-snmp-utils.rpm --nodeps --force
	rpm -ivh $pkgpath/net-snmp/6net-snmp-agent-libs.rpm --nodeps --force
	if [ $? -ne 0 ]
	then
	        echoColor red "请检查 $packapgepath 路径下是否存在net-snmp文件夹" && >> $logpath/install.log
	else
	        echoColor green "net-snmp相关依赖包已成功安装" && >> $logpath/install.log
	fi

}

installUbuntuSnmpd() {
	echoColor green "start install snmpd ......"

	cp -f $pkgpath/snmpd/so/libsensors.so.5 /usr/lib/x86_64-linux-gnu

	sleep 1

	dpkg -i --force-all $pkgpath/snmpd/libsnmp35_5.8+dfsg-2ubuntu2.7_amd64.deb
	dpkg -i --force-all $pkgpath/snmpd/libsnmp-base_5.8+dfsg-2ubuntu2.7_all.deb
	dpkg -i --force-all $pkgpath/snmpd/snmpd_5.8+dfsg-2ubuntu2.7_amd64.deb
	if [ $? -ne 0 ]
	then
	        echoColor red "请检查 $packapgepath 路径下是否存在snmpd文件夹" && >> $logpath/install.log
	else
	        echoColor green "snmpd相关依赖包已成功安装" && >> $logpath/install.log
	fi

}

#输入一个路径，将输入路径赋值给dbpath变量
dbPathInput() {
	echo "请输入数据库服务安装目录:"
	read DBpath
	#echo $dbpath >> /tmp/install.log
}

#选择判断
enSuredbPath() {
    echo "请确认数据库服务安装目录(y/n)"
    echo 数据库是否安装到：$DBpath
    read choose
    case "$choose" in
        Y|y)
            echo "数据库服务将被安装到$DBpath"
			echo "$DBpath" > /tmp/dbpath.txt
            ;;
        N|n)
            echo "请重新输入数据库服务安装路径"
			dbPathInput
			enSuredbPath
            ;;
        *)
            echo "请输入正确的选项(y/n)"
            #exit 1
			enSuredbPath
            ;;
    esac
}

#判断输入的路径是否为一个绝对路径
checkAbsolutePath() {
	if [[ $DBpath != /* ]]
	then
		echo "请输入绝对路径，例如/usr/local"
		dbPathInput
		enSuredbPath
		checkAbsolutePath
	fi
}

#修改mongodb6预置脚本路径变量
sedMongodb6path() {
	sed -i 's#/usr/local#'$dbpath'#' $dbpath/ehr/mongodb6/startmongodb.sh

	sed -i 's#/usr/local#'$dbpath'#' $dbpath/ehr/mongodb6/startmongodb2.sh

	sed -i 's#/usr/local#'$dbpath'#' $dbpath/ehr/mongodb6/stopmongodb.sh

	sed -i 's#/usr/local#'$dbpath'#' $dbpath/ehr/mongodb6/mongodb_data_bak.sh

	sed -i 's#/usr/local#'$dbpath'#' $dbpath/ehr/mongodb6/bin/mongod.cfg

	sed -i 's#/usr/local#'$dbpath'#' $dbpath/ehr/mongodb6/bin/mongod2.cfg
}

#修改mongodb4预置脚本路径变量
sedMongodb4path() {
	sed -i 's#/usr/local#'$dbpath'#' $dbpath/ehr/mongodb/startmongodb.sh

	sed -i 's#/usr/local#'$dbpath'#' $dbpath/ehr/mongodb/startmongodb2.sh

	sed -i 's#/usr/local#'$dbpath'#' $dbpath/ehr/mongodb/stopmongodb.sh

	sed -i 's#/usr/local#'$dbpath'#' $dbpath/ehr/mongodb/mongodb_data_bak.sh

	sed -i 's#/usr/local#'$dbpath'#' $dbpath/ehr/mongodb/bin/mongodb.conf

	sed -i 's#/usr/local#'$dbpath'#' $dbpath/ehr/mongodb/bin/mongodb2.conf
}

#修改postgresql15预置脚本路径变量
sedPgdbpath() {

	sed -i 's#/usr/local#'$dbpath'#' $dbpath/ehr/postgresql15/startpostgresql.sh

	sed -i 's#/usr/local#'$dbpath'#' $dbpath/ehr/postgresql15/stoppostgresql.sh

	sed -i 's#/usr/local#'$dbpath'#' $dbpath/ehr/postgresql15/postgresql_data_bak.sh
}

installPostgreSQL() {
	echoColor green "start install postgreSQL ......"
	sleep 2
#	sh $packagepath/start.sh
	#progress_bar
	#insatll postgreSQL and start it
	tar xf $packagepath/postgresql-15.3.tar.gz -C $dbpath/ehr
	mv $packagepath/init_PostgreSQL_Index.sql  $dbpath/ehr && sedPgdbpath >> $logpath/install.log
	if [ $? -ne 0 ]
	then
	        echoColor red "postgreSQL启动失败" && >> $logpath/install.log
	else
	        chown -R postgres:postgres $dbpath/ehr/postgresql15 >> $logpath/install.log \
	        && su - postgres -c "/bin/bash $dbpath/ehr/postgresql15/startpostgresql.sh" && >> $logpath/install.log
	        echoColor green "已成功安装并启动PostgreSQL，安装路径为 $dbpath/ehr/postgresql15" && >> $logpath/install.log
	fi
}

#检查服务器cpu是否支持avx指令集
#该处需要修改判断cpu是否支持avx指令集和服务器操作系统，再选择对应可用的mongodb安装包
#Centos7支持avx指令集：mongodb6-centos7版本，不支持avx指令集mongodb4.0.13
#Ubuntu20.04支持avx指令集：mongodb6-Ubuntu20版本，不支持avx指令集mongodb4.0.23（该版本需单独修改预置ehr用户的密码为kh5MCLQRhe后重新打包）
installUbuntuMongodb4() {
	echoColor green "start install mongodb ......"
	#sh $packagepath/start.sh
	#install mongodb and start it
	tar xf $pkgpath/mongodb-4.0.23.tar.gz -C $dbpath/ehr
	mv $packagepath/inti_MongoDB_index.js init_MongoDB_App.js $dbpath/ehr >> $logpath/install.log \
	&& sedMongodb4path && >> $logpath/install.log
	if [ $? -ne 0 ]
	then
	        echoColor red "请检查mongodb相关依赖是否安装" && >> $logpath/install.log
	else
	        sh $dbpath/ehr/mongodb/startmongodb.sh && >> $logpath/install.log \
	        && $dbpath/ehr/mongodb/bin/mongo 127.0.0.1:27011/ehr -u ehr -p kh5MCLQRhe $dbpath/ehr/inti_MongoDB_index.js && >> $logpath/install.log \
	        && $dbpath/ehr/mongodb/bin/mongo 127.0.0.1:27011/ehr -u ehr -p kh5MCLQRhe $dbpath/ehr/init_MongoDB_App.js && >> $logpath/install.log \
	        && echoColor green "已成功安装并启动mongodb，安装路径为 $dbpath/ehr/mongodb"  && >> $logpath/install.log
	fi
}

installUbuntuMongodb6() {
	echoColor green "start install mongodb ......"
	mv $packagepath/mongodb-6.0.6.tar.gz deployMongodb.sh mongosh-2.0.2-linux-x64.tgz inti_MongoDB_index.js init_MongoDB_App.js $dbpath/ehr &&  sh $dbpath/ehr/deployMongodb.sh >> $logpath/install.log \
	&& sedMongodb6path && >> $logpath/install.log
	if [ $? -ne 0 ]
	then
	        echoColor red "请检查mongodb相关依赖是否安装" && >> $logpath/install.log
	else
	        sh $dbpath/ehr/mongodb6/startmongodb.sh && >> $logpath/install.log \
	        && $pkgpath/mongosh*/bin/mongosh 127.0.0.1:27011/ehr -u ehr -p kh5MCLQRhe $dbpath/ehr/inti_MongoDB_index.js && >> $logpath/install.log \
	        && $pkgpath/mongosh*/bin/mongosh 127.0.0.1:27011/ehr -u ehr -p kh5MCLQRhe $dbpath/ehr/init_MongoDB_App.js && >> $logpath/install.log \
	        && echoColor green "已成功安装并启动mongodb，安装路径为 $dbpath/ehr/mongodb6" && >> $logpath/install.log
	fi
}

installCentosMongodb4() {
	echoColor green "start install mongodb ......"
	#sh $packagepath/start.sh
	#install mongodb and start it
	tar xf $pkgpath/mongodb-4.0.13.tar.gz -C $dbpath/ehr
	mv $packagepath/inti_MongoDB_index.js init_MongoDB_App.js $dbpath/ehr >> $logpath/install.log \
	&& sedMongodb4path && >> $logpath/install.log
	if [ $? -ne 0 ]
	then
	        echoColor red "请检查是否安装net-snmp相关依赖包" && >> $logpath/install.log
	else
	        sh $dbpath/ehr/mongodb/startmongodb.sh && >> $logpath/install.log \
	        && $dbpath/ehr/mongodb/bin/mongo 127.0.0.1:27011/ehr -u ehr -p kh5MCLQRhe $dbpath/ehr/inti_MongoDB_index.js && >> $logpath/install.log \
	        && $dbpath/ehr/mongodb/bin/mongo 127.0.0.1:27011/ehr -u ehr -p kh5MCLQRhe $dbpath/ehr/init_MongoDB_App.js && >> $logpath/install.log \
	        && echoColor green "已成功安装并启动mongodb，安装路径为 $dbpath/ehr/mongodb" && >> $logpath/install.log
	fi
}

installCentosMongod6() {
	echoColor green "start install mongodb ......"
	#sh $packagepath/start.sh
	#install mongodb and start it
	tar xf $pkgpath/centos7_mongodb-6.0.6.tar.gz -C $dbpath/ehr
	mv $packagepath/inti_MongoDB_index.js init_MongoDB_App.js $dbpath/ehr >> $logpath/install.log \
	&& sedMongodb6path && >> $logpath/install.log
	if [ $? -ne 0 ]
	then
	        echoColor red "请检查是否安装net-snmp相关依赖包" && >> $logpath/install.log
	else
	        sh $dbpath/ehr/mongodb6/startmongodb.sh && >> $logpath/install.log \
	        && $pkgpath/mongosh*/bin/mongosh 127.0.0.1:27011/ehr -u ehr -p kh5MCLQRhe $dbpath/ehr/inti_MongoDB_index.js && >> $logpath/install.log \
	        && $pkgpath/mongosh*/bin/mongosh 127.0.0.1:27011/ehr -u ehr -p kh5MCLQRhe $dbpath/ehr/init_MongoDB_App.js && >> $logpath/install.log \
	        && echoColor green "已成功安装并启动mongodb，安装路径为 $dbpath/ehr/mongodb6"  && >> $logpath/install.log
	fi
}

#判断操作系统为Ubuntu20.04还是Centos7
#detectOSVersionAndInstallSnmpd() {
#	if [ -f /etc/os-release ]; then
#		. /etc/os-release
#		OS=$NAME
#		VERSION=$VERSION_ID
#	else
#		OS=$(uname -s)
#	fi
#
#	if [ "$OS" = "Ubuntu" ] && [ "$VERSION" = "20.04" ]; then
#		echo "This is Ubuntu 20.04"
#	elif [ "$OS" = "CentOS Linux" ] && [ "$VERSION" = "7" ]; then
#		echo "This is CentOS 7"
#	else
#		echo "This is not Ubuntu 20.04 or CentOS 7"
#	fi
#}

#判断服务器操作系统版本选择安装相应版本mongodb服务，相应系统下增加判断cpu是否支持avx指令集
checkOSandInstallMongodb() {
    avx=$(grep avx /proc/cpuinfo)
    if [ -f /etc/os-release ]; then
        . /etc/os-release
        OS=$NAME
		VERSION=$VERSION_ID
    else
        OS=$(uname -s)
    fi

    if [ "$OS" = "Ubuntu" ] && [ "$VERSION" = "20.04" ]; then
        echo "This is Ubuntu 20.04"
        if [ -z "$avx" ]; then
            echo "CPU不支持avx指令集"
			installUbuntuMongodb4
        else
            echo "CPU支持avx指令集"
			installUbuntuSnmpd
			installUbuntuMongodb6
        fi
    elif [ "$OS" = "CentOS Linux" ] && [ "$VERSION" = "7" ]; then
        echo "This is CentOS 7"
        if [ -z "$avx" ]; then
            echo "CPU不支持avx指令集"
			installNetsnmp
			installCentosMongodb4
        else
            echo "CPU支持avx指令集"
			installNetsnmp
			installCentosMongod6
        fi
    else
        echo "This is not Ubuntu 20.04 or CentOS 7"
		exit 1
    fi
}

#判断服务器操作系统版本创建postgresql15依赖的软链接
detectOSandCreateSoftLink() {
	if [ -f /etc/os-release ]; then
		. /etc/os-release
		OS=$NAME
	else
		OS=$(uname -s)
	fi

	if [ "$OS" = "Ubuntu" ]; then
		echo "This is Ubuntu,create a sof link in the /usr/lib directory"
		ln -s $dbpath/ehr/postgresql15/lib/libpq.so.5 /usr/lib/libpq.so.5
	elif [ "$OS" = "CentOS Linux" ]; then
		echo "This is CentOS,create a sof link in the /usr/lib64 directory"
		ln -s $dbpath/ehr/postgresql15/lib64/libpq.so.5 /usr/lib64/libpq.so.5
	else
		echo "This is not Ubuntu or CentOS"
	fi
}

#服务是否安装判断
isInstall() {
	Tomcat="tomcat"

	PGSQL="postgres"

	MongoDB="mongod"

	if [ $# -ne 1 ];then
		echo "Usage $0 content {tomcat|postgres|mongod}"
		exit
	fi
	case "$1" in	
		mongod|MONGOD)
			if [ -f "$dbpath/ehr/mongodb6/bin/mongod" ]  || [ -f "$dbpath/ehr/mongodb/bin/mongod" ]
			then
				echoColor red "mongodb已安装"
			else
				echoColor green "mongodb未安装"
				return 1
			fi
			;;
		postgres|POSTGRES)	
			if	[ -f "$dbpath/ehr/postgresql15/bin/psql" ]
			then
				echoColor red "postgresql已安装"
			else
				echoColor green "postgresql未安装"
				return 1
			fi
			;;
		tomcat|TOMCAT)
			if	[ -f "$webpath/dhr/dhr.war" ]
			then
				echoColor red "tomcat已安装"
			else
				echoColor green "tomcat未安装"
				return 1
			fi
			;;
		*)
        	echo "请输入指定的服务名称：{tomcat|postgres|mongod}"
			;;
	esac
}

#java基础环境部署
deployJavaEnvironment() {
    if [ -f $packagepath/ehr_jdk.tar.gz ]
    then
        tar xf $packagepath/ehr_jdk.tar.gz -C $webpath
        echoColor green "Java环境已安装"
    else
        echoColor red "Java环境未安装"
        return 1
    fi
}

#dhr服务部署
deployDHR() {
	if [ -f $packagepath/ehr_privatization.war ]
	then
		mv $packagepath/ehr_privatization.war deployDHR.sh *.properties $webpath && sh $webpath/deployDHR.sh >> $logpath/install.log
	else
		echoColor red "请确认安装包内是否存在ehr_privatization.war文件"
		exit 1
	fi
}

#测试从应用服务器是否能正常访问到license系统
testConnection() {
	curl --head --silent --fail https://license.x-dhr.com 2>&1 >/dev/null
	if [ $? -eq 0 ]; then
		echoColor green "正常访问https://license.x-dhr.com/"
		#echoColor green "start deployweb ......"
		#启动薪事力服务
		cd $webpath/dhr
		sh startDHR.sh
	else
		echoColor red "请确认是否安装curl命令，如果已经安装，请开放访问https://license.x-dhr.com/和https://www.x-dhr.com/地址，用做license在线校验,开放后启动应用服务" && >> $logpath/install.log
		exit 1
	fi
}

#选择是否配置软加密，启动薪事力服务
chooseEncryptionFile() {
	echoColor yellow "请确认本次部署是否为普通环境部署（输入y代表非软加密方式进行部署，输入n代表采用加密方式进行部署）（y/n）"
	read select
	case "$select" in
		Y|y)
			echo "测试访问license系统"
			testConnection
			;;
		N|n)
			echo "配置软加密文件"
			\cp $packagepath/key $webpath/dhr/config

			sleep 1

			#启动薪事力服务
			cd $webpath/dhr
			sh startDHR.sh
			;;
		*)
			echo "请输入正确的选项(y/n)"
			chooseEncryptionFile
			;;
	esac
}
############################################################################

#create db install path and update dependent shell script

if [ -f /tmp/dbpath.txt ]; then
    echoColor red "存在path文件，跳过变量赋值"
else
    dbPathInput

    enSuredbPath

    checkAbsolutePath
fi

#判断输入的路径结尾是否以/结束，如果是，向前截取一位重新重定向content变量值到/tmp/dbpath.txt
if [ -f /tmp/dbpath.txt ]; then
    content=$(cat /tmp/dbpath.txt)
    last_char=${content: -1}
    if [ "$last_char" = "/" ]; then
        echo "The content ends with /"
        content=${content%?}
        echo $content > /tmp/dbpath.txt
    else
        echo "The content does not end with /"
    fi
else
    echo "/tmp/dbpath.txt does not exist"
fi

#持久化DBpath变量值
export dbpath=`cat /tmp/dbpath.txt`

mkdir -p $dbpath/ehr

chmod -R 755 $dbpath/ehr

sedDbPath

#create postgres user and group
createUserAndGroup

#deploy postgresql15 server and create soft link
#installPostgreSQL
#detectOSandCreateSoftLink

#deploy mongodb server
#checkOSandInstallMongodb

if isInstall mongod $1;then
		echoColor red "MongoDB已存在，跳过安装"
	else
		checkOSandInstallMongodb
	fi

if isInstall postgres $1;then
		echoColor red "PostgreSQL已存在，跳过安装"
	else
		installPostgreSQL
		detectOSandCreateSoftLink
	fi

if isInstall tomcat $1;then
		echoColor red "Tomcat已存在，跳过安装"
	else
		deployJavaEnvironment	
	fi

deployDHR

#choosen set key file or not, and test whether the website can be accessed normally and start webservice
chooseEncryptionFile

sleep 99

#check dhr service status and init postgresql
if pidCheck tomcat $1;then
	echoColor green "dhr服务启动成功"
	echoColor red "请完整复制如下命令在数据库服务器上进行执行!"
	echoColor yellow "$dbpath/ehr/postgresql15/bin/psql -f $dbpath/ehr/init_PostgreSQL_Index.sql -U postgres -p 5632 -h 127.0.0.1 -d dbehr "
else 
	echoColor red "dhr服务启动失败，请检查$webpath/dhr/logs/dhr.log日志内容排查错误"
	echoColor red "请在dhr服务启动正常访问后，完整复制如下命令在数据库服务器上进行执行！"
	echoColor yellow "$dbpath/ehr/postgresql15/bin/psql -f $dbpath/ehr/init_PostgreSQL_Index.sql -U postgres -p 5632 -h 127.0.0.1 -d dbehr "
fi

#rm -f /tmp/dbpath.txt
#考虑是否增加	数据库服务判断是否防火墙来确认开放端口
#考虑是否增加	将数据库服务和应用服务注册成系统服务
#考虑是否增加	创建定时任务执行数据库备份脚本