Linux下建立nginx指令碼-start、stop、reload…_php技巧

來源:互聯網
上載者:User

1、關閉nginx
利用ps -aux | grep nginx 查看nginx是否啟動 如果啟動了就kill殺死
2、建立/etc/init.d/nginx檔案

root@dnnp:~/software/nginx-1.2.3# vim /etc/init.d/nginx

3、添加許可權並啟動

root@dnnp:~/software/nginx-1.2.3# chmod +x /etc/init.d/nginxroot@dnnp:~/software/nginx-1.2.3# /etc/init.d/nginx startStarting nginx: nginx.root@dnnp:~/software/nginx-1.2.3# ps -aux | grep nginxWarning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.htmlroot   25078 0.0 0.0  4596  700 ?    Ss  14:20  0:00 nginx: master process /usr/local/nginx/sbin/nginxnobody  25079 0.0 0.1  4820 1056 ?    S  14:20  0:00 nginx: worker processroot   25081 0.0 0.0  3304  768 pts/0  S+  14:20  0:00 grep nginxroot@dnnp:~/software/nginx-1.2.3#

註:/etc/init.d/nginx檔案內容如下

#! /bin/sh ### BEGIN INIT INFO# Provides:     nginx# Required-Start:  $all# Required-Stop:   $all# Default-Start:   2 3 4 5# Default-Stop:   0 1 6# Short-Description: starts the nginx web server# Description:    starts nginx using start-stop-daemon### END INIT INFO PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/binDAEMON=/usr/local/nginx/sbin/nginxNAME=nginxDESC=nginx test -x $DAEMON || exit 0 # Include nginx defaults if availableif [ -f /etc/default/nginx ] ; then  . /etc/default/nginx#    . /usr/local/nginx/conffi set -e . /lib/lsb/init-functions case "$1" in start)  echo -n "Starting $DESC: "  start-stop-daemon --start --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \    --exec $DAEMON -- $DAEMON_OPTS || true  echo "$NAME."  ;; stop)  echo -n "Stopping $DESC: "  start-stop-daemon --stop --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \    --exec $DAEMON || true  echo "$NAME."  ;; restart|force-reload)  echo -n "Restarting $DESC: "  start-stop-daemon --stop --quiet --pidfile \    /usr/local/nginx/logs/$NAME.pid --exec $DAEMON || true  sleep 1  start-stop-daemon --start --quiet --pidfile \    /usr/local/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true  echo "$NAME."  ;; reload)   echo -n "Reloading $DESC configuration: "   start-stop-daemon --stop --signal HUP --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \     --exec $DAEMON || true   echo "$NAME."   ;; status)   status_of_proc -p /usr/local/nginx/logs/$NAME.pid "$DAEMON" nginx && exit 0 || exit $?   ;; *)  N=/etc/init.d/$NAME  echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2  exit 1  ;;esac exit 0

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.