[root@node01 ~ 10:50:56&&1]#cat /usr/local/sbin/format.sh
#!/usr/bin/env bash

echo "1、定义服务器名称"
read -p "Please input your server's hostname :" I

sed -i "s/HOSTNAME=.*./HOSTNAME=$I/" /etc/sysconfig/network

#关闭第一次登录服务器的提醒
sed -i 's/#   StrictHostKeyChecking ask/StrictHostKeyChecking no/' /etc/ssh/ssh_config
echo
echo
echo "2、格式化磁盘"
yum makecache >/dev/null
yum install -y vim expect screen lrzsz >/dev/null

#对新磁盘xvdb 进行分区
expect /usr/local/sbin/fdisk.pt

#格式化新分区
mkfs -t ext4 /dev/xvdb1 >/dev/null

#判断要挂载的目录是否存在，不存在则创建
MOUNT_DIR=/data
if [ ! -d "$MOUNT_DIR" ] ;then
        mkdir -p $MOUNT_DIR
fi

#判断fstab 文件中是否有写自动挂载的新分区 xvdb1
Z="$(egrep xvdb1 /etc/fstab)"
if [ -z "$Z" ] ;then
        echo "/dev/xvdb1              /data                      ext4   defaults  0  0" >> /etc/fstab
	else
		sleep 10
fi

#挂载新分区
mount /dev/xvdb1 /data

echo
echo
echo "3、创建挂载swap"
#生产虚拟内存并启用
dd if=/dev/zero of=/data/myswap bs=1024 count=8192000
mkswap /data/myswap
swapon /data/myswap

echo
echo
echo "4、创建/data/ 下相应目录"
#判断data 分区是否已经挂在，如果没挂载，则创建下面的目录并授权
R="$(df -lh |grep data)"
if [ ! -z "$R" ];then
	mkdir -p $MOUNT_DIR/{adminshell,autobuild,zuan,cert,logs,Runtime}
	mkdir -p $MOUNT_DIR/autobuild/source/WeiZuanHtml5/
	mkdir $MOUNT_DIR/zuan/{Uploads,Runtime,Html}
	chmod 777 $MOUNT_DIR/zuan/{Runtime,Html} $MOUNT_DIR/Runtime
fi


rsync -ave 'ssh' 10.117.64.45:/data/adminshell/invoking/* /data/adminshell/invoking/
/bin/bash /data/adminshell/invoking/modify-nginx-ip.sh

echo
echo
echo "5、同步数据"
#同步代码
rsync -ave 'ssh' 10.117.64.45:/data/zuan/* /data/zuan/ --delete --exclude=.svn --exclude=Uploads --exclude=WeiZuanHtml5 --exclude=Runtime --exclude=*.log --exclude=*.gz --exclude=*.zip --exclude=id  --exclude=Html >/dev/null

rsync -ave 'ssh' 10.117.64.45:/data/zuan/.htaccess /data/zuan/ >/dev/null
if [ ! -f '/data/zuan/.htaccess' ] ;then
	exit
fi

echo
echo
echo"6、挂载剩下的nfs"
#启用nfs 挂载及挂载虚拟内存
sed -i 's/#10.162.100.182:\/app/10.162.100.182:\/app/' /etc/fstab
sed -i 's/#10.162.100.182:\/img/10.162.100.182:\/img/' /etc/fstab
sed -i 's/#10.162.100.182:\/Runtime/10.162.100.182:\/Runtime/' /etc/fstab
sed -i 's/#swap/swap/' /etc/fstab

#再次挂载剩余的nfs
mount -a

echo
echo
echo "7、重新运行grearmand"
#重新启动gearmand
service gearmand stop >>/dev/nulll
ps aux|grep super|grep -v grep|awk '{print $2}'|xargs kill -9
service gearmand start >>/dev/nulll
nohup /usr/bin/supervisord -c /etc/supervisord.conf >> /root/wx_work.log &

Z=$(gearadmin --status |grep update)
if [ ! -z "${Z}" ];then 
		echo "gearmand start secussfull"
	else 
		exit
fi

echo
echo
echo "8、重启nginx 和 php-fpm"
#重启nginx 
service nginx restart && service php-fpm restart










[root@node01 ~ 10:50:56&&1]#cat /usr/local/sbin/fdisk.pt
#!/usr/bin/env expect

spawn fdisk -c -u /dev/xvdb

expect "Command (m for help):"

send "n\r"

expect "primary partition"
send "p\r"

expect "Partition number (1-4):"
send "1\r"

expect "First sector"
send "\r"

expect "Last sector"
send "\r"

expect "Command (m for help):"
send "w\r"

interact
