欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Nginx和PHP-FPM的啟動(dòng)、重啟、停止腳本分享

 更新時(shí)間:2014年12月22日 09:24:36   投稿:junjie  
這篇文章主要介紹了Nginx和PHP-FPM的啟動(dòng)、重啟、停止腳本分享,腳本中包含start、stop、reload、restart等常用的管理方法,并可以加入系統(tǒng)服務(wù)然后使用servicem命令管理,需要的朋友可以參考下

服務(wù)器上的Nginx和PHP都是源碼編譯安裝的,不像ubuntu一樣有自帶service啟動(dòng)腳本,所以不支持類(lèi)似以前的nginx (start|restart|stop|reload)了。自己動(dòng)手豐衣足食。以下腳本應(yīng)該在RHEL, Fedora, CentOS下都適用。

一、Nginx啟動(dòng)腳本/etc/init.d/nginx

復(fù)制代碼 代碼如下:

#!/bin/bash
#
# Startup script for Nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /usr/local/nginx/conf/nginx.conf
# pidfile:     /usr/local/nginx/logs/nginx.pid
 
# Source function library.
. /etc/rc.d/init.d/functions
 
# Source networking configuration.
. /etc/sysconfig/network
 
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
 
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
 
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
 
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
 
lockfile=/var/lock/subsys/nginx
 
start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
 
stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
 
restart() {
    configtest || return $?
    stop
    sleep 1
    start
}
 
reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}
 
force_reload() {
    restart
}
 
configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}
 
rh_status() {
    status $prog
}
 
rh_status_q() {
    rh_status >/dev/null 2>&1
}
 
case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac

編輯好后保存,執(zhí)行以下命令
復(fù)制代碼 代碼如下:

sudo chmod +x /etc/init.d/nginx
sudo /sbin/chkconfig nginx on
# 檢查一下
sudo /sbin/chkconfig --list nginx
nginx           0:off   1:off   2:on    3:on    4:on    5:on    6:off

完成!可以使用以下命令管理Nginx了
復(fù)制代碼 代碼如下:

service nginx start
service nginx stop
service nginx restart
service nginx reload
 
/etc/init.d/nginx start
/etc/init.d/nginx stop
/etc/init.d/nginx restart
/etc/init.d/nginx reload

二、PHP-FPM啟動(dòng)腳本/etc/init.d/php-fpm
復(fù)制代碼 代碼如下:

#!/bin/bash
#
# Startup script for the PHP-FPM server.
#
# chkconfig: 345 85 15
# description: PHP is an HTML-embedded scripting language
# processname: php-fpm
# config: /usr/local/php/etc/php.ini
 
# Source function library.
. /etc/rc.d/init.d/functions
 
PHP_PATH=/usr/local
DESC="php-fpm daemon"
NAME=php-fpm
# php-fpm路徑
DAEMON=$PHP_PATH/php/sbin/$NAME
# 配置文件路徑
CONFIGFILE=$PHP_PATH/php/etc/php-fpm.conf
# PID文件路徑(在php-fpm.conf設(shè)置)
PIDFILE=$PHP_PATH/php/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
 
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
 
rh_start() {
  $DAEMON -y $CONFIGFILE || echo -n " already running"
}
 
rh_stop() {
  kill -QUIT `cat $PIDFILE` || echo -n " not running"
}
 
rh_reload() {
  kill -HUP `cat $PIDFILE` || echo -n " can't reload"
}
 
case "$1" in
  start)
        echo -n "Starting $DESC: $NAME"
        rh_start
        echo "."
        ;;
  stop)
        echo -n "Stopping $DESC: $NAME"
        rh_stop
        echo "."
        ;;
  reload)
        echo -n "Reloading $DESC configuration..."
        rh_reload
        echo "reloaded."
  ;;
  restart)
        echo -n "Restarting $DESC: $NAME"
        rh_stop
        sleep 1
        rh_start
        echo "."
        ;;
  *)
         echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
         exit 3
        ;;
esac
exit 0

編輯好后保存,執(zhí)行以下命令
復(fù)制代碼 代碼如下:

sudo chmod +x /etc/init.d/php-fpm
sudo /sbin/chkconfig php-fpm on
# 檢查一下
sudo /sbin/chkconfig --list php-fpm
php-fpm           0:off   1:off   2:on    3:on    4:on    5:on    6:off

完成!可以使用以下命令管理php-fpm了
復(fù)制代碼 代碼如下:

service php-fpm start
service php-fpm stop
service php-fpm restart
service php-fpm reload
 
/etc/init.d/php-fpm start
/etc/init.d/php-fpm stop
/etc/init.d/php-fpm restart
/etc/init.d/php-fpm reload

相關(guān)文章

  • shell中實(shí)用eval命令和安全問(wèn)題

    shell中實(shí)用eval命令和安全問(wèn)題

    eval命令非常強(qiáng)大,但也非常容易被濫用,本文主要介紹了shell中實(shí)用eval命令和安全問(wèn)題,具有一定的參考價(jià)值,感興趣的可以了解一下
    2023-10-10
  • linux系統(tǒng)安裝字體詳細(xì)介紹

    linux系統(tǒng)安裝字體詳細(xì)介紹

    這篇文章主要介紹了linux系統(tǒng)安裝字體詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下
    2017-05-05
  • linux?iptables防火墻中的工作常用命令

    linux?iptables防火墻中的工作常用命令

    linux系統(tǒng)的防火墻,IP信息包過(guò)濾u系統(tǒng),它實(shí)際上由兩個(gè)組件netfilter和iptables組成,這篇文章主要介紹了linux?iptables防火墻-工作常用命令,需要的朋友可以參考下
    2022-10-10
  • shell腳本一鍵安裝php7的實(shí)例(推薦)

    shell腳本一鍵安裝php7的實(shí)例(推薦)

    下面小編就為大家?guī)?lái)一篇shell腳本一鍵安裝php7的實(shí)例(推薦)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-10-10
  • 自動(dòng)殺掉占用較多CPU資源的Shell腳本

    自動(dòng)殺掉占用較多CPU資源的Shell腳本

    這篇文章主要介紹了自動(dòng)殺掉占用較多CPU資源的Shell腳本,需要的朋友可以參考下
    2014-06-06
  • linux文件目錄默認(rèn)權(quán)限(詳解)

    linux文件目錄默認(rèn)權(quán)限(詳解)

    下面小編就為大家?guī)?lái)一篇linux文件目錄默認(rèn)權(quán)限(詳解)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-02-02
  • linux shell中的比較符號(hào)與特殊符號(hào)介紹

    linux shell中的比較符號(hào)與特殊符號(hào)介紹

    本文為大家介紹linux shell中的特殊符號(hào),包括字符串比較、數(shù)字比較與計(jì)算、特殊字符等,學(xué)習(xí)shell的朋友可以看下
    2013-06-06
  • shell判斷變量是否含某個(gè)字符串的6種方法

    shell判斷變量是否含某個(gè)字符串的6種方法

    本文主要介紹了shell判斷變量是否含某個(gè)字符串的6種方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-05-05
  • 在Linux中查找 IP 地址的3種方法

    在Linux中查找 IP 地址的3種方法

    在 Linux 系統(tǒng)中,經(jīng)常需要查找 IP 地址以進(jìn)行網(wǎng)絡(luò)配置、故障排除或安全管理,無(wú)論是查找本地主機(jī)的 IP 地址還是查找其他設(shè)備的 IP 地址,本文將介紹三種簡(jiǎn)單的方法,幫助你在 Linux 中輕松找到所需的 IP 地址,需要的朋友可以參考下
    2023-09-09
  • 反彈shell的幾種姿勢(shì)小結(jié)

    反彈shell的幾種姿勢(shì)小結(jié)

    在滲透過(guò)程中,往往因?yàn)槎丝谙拗贫鵁o(wú)法直連目標(biāo)機(jī)器,此時(shí)需要通過(guò)反彈shell來(lái)獲取一個(gè)交互式shell,以便繼續(xù)深入,本文就介紹了幾種方法,感興趣的可以了解一下
    2021-07-07

最新評(píng)論