Create nginx scripts in Linux-start, stop, reload...

Source: Internet
Author: User
This article describes how to create nginx scripts-start, stop, and reload in Linux. For more information, see section 1. disable nginx.
Use ps-aux | grep nginx to check whether nginx is started. if so, kill and kill.
2. create the/etc/init. d/nginx file.

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

3. add permissions and start

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#

Note: the content of the/etc/init. d/nginx file is as follows:

#! /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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.