# Nginx service can not auto start

**URL:** <https://www.ruby-forum.com/t/nginx-service-can-not-auto-start/188595>\
**Category:** NGINX\
**Created:** [May 14, 2010, 4:00pm UTC](https://www.ruby-forum.com/t/nginx-service-can-not-auto-start/188595 "2010-05-14T16:00:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![wangyu1314](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a3d4f5/32.png) [@wangyu1314](https://www.ruby-forum.com/u/wangyu1314)\
**Post date:** [May 14, 2010, 4:00pm UTC](https://www.ruby-forum.com/t/nginx-service-can-not-auto-start/188595/1 "2010-05-14T16:00:14Z")

</div>

I am using nginx on redhat for a very long time, I found a service  
script, installed nginx as a service to redhat, it is fine.  
but I found a bug, that after dirty shutdown, nginx service can not  
auto start, and i only start it by hand.  
please help me, blow is the service script:

#!/bin/bash

# nginx Startup script for the Nginx HTTP Server

# this script create it by jackbillow at 2007.10.15.

# it is v.0.0.2 version.

# if you find any errors on this scripts,please contact jackbillow.

# and send mail to jackbillow at gmail dot com.

# chkconfig: - 85 15

# description: Nginx is a high-performance web and proxy server.

# It has a lot of features, but it’s not for everyone.

# processname: nginx

# pidfile: /usr/local/webserver/nginx/logs/nginx.pid

# config: /usr/local/webserver/nginx/conf/nginx.conf

nginx=/usr/local/webserver/nginx/sbin/nginx  
nginx\_config=/usr/local/webserver/nginx/conf/nginx.conf  
nginx\_pid=/usr/local/webserver/nginx/logs/nginx.pid

RETVAL=0  
prog=“nginx”

# 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 $nginx] || exit 0

# Start nginx daemons functions.

start() {

if [-e $nginx\_pid];then  
echo “nginx already running…”  
exit 1  
fi

echo -n $"Starting $prog: "  
daemon $nginx -c ${nginx\_config}  
RETVAL=$?  
echo  
[$RETVAL = 0] && touch /var/lock/subsys/nginx  
return $RETVAL

}

# Stop nginx daemons functions.

stop() {  
echo -n $"Stopping $prog: "  
killproc $nginx  
RETVAL=$?  
echo  
[$RETVAL = 0] && rm -f /var/lock/subsys/nginx  
/usr/local/webserver/nginx/logs/nginx.pid  
}

# reload nginx service functions.

reload() {

```
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginx -HUP
RETVAL=$?
echo

```

}

# See how we were called.

case “$1” in  
start)  
start  
;;

stop)  
stop  
;;

reload)  
reload  
;;

restart)  
stop  
start  
;;

status)  
status $prog  
RETVAL=$?  
;;  
\*)  
echo $“Usage: $prog {start|stop|restart|reload|status|help}”  
exit 1  
esac

exit $RETVAL

Posted at Nginx Forum:

> **[nginx service can not auto start](https://forum.nginx.org/read.php?2,86637,86637#msg-86637)**
>
> I am using nginx on redhat for a very long time, I found a service script, installed nginx as a service to redhat, it is fine. but I found a bug, that after dirty shutdown, nginx service can not auto start, and i only start it by hand. please help...

---

<div class="post-metadata">

**Author:** ![wangyu1314](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a3d4f5/32.png) [@wangyu1314](https://www.ruby-forum.com/u/wangyu1314)\
**Post date:** [May 14, 2010, 4:14pm UTC](https://www.ruby-forum.com/t/nginx-service-can-not-auto-start/188595/2 "2010-05-14T16:14:52Z")

</div>

# chkconfig nginx on

On Fri, May 14, 2010 at 9:58 PM, wangyu1314 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I am using nginx on redhat for a Â very long time, I found a service script, installed nginx as a service to redhat, it is fine.  
> but I found a bug, that after dirty shutdown, Â nginx service can not auto start, and i only start it by hand.

–  
Ren Xiaolei

---

<div class="post-metadata">

**Author:** ![wangyu1314](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a3d4f5/32.png) [@wangyu1314](https://www.ruby-forum.com/u/wangyu1314)\
**Post date:** [May 14, 2010, 4:17pm UTC](https://www.ruby-forum.com/t/nginx-service-can-not-auto-start/188595/3 "2010-05-14T16:17:12Z")

</div>

Any output in log files for the service? Can you show how you start  
nginx by  
hand and then how the script runs (set -x)?

-peter

---

<div class="post-metadata">

**Author:** ![wangyu1314](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a3d4f5/32.png) [@wangyu1314](https://www.ruby-forum.com/u/wangyu1314)\
**Post date:** [May 14, 2010, 4:34pm UTC](https://www.ruby-forum.com/t/nginx-service-can-not-auto-start/188595/4 "2010-05-14T16:34:11Z")

</div>

On 14.05.2010 16:58, wangyu1314 wrote:

> I am using nginx on redhat for a very long time, I found a service script, installed nginx as a service to redhat, it is fine.  
> but I found a bug, that after dirty shutdown, nginx service can not auto start, and i only start it by hand.  
> please help me

place nginx-init.txt from attach to /etc/init.d/nginx  
place nginx-sysconfig.txt from attach to /etc/sysconfig/nginx  
edit path inside init script and config to yours.

> start() {  
> if [-e $nginx\_pid];then  
> echo “nginx already running…”  
> exit 1

bug here: $nginx\_pid file exists after dirty shundown

---

<div class="post-metadata">

**Author:** ![wangyu1314](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a3d4f5/32.png) [@wangyu1314](https://www.ruby-forum.com/u/wangyu1314)\
**Post date:** [May 15, 2010, 7:13am UTC](https://www.ruby-forum.com/t/nginx-service-can-not-auto-start/188595/5 "2010-05-15T07:13:19Z")

</div>

Thanks very much, Peter Portante and Gena M…  
I am testing Gena M.â€˜s script, if have some news i would reports  
again.

Posted at Nginx Forum:

> **[Re: nginx service can not auto start](https://forum.nginx.org/read.php?2,86637,86860#msg-86860)**
>
> I am using nginx on redhat for a very long time, I found a service script, installed nginx as a service to redhat, it is fine. but I found a bug, that after dirty shutdown, nginx service can not auto start, and i only start it by hand. please help...

---

<div class="post-metadata">

**Author:** ![wangyu1314](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a3d4f5/32.png) [@wangyu1314](https://www.ruby-forum.com/u/wangyu1314)\
**Post date:** [May 15, 2010, 12:18pm UTC](https://www.ruby-forum.com/t/nginx-service-can-not-auto-start/188595/6 "2010-05-15T12:18:57Z")

</div>

thanks.  
it’s not this reason.  
because i have done it:

chmod 755 /etc/init.d/nginx  
chkconfig --add nginx  
chkconfig --level 345 nginx on

Posted at Nginx Forum:

> **[Re: nginx service can not auto start](https://forum.nginx.org/read.php?2,86642,86903#msg-86903)**
>
> \# chkconfig nginx on On Fri, May 14, 2010 at 9:58 PM, wangyu1314 \<nginx-forum@nginx.us\> wrote: \> I am using nginx on redhat for a  very long time, I found a service script, installed nginx as a service to redhat, it is fine. \> but I found...
