Demo entry 5865360

ss

   

Submitted by anonymous on Aug 18, 2016 at 03:53
Language: PowerShell. Code size: 3.8 kB.

#!/bin/sh
#
# 脚本功能:自动化安装RJCloud
#
#
############################################
# 安装httpd mysql php
############################################

#RCD服务器输出格式要求
S_NAME=tomcat6
DB_NAME=rcd
declare C_DIR=$(cd "$(dirname "$0")"; pwd)
RCD_DIR=/usr/rcd
CONF_DIR=$RCD_DIR/conf
BIN_DIR=$RCD_DIR/bin

#include files
if [ -f "$BIN_DIR/common.main" ]
then
. $BIN_DIR/common.main
else
. $C_DIR/common.main
fi

#开始标志
start_out
declare version=`cat ${C_DIR}/RJversion`

#写入日志
write_log()
{
	cd ${C_DIR}
	if [ ! -f 'output.log' ]
	then
		touch output.log
	fi
	
	if [ -f 'output.log' ]
	then
		if [ $1 -eq 0 ]
		then		
			now=$(date)
			echo -e "---- WORKSPACE "$version" is installing----" >> output.log
			echo -e "Install time: "$now >> output.log
			echo -e "Install version: "$version >> output.log
			echo -e "---- WORKSPACE is installed success----" >> output.log
		elif [ $1 -eq 3 ]
		then
			now=$(date)
			echo -e "---- WORKSPACE "$version" is installing----" >> output.log
			echo -e "Install time: "$now >> output.log
			echo -e "Install version: "$version >> output.log
			echo -e "Install component: "$2 >> output.log
			echo -e "---- WORKSPACE is installing component----" >> output.log
		else
			now=$(date)
			echo -e "---- WORKSPACE "$version" is installing----" >> output.log
			echo -e "Install time: "$now >> output.log
			echo -e "Install version: "$version >> output.log
			echo -e "Install error: "$2 >> output.log
			echo -e "---- WORKSPACE is installed fail----" >> output.log
		fi		
	fi

}



#检测是否已安装httpd相关服务
check_env()
{
	rpm -qa $1 | grep $1
	install_bool=$?
	if [ $install_bool -eq 1 ]
	then
		msg="component "$1" is missing,check your environment"
		write_log 1 "$msg"
			fail_out
		msg_out " component "$1" is missing,fail."
			end_out
			exit 1
	fi
    return ${install_bool}
}

####################################
#程序入口
####################################
echo "Install workspace start....."

setenforce 0
sed -i -e 's/SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config

#检测是否已安装mysql相关服务
check_env mysql
check_env mysql-server
#如果是意外开启mysql,要先关闭mysql
test_mysql_status=$(/usr/bin/pgrep mysqld)
if [ "$test_mysql_status" != "" ]
then
	echo "stop mysqld service"
	service mysqld stop &>/dev/null
fi

echo "change mysql data dir..."
#修改/etc/my.cnf
sed -i 's/datadir=\/var\/lib\/mysql/datadir=\/opt\/var\/lib\/mysql/' /etc/my.cnf
sed -i 's/socket=\/var\/lib\/mysql\/mysql.sock/socket=\/opt\/var\/lib\/mysql\/mysql.sock/' /etc/my.cnf

#修改/etc/init.d/mysqld
sed -i -e 's/datadir "\/var\/lib\/mysql"/datadir "\/opt\/var\/lib\/mysql"/' /etc/init.d/mysqld

#修改/usr/bin/mysqld_safe
sed -i 's/DATADIR=\/var\/lib\/mysql/DATADIR=\/opt\/var\/lib\/mysql/' /usr/bin/mysqld_safe

#修改/usr/lib/mysql/mysql_config
sed -i "s/ldata='\/var\/lib\/mysql'/ldata='\/opt\/var\/lib\/mysql'/" /usr/lib64/mysql/mysql_config
sed -i "s/socket='\/var\/lib\/mysql\/mysql.sock'/socket='\/opt\/var\/lib\/mysql\/mysql.sock'/" /usr/lib64/mysql/mysql_config

#创建路径
if [ ! -d '/opt/var/lib/mysql' ]
then
	mkdir -p /opt/var/lib
	cp /var/lib/mysql /opt/var/lib/ -r
fi

chmod 777 -R /opt/var/lib
ln -s /opt/var/lib/mysql/mysql.sock /var/lib/mysql/mysql.sock

/etc/init.d/mysqld start &>/dev/null

#判断是否开启mysql服务
test_mysql_start=$(/usr/bin/pgrep mysqld)
if [ "$test_mysql_start" = "" ]
then
	write_log 1 "Can not connect to mysql"
	fail_out
	msg_out " Can not connect to mysql,fail."
	end_out
	exit 1
fi

#检测是否已安装expect相关服务
check_env expect

#安装unzip
check_env unzip
	
cd ${C_DIR}
#判断是否配置mysql密码
flag=`mysql -e "show databases;"  &>/dev/null && echo 1 || echo 0`> /dev/null  
if [ $flag -eq 0 ]
then
    echo "mysql_secure_installation has install..."
	chmod 777 ./Cloud_install.sh
	./Cloud_install.sh
else
	write_log 3 "mysql_secure_installation"
	echo "mysql_secure_installation has not been installed"
	chmod 777 ./auto.sh
	./auto.sh
fi

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).