nginx init script for redhat (rhel5)
mike
mike503 at gmail.com
Tue Mar 17 06:51:23 MSK 2009
On Mon, Mar 16, 2009 at 8:44 PM, Cliff Wells <cliff at develix.com> wrote:
> Oops. Ignore that. Here's what I use:
>
> http://wiki.nginx.org/RedHatNginxInitScript
Got that in plaintext? It wants to copy all the whitespace in my browser too :P
For sharing sake this seems to be pretty foolproof too. Should kill
off rogue instances that don't match the pidfile etc.
even "reload" will restart it if it isn't actually running.
#!/bin/sh
#
# Init file for nginx
#
# chkconfig: 2345 55 25
# description: Nginx web server
#
# processname: nginx
# config: /usr/local/nginx/nginx.conf
# pidfile: /usr/local/nginx/nginx.pid
# Description: Startup script for nginx webserver on Debian. Place in
/etc/init.d and
# run 'sudo update-rc.d nginx defaults', or use the appropriate command on your
# distro. For CentOS/Redhat run: '/sbin/chkconfig --add nginx'
#
# Author: Ryan Norbauer <ryan.norbauer at gmail.com>
# Modified: Geoffrey Grosenbach http://topfunky.com
# Modified: David Krmpotic http://davidhq.com
# Modified: Vishnu Gopal http://vish.in
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/sbin/nginx
CONFIGFILE=/etc/nginx/nginx.conf
PIDFILE=/var/run/nginx.pid
SCRIPTNAME=/etc/init.d/nginx
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
d_start() {
$DAEMON -c $CONFIGFILE || echo -en "ERROR: Could not start.\n"
}
d_stop() {
if [ -f $PIDFILE ]; then
kill -QUIT `cat $PIDFILE` || echo -en "INFO: not running.\n"
fi
# force kill
pgrep -f "nginx:" | xargs --no-run-if-empty kill -9 2>/dev/null
rm -f $PIDFILE
}
d_reload() {
if [ -f $PIDFILE ]; then
kill -HUP `cat $PIDFILE` || echo -en "ERROR: can't reload.\n"
else
echo -en "NOTICE: can't reload, force (re)starting\n"
$SCRIPTNAME restart
fi
}
case "$1" in
start)
echo -en "Starting $DESC: $NAME\n"
d_start
;;
stop)
echo -en "Stopping $DESC: $NAME\n"
d_stop
;;
reload)
echo -en "Reloading $DESC configuration...\n"
d_reload
;;
restart)
echo -en "Restarting $DESC: $NAME\n"
d_stop
sleep 1
d_start
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
exit 3
;;
esac
exit 0
More information about the nginx
mailing list