码迷,mamicode.com
首页 > 其他好文 > 详细

管理http服务的脚本

时间:2014-05-15 13:32:57      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:des   class   code   c   tar   http   

由于老是需要重新安装系统,重一次都要重新设置http服务的启动脚本。麻烦,所以这一次就把脚本备份出来。

httpd for Ubuntu

system: nginx + php-fpm

#! /bin/sh
### BEGIN INIT INFO
# Provides:          httpd
# Required-Start:    $all
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: Run http server
### END INIT INFO

exec_phpfpm="/opt/php5/sbin/php-fpm"
pid_phpfpm="/run/php-fpm.pid"
exec_nginx="/opt/nginx/sbin/nginx"
pid_nginx="/run/nginx.pid"

## 停止php-fpm服务
do_stop_phpfpm() {
    echo -n "Stoping php-fpm... "
    kill -QUIT `cat ${pid_phpfpm}` > /dev/null 2>&1
    if [ $? -eq 0 ];then
        show_success
    else
        show_failed
    fi
    echo ""
}

## 输出OK
show_success() {
	echo -n "\033[32m [OK] \033[0m"
}

## 输出NO
show_failed() {
	echo -n "\033[37m [NO] \033[0m"
}

## 启动php-fpm服务
do_start_phpfpm() {
    echo -n "starting php-fpm... "
    $exec_phpfpm -g $pid_phpfpm > /dev/null 2>&1
    if [ $? -eq 0 ];then
		show_success
    else
        echo -n "\033[37m [NO] \033[0m"
    fi
    echo ""
}

## nignx重新加载设置
do_reload_nginx() {
    $exec_nginx -s reload > /dev/null 2>&1
    echo "\033[32m nginx reload config successfully. \033[0m"
}

## 启动nginx服务
do_start_nginx() {
	 echo -n "Starting nginx... "
    $exec_nginx > /dev/null 2>&1
    if [ $? -eq 0 ];then
		show_success
    else
        show_failed
    fi
    echo
}

##  停止nginx服务
do_stop_nginx() {
	echo -n "Stoping nginx..."
	$exec_nginx -s stop > /dev/null 2>&1
	if [ $? -eq 0 ];then
		show_success
    else
        show_failed
    fi
    echo
}

case $1 in
start)
echo "starting httpd server..."
do_start_phpfpm
do_start_nginx
;;
stop_phpfpm)
echo "stoping php-fpm server..."
do_stop_phpfpm
;;
stop_nginx)
echo "stoping nginx server..."
do_stop_nginx
;;
start_nginx)
echo "starting nginx server..."
do_start_nginx
;;
restart_nginx)
echo "restart nginx server..."
do_stop_nginx
do_start_nginx
;;
restart_phpfpm)
echo "restart php-fpm server..."
do_stop_phpfpm
do_start_phpfpm
;;
restart)
echo "restart httpd server..."
do_stop_phpfpm
do_stop_nginx
do_start_phpfpm
do_start_nginx
;;
stop)
echo "stop httpd server..."
do_stop_phpfpm
do_stop_nginx
;;
reload)
echo "reload nginx config"
do_reload_nginx
;;
*)
echo "USE:httpd start|restart|reload|stop|restart_phpfpm|stop_phpfpm|stop_nginx|start_nginx"
;;
esac

exit 0


管理http服务的脚本,布布扣,bubuko.com

管理http服务的脚本

标签:des   class   code   c   tar   http   

原文地址:http://blog.csdn.net/yagas/article/details/25877577

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!