Daemonizing

Asked by Adam Nelson

Does anybody have best practices for daemonizing Gunicorn, specifically gunicorn_django? Ideally I could run this through 'service' and run something like:

sudo update-rc.d gunicorn defaults

It doesn't look like that's available yet though.

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu gunicorn Edit question
Assignee:
No assignee Edit question
Solved by:
Eliah Kagan
Solved:
Last query:
Last reply:
Revision history for this message
Eliah Kagan (degeneracypressure) said :
#1

To run gunicorn as a daemon, pass the -D option. See http://manpages.ubuntu.com/manpages/maverick/man1/gunicorn.1.html.

Or are you asking about how to make it start up at boot-time?

Revision history for this message
Adam Nelson (adam-varud) said :
#2

I'm sorry, I should have been more clear. I'm looking to handle
starting up at boot time and controlling the process without knowing
the PID (i.e. an upstart or init or supervisord or runit script).

On Fri, Mar 4, 2011 at 5:11 AM, Eliah Kagan
<email address hidden> wrote:
> Your question #147702 on gunicorn in ubuntu changed:
> https://answers.launchpad.net/ubuntu/+source/gunicorn/+question/147702
>
>    Status: Open => Answered
>
> Eliah Kagan proposed the following answer:
> To run gunicorn as a daemon, pass the -D option. See
> http://manpages.ubuntu.com/manpages/maverick/man1/gunicorn.1.html.
>
> Or are you asking about how to make it start up at boot-time?
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
> https://answers.launchpad.net/ubuntu/+source/gunicorn/+question/147702/+confirm?answer_id=0
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/ubuntu/+source/gunicorn/+question/147702
>
> You received this question notification because you are a direct
> subscriber of the question.
>

--
Adam

Revision history for this message
Best Eliah Kagan (degeneracypressure) said :
#3

To make gunicorn run via upstart at boot-time (which is probably what you want), add a .conf file in the directory /etc/init for it (you might call it gunicorn.conf), and write the conf file to perform the desired actions. Remember use the command "gunicorn -D" (or, equivalently, "gunicorn --daemon") rather than simply "gunicorn". See http://upstart.ubuntu.com/getting-started.html for information on how to write .conf files for upstart (skip down to "Writing Jobs").

A Google search for "gunicorn upstart" (without the quotes) yielded, among other things, https://gist.github.com/500414/ebf54c086c9a38840655454337a4d83fac89c46f, which might be a source for ideas (if you have to do more than just start gunicorn and let it run, which can do with a single "exec gunicorn -D" stanza).

Revision history for this message
Adam Nelson (adam-varud) said :
#4

Thanks for the help. We ended up using supervisord because it was easier to set up for our situation (we need 8 different workers with different settings files). One thing to note when using supervisord is to not use the -D flag (supervisord wants a non-daemonized process).