溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

如何在Linux下創(chuàng)建nginx腳本-start、stop、reload…

發(fā)布時(shí)間:2021-07-01 09:32:37 來(lái)源:億速云 閱讀:521 作者:chen 欄目:開(kāi)發(fā)技術(shù)

這篇文章主要講解了“如何在Linux下創(chuàng)建nginx腳本-start、stop、reload…”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“如何在Linux下創(chuàng)建nginx腳本-start、stop、reload…”吧!

1、關(guān)閉nginx
利用ps -aux | grep nginx 查看nginx是否啟動(dòng) 如果啟動(dòng)了就kill殺死
2、創(chuàng)建/etc/init.d/nginx文件

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

3、添加權(quán)限并啟動(dòng)

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

注:/etc/init.d/nginx文件內(nèi)容如下

#! /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/bin
DAEMON=/usr/local/nginx/sbin/nginx
NAME=nginx
DESC=nginx
 
test -x $DAEMON || exit 0
 
# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
  . /etc/default/nginx
#    . /usr/local/nginx/conf
fi
 
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

感謝各位的閱讀,以上就是“如何在Linux下創(chuàng)建nginx腳本-start、stop、reload…”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)如何在Linux下創(chuàng)建nginx腳本-start、stop、reload…這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI