Creating PID File?

Neil Sheth nsheth at gmail.com
Thu Mar 20 05:59:04 MSK 2008


I'm having some issues with the creation of a pid file.  It looks like
log rotation for nginx fails (on occasion).  What happens is that it
can't find a pid file, so it doesn't know where to send the -USR1
signal.  Not sure if I have to do something in particular to make the
startup script generate a pid file?  Here's the current startup script
I have, I'm running on Red Hat Enterprise Linux ES 4.  Any thoughts?
Thanks for the help!

#!/bin/bash
# v.0.0.2
# nginx - This shell script takes care of starting and stopping nginx.
#
# chkconfig: - 60 50
# description: nginx [engine x] is light http web/proxy server
#              that answers incoming ftp service requests.
# processname: nginx
# config: /etc/nginx/nginx.conf

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

[ -x /usr/sbin/nginx ] || exit 0

RETVAL=0
prog="nginx"

start() {
        # Start daemons.
        if [ -e /etc/nginx/nginx.conf ] ; then

            echo -n $"Starting $prog: "
             /usr/sbin/nginx -c /etc/nginx/nginx.conf &
                        RETVAL=$?
                        [ $RETVAL -eq 0 ] && {
                           touch /var/lock/subsys/$prog
                           success $"$prog"
                        }
                        echo
        else
                RETVAL=1
        fi
        return $RETVAL
}

stop() {
        # Stop daemons.
        echo -n $"Shutting down $prog: "
        kill -3 `cat /var/run/nginx.pid 2>/dev/null`
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
        return $RETVAL
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  reconfigure)
        if [ -f /var/lock/subsys/$prog ]; then
            kill -1 `cat /var/run/nginx.pid 2>/dev/null`
            RETVAL=$?
        fi
        ;;
  status)
        status $prog
        RETVAL=$?
        ;;
  *)
        echo $"Usage: $0 {start|stop|reconfigure|status}"
        exit 1
esac

exit $RETVAL





More information about the nginx mailing list