由于老是需要重新安装系统,重一次都要重新设置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服务的脚本
时间: 2024-10-29 03:05:11