work, study, life ..........

Tuesday, March 3, 2009

ngnix 启动脚本

#!/bin/bash

####################
# Author: qing
# Data: Aug 2008
####################

Phpcgi=”/opt/php/sbin/php-fpm”
Tool=”/opt/ngnix/sbin/nginx -c”
Confile=”/opt/ngnix/conf/nginx.conf”
Pidfile=”/opt/ngnix/logs/nginx.pid”
Pcgiconf=”/opt/php/etc/php-fpm.conf”

start(){
if [ -e “$Pidfile” -a ! -z “$Pidfile” ] ; then
echo “Nginx is running …………..”
exit 1
fi

if [ -f “$Confile” ]
then
if [ -f “$Pcgiconf” ] ; then
echo -n $”Staring PHPCGI:”
$Phpcgi start
else
exit 1
fi
echo -n $”Staring Nginx :”
$Tool $Confile
if [ $? -eq 0 ];then
echo -n $”Nginx has started”
else
echo “Nginx has an error when is starting”
fi
fi
exit 0
}

stop(){
if [ ! -f “$Pidfile” ]; then
echo “Nginx didn’t run!!!”;
exit 1
else
$Phpcgi stop
PID=`cat $Pidfile`
if kill $PID 2> /dev/null; then
kill $PID
rm -f $Pidfile
echo “Stopping Nginx:”
else
echo “Stopping Nginx:”
echo “Nginx is not running, but PID file exists”
exit 1
fi
fi
}

restart(){
stop
start
}
case “$1″ in
start) start
;;
stop) stop
;;
restart) restart
;;
*) echo “Usage: `basename $0` [ star | stop | restart] ”
;;
esac
exit 0

No comments: