# Lighttpd Restart Script

**URL:** <https://www.ruby-forum.com/t/lighttpd-restart-script/50519>\
**Category:** Rails\
**Created:** [December 17, 2005, 2:57pm UTC](https://www.ruby-forum.com/t/lighttpd-restart-script/50519 "2005-12-17T14:57:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nshb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df788c/32.png) [@nshb](https://www.ruby-forum.com/u/nshb)\
**Post date:** [December 17, 2005, 2:57pm UTC](https://www.ruby-forum.com/t/lighttpd-restart-script/50519/1 "2005-12-17T14:57:17Z")

</div>

After quite a bit of searching and coding, I customized an init.d/bash  
script which allows me to manage multiple instances of Lighttpd server  
running Rails.

It targets the specific PID address instead of the default binary  
location  
when starting and stopping /usr/local/bin/lighttpd process.

This provides the ability in my case to have multiple lighttpd.conf  
files  
running many different instances and be able to restart each without  
disturbing the next.

You can find the script at  
[http://www.nshb.net/lighttpd-restart-script.html](http://www.nshb.net/lighttpd-restart-script.html).  
Comments are welcome.

Regards,  
Nathaniel.

```auto
 Nathaniel S. H. Brown http://nshb.net

```

---

<div class="post-metadata">

**Author:** ![nshb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df788c/32.png) [@nshb](https://www.ruby-forum.com/u/nshb)\
**Post date:** [December 17, 2005, 10:16pm UTC](https://www.ruby-forum.com/t/lighttpd-restart-script/50519/2 "2005-12-17T22:16:06Z")

</div>

On Dec 17, 2005, at 5:58 AM, Nathaniel S. H. Brown wrote:

> running many different instances and be able to restart each without  
> Nathaniel S. H. Brown [http://nshb.net](http://nshb.net)  
> Cool. Thanks Nathaniel. I will check this one out. Will it let you  
> restart your fcgi’s without restarting lighttpd?

Cheers-  
-Ezra Z.  
WebMaster  
Yakima Herald-Republic Newspaper  
removed\_email\_address@domain.invalid  
509-577-7732

---

<div class="post-metadata">

**Author:** ![nshb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df788c/32.png) [@nshb](https://www.ruby-forum.com/u/nshb)\
**Post date:** [December 17, 2005, 10:19pm UTC](https://www.ruby-forum.com/t/lighttpd-restart-script/50519/3 "2005-12-17T22:19:07Z")

</div>

Ezra Z. wrote:

> > This provides the ability in my case to have multiple lighttpd.conf files  
> > running many different instances and be able to restart each without  
> > disturbing the next.
> > 
> > You can find the script at  
> > [http://www.nshb.net/lighttpd-restart-script.html](http://www.nshb.net/lighttpd-restart-script.html).  
> > Comments are welcome.
> 
> Cool. Thanks Nathaniel. I will check this one out.

Actually, I’ve been wondering about this. I’ve seen a number of posts  
recently  
about ways to restart Lighttpd and I’m not sure why that’s the case. How  
often  
are people changing their lighttpd.conf files? Is this a Windows thing  
that I’m  
just not seeing under Mac OS X and Linux?

> Will it let you restart your fcgi’s without restarting lighttpd?

This is what script/process/reaper is for. It’s pretty much the only  
thing I’ve  
used since it came out in 0.14.1/0.14.2 and it’s awesome. Plus, if you  
can  
configure your lighttpd to start as your user, then you can do  
script/process/reaper without needing sudo.

-Brian

---

<div class="post-metadata">

**Author:** ![nshb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df788c/32.png) [@nshb](https://www.ruby-forum.com/u/nshb)\
**Post date:** [December 18, 2005, 2:14am UTC](https://www.ruby-forum.com/t/lighttpd-restart-script/50519/4 "2005-12-18T02:14:22Z")

</div>

After reading this how-to,  
[Peak Obsession](http://wiki.rubyonrails.com/rails/pages/LighttpdWithProcessScripts).

You will find that by running the script/server and spinner/spawner  
instances that it runs a single instance for that process.

My server runs many domains, and requires each to have their own  
instance of  
the lighttpd being able to be managed without disturbing the next. The  
lighttpd.sh script that was included with the lighttpd 1.3.7 package  
when  
ran, starts the instance itself, but when I ran stop, it would kill all  
processes matching the /usr/local/bin/lighttpd binary. This package  
solves  
that by specifically addressing the PID file associated to the lighttpd  
instance for that configuration file.

In addition, the script that I have created can be placed in the  
/etc/init.d/ or rc.d directory and will be ran on boot time of the  
server,  
or manually managed by running the (start|stop|restart|reload|status)  
options on the script.

David G. had mentioned on his blog about using the @restart flag  
within  
the cron entry to manage the lighttpd instance. This will work well for  
starting the lighttpd server on reboot. But what happens if someone  
decides  
to killall -9 all the /usr/bin/local/lighttpd processes by accident?

In such a case to ensure that your server is always running, you want to  
be  
able to probe the lighttpd instance itself, and be able to ensure that  
it is  
always up, you can do so by running the bin/lighttd.sh script every 5  
minutes which will check to ensure the process is alive by checking the  
pid  
file and running a focused process status, and if the server is not  
running  
already it will start it for you.

Such as putting this in your crontab file.

\*/5 \* \* \* \* /home/httpd/vhosts/example.com/lighttpd/bin/lighttpd.sh  
start \>/dev/null 2\>&1

In addition to this bash script, I have just completed a full  
lighttpd-package template which I use to deploy my lighttpd installs on  
my  
system. And have made it available at  
[http://nshb.net/lighttpd-package.html](http://nshb.net/lighttpd-package.html)

Regards,  
Nathaniel.

```auto
 Nathaniel S. H. Brown http://nshb.net

```

---

<div class="post-metadata">

**Author:** ![nshb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df788c/32.png) [@nshb](https://www.ruby-forum.com/u/nshb)\
**Post date:** [December 18, 2005, 4:59am UTC](https://www.ruby-forum.com/t/lighttpd-restart-script/50519/5 "2005-12-18T04:59:30Z")

</div>

On 12/17/05 Brian V. Hughes wrote:

> for restarting the FastCGI listeners that control your app. Lighttpd  
> is really just a HTTP reverse proxy for the application, if it’s run  
> by FastCGI/SCGI.

Sorry, I meant Switchtower, not Scripttower. See, told you I wasn’t an  
expert,  
yet. 🙂

-Brian

---

<div class="post-metadata">

**Author:** ![nshb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df788c/32.png) [@nshb](https://www.ruby-forum.com/u/nshb)\
**Post date:** [December 18, 2005, 4:56am UTC](https://www.ruby-forum.com/t/lighttpd-restart-script/50519/6 "2005-12-18T04:56:30Z")

</div>

Nathaniel S. H. Brown wrote:

> After reading this how-to,  
> [Peak Obsession](http://wiki.rubyonrails.com/rails/pages/LighttpdWithProcessScripts).
> 
> You will find that by running the script/server and spinner/spawner  
> instances that it runs a single instance for that process.

I didn’t say anything about spinner and spawner. In fact, the stuff I’ve  
read  
seems to indicate that spinner/spawner are meant to be used with  
scripttower  
deployments. I was talking about the reaper command for restarting the  
FastCGI  
listeners that control your app. Lighttpd is really just a HTTP reverse  
proxy  
for the application, if it’s run by FastCGI/SCGI.

> My server runs many domains, and requires each to have their own instance of  
> the lighttpd being able to be managed without disturbing the next.

No problem. That’s not only easy to do, it’s one of the preferred ways  
that  
Lighttpd should be run, based on the stuff I’ve read. (I don’t claim to  
be a  
Lighttpd expert)

> The lighttpd.sh script that was included with the lighttpd 1.3.7 package when  
> ran, starts the instance itself, but when I ran stop, it would kill all  
> processes matching the /usr/local/bin/lighttpd binary. This package solves  
> that by specifically addressing the PID file associated to the lighttpd  
> instance for that configuration file.

My question is why are you starting and stopping the specific Lighttpd  
process,  
when there’s a better way to restart/reload your Rails application? Are  
you, in  
fact, making new changes to the lighttpd.conf file each time you start  
and stop  
Lighttpd? If not, then I don’t understand why you are bouncing that  
process.

> In addition, the script that I have created can be placed in the  
> /etc/init.d/ or rc.d directory and will be ran on boot time of the server,  
> or manually managed by running the (start|stop|restart|reload|status)  
> options on the script.

Having startups automatically happen is a good thing. But all you really  
need is  
something that calls Lighttpd with the specific .conf file for your  
app/domain/virtual host. Right? Am I missing something?

> David G. had mentioned on his blog about using the @restart flag within  
> the cron entry to manage the lighttpd instance. This will work well for  
> starting the lighttpd server on reboot. But what happens if someone decides  
> to killall -9 all the /usr/bin/local/lighttpd processes by accident?

If that last statement is indicative of what can happen on the  
production server  
that hosts your Rails apps, I’m really sorry to hear that. I guess,  
whatever you  
need to do to try and operate under those potential conditions is  
necessary.

> start \>/dev/null 2\>&1  
> Like I said. If there’s a possibility that someone with root access on  
> your  
> server would “accidentally” kill -9 just the Lighttpd processes,  
> whatever you  
> need to do to keep them running is fine by me. I would be looking for  
> another  
> server admin, or a new hosting service, rather than trying to deal with  
> that  
> level of potential accident.

> In addition to this bash script, I have just completed a full  
> lighttpd-package template which I use to deploy my lighttpd installs on my  
> system. And have made it available at [http://nshb.net/lighttpd-package.html](http://nshb.net/lighttpd-package.html)

Sounds good. I will most likely take a look, as I like to learn from  
those with  
more experience than me in the systems that run my  
applications/services.  
However, I’ve been running Lighttpd on my OS X Tiger server and I’ve  
never had a  
case where the Lighttpd process was accidentally killed (at least, not a  
case  
that didn’t coincide with a building/campus wide power outage that  
lasted longer  
than our UPS’s.

For those not in the extreme situation as Nathaniel, please quit mucking  
with  
your Lighttpd processes if you aren’t making changes to the associated  
conf file  
that you need to enable. Use reaper to reload your Rails app code and  
reset the  
page caches. Based on what I’ve read and how I’ve seen it used, that’s  
was  
reaper was built for…

## -Brian

Brian V. Hughes  
Associate Director for Web Operations (aka. Webmaster)  
Computing Technical Services  
Dartmouth College  
[http://www.dartmouth.edu/comp/](http://www.dartmouth.edu/comp/)

---

<div class="post-metadata">

**Author:** ![nshb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df788c/32.png) [@nshb](https://www.ruby-forum.com/u/nshb)\
**Post date:** [December 19, 2005, 7:06pm UTC](https://www.ruby-forum.com/t/lighttpd-restart-script/50519/7 "2005-12-19T19:06:16Z")

</div>

Nathaniel,

Thanks for the script! After months of fiddling around with this I  
finally found what I was looking for. The only thing I modified from  
your script was adding a DOMAIN line so I can multiply/modify the script  
easier and I also added a binary variable for sleep. Here are my mods:

# Binary Paths

CAT=“/bin/cat”  
PS=“/bin/ps”  
_SLEEP=“/bin/sleep”_  
HTTPD=“/usr/local/sbin/lighttpd”

# Modifiy this line for each install

_DOMAIN=“[xyz.abc.com](http://xyz.abc.com)”_  
PATH=“/home/abc/domains/”_$DOMAIN_"/run/"  
LIGHTTPD\_CONF=$PATH"lighttpd.conf"  
PIDFILE=$PATH"lighttpd.pid"

Thanks again,

Adrian M.  
HyperX Inc.  
Mobile: 801.815.1870  
Office: 801.566.0670  
removed\_email\_address@domain.invalid

> **[Custom Digital Marketing Solutions | Marketo Management](https://hyperxmarketing.com/)**
>
> Beautiful, automated, digital marketing solutions designed to maximize Marketo's power and integrate seamlessly with CRM and martech while delivering real results. HyperX is a marketing agency with more than 20 years in the business focused on...

9000 S. 45 W.  
Sandy, UT 84070
