CentOS6.3 Add a detailed example of nginx system services
- 2020-06-19 12:27:55
- OfStack
CentOS 6.3 adds example details of nginx system services
Preface:
Today the VIRTUAL machine is equipped with a server to sort out this nginx service
Pay attention to this symbol - see if there is any messy code after copying it. I have encountered this problem before, and it took me a long time to find it
Tip: Do not remove the comment at the top or you will not be able to register as a system service,
About: chkconfig: 2345 65 37
Online search summed up the following meaning:
The values of 65 and 37 cannot be the same, nor can they conflict with the values of other services. I have never encountered this problem. If you find any problem, please modify it according to your own configuration
New file:
# vi /etc/init.d/nginx
Input Content:
#!/bin/sh
# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 65 37
# description: A nginx daemon.
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
SCRIPTNAME=/etc/init.d/$NAME
# If the daemon file is not found, terminate the script.
test -x $DAEMON || exit 0
d_test() {
$DAEMON -t
}
d_start() {
$DAEMON || echo -n " already running"
}
d_stop() {
$DAEMON -s quit || echo -n " not running"
}
d_reload() {
$DAEMON -s reload || echo -n " could not reload"
}
case "$1" in
test)
d_test
echo "."
;;
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
reload)
echo -n "Reloading $DESC configuration..."
d_reload
echo "reloaded."
;;
restart)
echo -n "Restarting $DESC: $NAME"
d_stop
# Sleep for two seconds before starting again, this should give the
# Nginx daemon some time to perform a graceful stop.
sleep 2
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {test|start|stop|restart|reload}" >&2
exit 3
;;
esac
exit $?
Register for nginx service:
chmod +x /etc/init.d/nginx
chkconfig --add nginx
chkconfig --level 2345 nginx on
chkconfig --list nginx
Related nginx commands:
Detect the nginx configuration
# service nginx test
Start the
# service nginx start
Shut down
# service nginx stop
restart
# service nginx restart
reload
# service nginx reload
If you have any questions, please leave a message or go to this site community exchange discussion, thank you for reading, hope to help you, thank you for your support to this site!