# Starting lighttpd/Rails apps as user, not root

**URL:** <https://www.ruby-forum.com/t/starting-lighttpd-rails-apps-as-user-not-root/99834>\
**Category:** Rails\
**Created:** [February 1, 2006, 8:34pm UTC](https://www.ruby-forum.com/t/starting-lighttpd-rails-apps-as-user-not-root/99834 "2006-02-01T20:34:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![seanhussey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@seanhussey](https://www.ruby-forum.com/u/seanhussey)\
**Post date:** [February 1, 2006, 8:34pm UTC](https://www.ruby-forum.com/t/starting-lighttpd-rails-apps-as-user-not-root/99834/1 "2006-02-01T20:34:56Z")

</div>

Hi everyone,

When I want something to start at boot, I put it into /etc/rc\*. The  
service will start as root, though.

How do I make it start as a particular user? I’m worried about the  
machine going down and me not being around to pick my app back up when  
it does.

I think this would also help my SwitchTower issue of having 8 fastcgi  
processes running for the app. 4 started by lighttpd, and 4  
started/restarted when I deploy. Since the deployment user can’t kill  
the root-run fastcgi processes, they stay running.

Thanks,

Sean

---

<div class="post-metadata">

**Author:** ![seanhussey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@seanhussey](https://www.ruby-forum.com/u/seanhussey)\
**Post date:** [February 1, 2006, 8:43pm UTC](https://www.ruby-forum.com/t/starting-lighttpd-rails-apps-as-user-not-root/99834/2 "2006-02-01T20:43:24Z")

</div>

Sean H. wrote:

> Hi everyone,
> 
> When I want something to start at boot, I put it into /etc/rc\*. The  
> service will start as root, though.
> 
> How do I make it start as a particular user? I’m worried about the  
> machine going down and me not being around to pick my app back up when  
> it does.
> 
> I think this would also help my SwitchTower issue of having 8 fastcgi  
> processes running for the app. 4 started by lighttpd, and 4  
> started/restarted when I deploy. Since the deployment user can’t kill  
> the root-run fastcgi processes, they stay running.
> 
> Thanks,
> 
> Sean

add a cronjob at @reboot this will get executed at…well…reboot…

M

---

<div class="post-metadata">

**Author:** ![seanhussey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@seanhussey](https://www.ruby-forum.com/u/seanhussey)\
**Post date:** [February 1, 2006, 9:05pm UTC](https://www.ruby-forum.com/t/starting-lighttpd-rails-apps-as-user-not-root/99834/3 "2006-02-01T21:05:19Z")

</div>

On Wed, 2006-02-01 at 14:33 -0500, Sean H. wrote:

> Hi everyone,
> 
> When I want something to start at boot, I put it into /etc/rc\*. The  
> service will start as root, though.
> 
> How do I make it start as a particular user? I’m worried about the  
> machine going down and me not being around to pick my app back up when  
> it does.

* * *

## su - some\_user -c ‘/usr/sbin/lighttpd’ &

> I think this would also help my SwitchTower issue of having 8 fastcgi  
> processes running for the app. 4 started by lighttpd, and 4  
> started/restarted when I deploy. Since the deployment user can’t kill  
> the root-run fastcgi processes, they stay running.

* * *

I wouldn’t know about this

Craig

---

<div class="post-metadata">

**Author:** ![seanhussey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@seanhussey](https://www.ruby-forum.com/u/seanhussey)\
**Post date:** [February 1, 2006, 9:50pm UTC](https://www.ruby-forum.com/t/starting-lighttpd-rails-apps-as-user-not-root/99834/4 "2006-02-01T21:50:43Z")

</div>

In your lighttpd.conf you can specify user and and group and then (on  
Debian anyway) when it does the /etc/init.d/lighttpd start at bootup  
it will spawn as that user.

server.username = “www-data”  
server.groupname = “www-data”

Michael T.

---

<div class="post-metadata">

**Author:** ![seanhussey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@seanhussey](https://www.ruby-forum.com/u/seanhussey)\
**Post date:** [February 1, 2006, 10:42pm UTC](https://www.ruby-forum.com/t/starting-lighttpd-rails-apps-as-user-not-root/99834/5 "2006-02-01T22:42:22Z")

</div>

Michael and Brian, that’s the thing. Thanks!

On 2/1/06, Brian V. Hughes [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Yes. It makes the auto-deployment of your changed app code much smoother. Just  
> make sure you tell lighttpd to become the user that SwitchTower logs in as and  
> you should be all set. That’s basically what I’m doing for all my Rails apps,  
> although I don’t have ST wired into my deployment process, just yet…

Yes, that’s how I have it working now. The only missing piece was the  
server-running-as-user.

Thanks again!

Sean

---

<div class="post-metadata">

**Author:** ![seanhussey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@seanhussey](https://www.ruby-forum.com/u/seanhussey)\
**Post date:** [February 1, 2006, 9:56pm UTC](https://www.ruby-forum.com/t/starting-lighttpd-rails-apps-as-user-not-root/99834/6 "2006-02-01T21:56:47Z")

</div>

Sean H. wrote:

> When I want something to start at boot, I put it into /etc/rc\*. The  
> service will start as root, though.
> 
> How do I make it start as a particular user? I’m worried about the  
> machine going down and me not being around to pick my app back up when  
> it does.

I’m far from being a Unix guru, but your subject line specifically  
mentions  
lighttpd, which is something I can offer some assistance on.

Basically, you always want root to launch lighttpd, for a production  
Rails app,  
but what you do is you tell lighttpd to change its user and group when  
it  
launches. You do that with these lines in your lighttpd.conf:

server.username = “foo”  
server.groupname = “bar”

Since lighttpd is run as root, it can pretty much change its user and  
group, at  
will. The advantage is that since the lighttpd process becomes owned by  
user  
“foo”, any child processes launched by lighttpd are also owned by user  
“foo”. So  
when you have lighttpd launch the FastCGI listeners, they will be owned  
by user  
“foo”.

> I think this would also help my SwitchTower issue of having 8 fastcgi  
> processes running for the app. 4 started by lighttpd, and 4  
> started/restarted when I deploy. Since the deployment user can’t kill  
> the root-run fastcgi processes, they stay running.

Yes. It makes the auto-deployment of your changed app code much  
smoother. Just  
make sure you tell lighttpd to become the user that SwitchTower logs in  
as and  
you should be all set. That’s basically what I’m doing for all my Rails  
apps,  
although I don’t have ST wired into my deployment process, just yet…

-Brian
