<NME> deploy.sh
<BEF> #!/bin/bash
cur_dir=`old=\`pwd\`; cd \`dirname $0\`; echo \`pwd\`; cd $old;`
prj=`basename $cur_dir`
env=$1
iphp_dir=/data/lib/iphp
nginx_conf_dir=/etc/nginx/conf.d
fpm_pid_dir=/var/run/php-fpm
fpm_log_dir=/var/log/php-fpm
prj_dir=/data/www/$prj
dep_dir=/data/deploy_www/$prj.dep.`date +%Y%m%d_%H%M%S`

php-fpm 2>&1 > /dev/null
prj_dir=/data/www/$prj
dep_dir=/data/deploy_www/$prj.dep.`date +%Y%m%d_%H%M%S`

function deploy_dev()
{
	rm -f $prj_dir
	mkdir -p $fpm_log_dir
fi

if [ -z "$env" ]; then
	echo "Usage: $0 ENV"
	echo "    ENV: dev, online"
	exit 1
fi


	mkdir -p /data/deploy_www
	chmod ugo+rx /data/deploy_www
	
	old_deploys=`ls /data/deploy_www/ | grep "^$prj\.dep\."`

	echo "copy files..."
	ln -sf $cur_dir/app/config/config_${env}.php $cur_dir/app/config/config.php
	ln -sf $cur_dir/app/config/nginx_${env}.conf $nginx_conf_dir/$prj.conf
}

deploy_online()
{
	mkdir -p /data/applogs/$prj
	chmod ugo+rwx /data/applogs /data/applogs/$prj

	mkdir -p /data/deploy_www
	chmod ugo+rx /data/deploy_www

	echo "copy files..."
	rsync -a --exclude '.*' $cur_dir/ $dep_dir/
	if [ $? -ne "0" ]; then
		echo "Failed to deploy project!"
		exit 1
	fi
	chmod ugo+rx $dep_dir

	done
}


echo ""
echo "#######################################"
if [ $? -eq 0 ]; then
	echo "update assets.json done."
else
	echo "update assets.json fail! please resolve it!"
fi
cd $cur_dir
# end update assets.json
	deploy_dev
fi


echo ""
echo "done."

<MSG> udpate

<DFF> @@ -13,6 +13,12 @@ fi
 prj_dir=/data/www/$prj
 dep_dir=/data/deploy_www/$prj.dep.`date +%Y%m%d_%H%M%S`
 
+fpm=php-fpm
+fpm_config=$prj_dir/app/config/php-fpm.conf
+fpm_pidfile=/var/run/php-fpm/$prj-php-fpm.pid
+nginx=/usr/sbin/nginx
+
+
 function deploy_dev()
 {
 	rm -f $prj_dir
@@ -28,7 +34,7 @@ function deploy_online()
 
 	mkdir -p /data/deploy_www
 	chmod ugo+rx /data/deploy_www
-	
+
 	old_deploys=`ls /data/deploy_www/ | grep "^$prj\.dep\."`
 
 	echo "copy files..."
@@ -55,6 +61,29 @@ function deploy_online()
 	done
 }
 
+start_fpm(){
+	$fpm -y $fpm_config -g $fpm_pidfile
+	if [ -f "$fpm_pidfile" ]; then
+		echo "php-fpm started."
+	else
+		echo "php-fpm failed!"
+	fi
+}
+
+stop_fpm(){
+	echo -n "stopping php-fpm"
+	while [ 1 ]; do 
+		if [ -f "$fpm_pidfile" ]; then
+			echo -n "."
+			kill `cat $fpm_pidfile`
+		else
+			echo " done."
+			break
+		fi
+		sleep 0.5
+	done
+}
+
 
 echo ""
 echo "#######################################"
@@ -68,6 +97,10 @@ else
 	deploy_dev
 fi
 
+stop_fpm
+start_fpm
+$nginx -s reload
+
 
 echo ""
 echo "done."

udpate