Creating PID File?

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

Not that it means much of anything but we have lots of weird, funky
pid file goes missing, nginx wont reload or restart type issues on the
last remaining red hat box that we have. No idea where it came from,
not investigating either as it works fine on all our debian machines.

#!/sbin/runscript

Copyright 1999-2004 Gentoo Foundation

Distributed under the terms of the GNU General Public License v2

$Header: /var/cvsroot/gentoo-x86/www-servers/nginx/files/nginx-r1,v

1.12006/07/04 16:58:38 voxus Exp $

opts="${opts} upgrade reload configtest"

depend() {
need net
use dns logger
}

start() {
configtest || return 1
ebegin “Starting nginx”
start-stop-daemon --start --pidfile /var/run/nginx.pid
–exec /usr/sbin/nginx – -c /etc/nginx/nginx.conf
eend $? “Failed to start nginx”
}

stop() {
configtest || return 1
ebegin “Stopping nginx”
start-stop-daemon --stop --pidfile /var/run/nginx.pid
eend $? “Failed to stop nginx”
rm -f /var/run/nginx.pid
}

reload() {
configtest || return 1
ebegin “Refreshing nginx’ configuration”
kill -HUP cat /var/run/nginx.pid &>/dev/null
eend $? “Failed to reload nginx”
}

upgrade() {
configtest || return 1
ebegin “Upgrading nginx”

    einfo "Sending USR2 to old binary"
    kill -USR2 `cat /var/run/nginx.pid` &>/dev/null

    einfo "Sleeping 3 seconds before pid-files checking"
    sleep 3

    if [ ! -f /var/run/nginx.pid.oldbin ]; then
            eerror "File with old pid not found"
            return 1
    fi

    if [ ! -f /var/run/nginx.pid ]; then
            eerror "New binary failed to start"
            return 1
    fi

    einfo "Sleeping 3 seconds before WINCH"
    sleep 3 ; kill -WINCH `cat /var/run/nginx.pid.oldbin`

    einfo "Sending QUIT to old binary"
    kill -QUIT `cat /var/run/nginx.pid.oldbin`

    einfo "Upgrade completed"

    eend $? "Upgrade failed"

}

configtest() {
ebegin “Checking nginx’ configuration”
/usr/sbin/nginx -c /etc/nginx/nginx.conf -t
eend $? “failed, please correct errors above”
}

Is this specific to Gentoo?

No! For every linux distribution

On Fri, Mar 21, 2008 at 4:11 AM, Neil S. [email protected] wrote:

     start-stop-daemon --start --pidfile /var/run/nginx.pid \

}
ebegin “Upgrading nginx”
fi
kill -QUIT cat /var/run/nginx.pid.oldbin
}


Please excuse my bad english…

С уважение,
Й. Георгиев.

WEB: http://gigavolt-bg.net/
Blog: http://live.gigavolt-bg.net/