189 Commits

Author SHA1 Message Date
Berker Peksag
829e8d32d4 Remove __future__.with_statement imports.
Gunicorn requires Python 2.6 or newer now:

http://docs.gunicorn.org/en/latest/install.html#requirements
2014-05-15 00:34:02 +03:00
Randall Leeds
b9d291e692 Merge pull request #745 from tilgovi/worker-signals-mixup
Fix mixed up worker signal handling
2014-05-14 12:18:37 -07:00
Nick Pillitteri
9c1b46f998 Move setting of environmental variables before preload_app start.
Move setting of env vars from Arbiter.start to Arbiter.setup so that they are available during application start up when 'preload_app' is used.

Closes #735
2014-05-13 15:46:06 -04:00
Randall Leeds
63967597a0 Fix mixed up worker signal handling
Commit 81241907ffcf94517ffa14b8427205906b61b540 changed the signal
handling by switching the roles of `TERM` and `QUIT` for the arbiter
so that `TERM` is graceful and `QUIT` is not.

At the time, workers performed graceful shutdown on `QUIT` and quick
shutdown on `TERM` and `INT`. This behavior was also changed so that
`QUIT` (and `INT`) cause a quick shutdown and `TERM` is graceful.

However, the documentation incorrectly reversed the roles of the worker
signals and the arbiter was not updated to use the correct signals.

This commit fixes the documentation and the arbiter signals.
2014-05-13 11:12:01 -07:00
Randall Leeds
20ed91497c Do not swallow unexpected errors when reaping
I can't imagine this wasn't what was intended here. Might be a merge
artifact but I can't trace it.

Thanks to Antti Kaihola (@akaihola) for spotting this.

Close #733
2014-05-07 20:38:15 -07:00
benoitc
81241907ff switch QUIT and TERM signal
With this change, when gunicorn receives a QUIT all the workers are
killed immediately and exit and TERM is used for the graceful shutdown.

Note: the old behaviour was based on the NGINX but the new one is more
correct according the following doc:

https://www.gnu.org/software/libc/manual/html_node/Termination-Signals.html

also it is complying with the way the signals are sent by heroku:

https://devcenter.heroku.com/articles/python-faq#what-constraints-exist-when-developing-applications-on-heroku
2014-03-08 17:14:06 -08:00
Randall Leeds
24a060ed02 Reap workers in SIGCHLD handler
This commit tries to minimize the chance of sending a kill signal
to a process that is not a gunicorn worker by reaping children
as soon as the SIGCHLD is received.

Close #371
2014-03-08 15:21:54 -08:00
W. Trevor King
64f98a0a1c arbiter: Consolidate configuration logging
Benoit prefers the log prefix for the first line ("Current
configuration:") but not subsequent lines (" {config}: {value}") [1],
so consolidate to a single log.debug call.  The newer '{0}'.format()
syntax requires Python 2.6 [2], but our setup.py only claims
compatibility with 2.6, 2.7, 3.2, and 3.3, so that should be fine.

[1]: https://github.com/benoitc/gunicorn/pull/701/files#r9767234
[2]: http://docs.python.org/2/whatsnew/2.6.html#pep-3101-advanced-string-formatting
2014-02-14 15:15:35 -08:00
W. Trevor King
2277901a72 Deprecate the --debug setting
"Limits the number of worker processes to 1" hasn't been true since
06a4dc6 (fix one error in gunicorn_paster, global conf was ignored,
2010-06-22), although it was true when the line was added in 3c7d532
(Large refactor of the documentation and website, 2010-05-22).

"changes some error handling that's sent to clients" hasn't been true
since feb86d3 (don't display the traceback in the HTTP response,
2013-09-27).

The only remaining actions that --debug had were disabling --preload
and hiding debug-level config logging.  The former seems useless (just
disable --preload directly) and the latter at doesn't seem useful
enough for a new setting (just turn down --log-level).  With this
commit, --preload always works and you always get debug-level config
logging.

I left a stub Debug entry in gunicorn.config, which we can leave in
place while folks convert any gunicorn scripts and configurations to
drop --debug.  When the time comes, we can just remove that entry.  I
also the boolean-config tests to use --preload, since that will still
be around after we remove the dummy Debug entry.

Fixes #700.
2014-02-13 12:40:41 -08:00
Adrien CLERC
d76bab4d71 Use a dynamic timeout to wait for the optimal time. 2014-01-30 15:32:02 -08:00
Qiangning Hong
5c4b77cd02 Run worker's setup early than set num_workers
`cfg.worker_class` is a property, which calls the classmethod `setup` of
the worker class when accessed.  Gevent worker relies on this mechanism
to call `gevent.monkey.patch_all()`.

However, `num_workers` is a hooked property, when it is set, gunicorn
will call hook defined by user.  If the hooked code relies on
gevent's monkey patch, it will fail because the monkey patch has not
been applied yet.

This commit makes sure that `worker_class` property getter invokes
before `num_workers` setter to resolve this problem.
2013-11-29 14:00:36 +08:00
benoitc
02b866f08a don't spam the console
SIGWINCH could happen often in the console when the terminal is resized.
Since the error is harmless just display it when the logging level is
debug.

fix #449
2013-11-06 08:02:12 +01:00
benoitc
82256a93a5 add --chdir option
chdir to specified directory before apps loading.

Ex:

	$ gunicorn --chdir ./examples test:app

fix #384
2013-08-27 16:52:49 +02:00
benoitc
4e3428af0e add -e/--env command line argunment
This command line argunment allows someone to pass an environement variable to
gunicorn:

	$ gunicorn --env FOO=1 test:app

With the command line above the application will be able to use the FOO
environment vatriable.
2013-08-27 13:21:53 +02:00
Stephane Wirtel
7ed7ca998d Close all the listener sockets 2013-08-27 11:24:32 +02:00
benoitc
532d1fffaf document the use of PYTHONUNBUFFERED in config 2013-04-23 16:23:46 +02:00
benoitc
29aefcc1cf only close 0-2 fds when -R isn't specified
Following some discussion on IRC with @GrahamDumpleton this patch only
close stdios if -R isn't specified. It also let others fds open and
don't try to close them.

This should fix logging around and behave like other daemons. It should
also close #309.
2013-04-23 16:23:46 +02:00
benoitc
208df4ddd9 let the VM close the sockets on exit
Closing sockets when stopping the arbiter was also closing unix sockets
if any because they aren't attached to a specific process. So remove it
and let the vm close them if needed. This change fix the reload of the
binary.

fix #476
2013-04-23 08:38:03 +02:00
benoitc
612f4125dd make sure we exit immediately if we fail to load the application.
While I'm here describe a more accurate error when it happens.

fix #508
2013-04-22 18:43:20 +02:00
benoitc
3ade8e8d78 make harder for workers to listen at the same time
fix #514
2013-04-22 18:10:18 +02:00
benoitc
765839b2ad we only care of it if gunicorn was started as a daemon
fix #466
2013-04-21 07:00:03 +02:00
Chris Streeter
e908ec3359 Consistently get CWD across apps and arbiter.
The Arbiter is smart about getting the CWD; first it checks the CWD
environment (which doesn't resolve symlinks), then it falls back to the
python os.getcwd() (which does resolve symlinks). However, the Arbiter
is the only place that does this, which will then do the right thing
when we reexec. However, when reloading the Arbiter, it won't pick up
changes if the symlink has changed.

By changing the *app.py entry points to also use the same method for
determining the CWD, we'll insert a symlink path into the first location
in sys.path. Then our reloaded app will correctly pull in any new
changes.
2013-04-03 11:15:53 +02:00
Chris Streeter
5b7696f032 Fix a typo. 2013-02-19 18:28:54 -08:00
Adnane Belmadiaf
20cd49595a PEP8 fixes 2012-12-24 09:53:03 +01:00
Adnane Belmadiaf
1c9b8460b1 s/create_sockeSt/create_sockets 2012-12-22 08:58:46 +01:00
Qiangning Hong
174c34ec9c add nworkers_changed hook
This hook will be called whenever the number of workers is set.
2012-12-21 15:43:26 +01:00
benoitc
b7b51adf13 allows gunicorn to bind to multiple address
Allows gunicorn to listen on different interface. It can be either ipv6,
unix or ipv4 sockets.

Ex:

    gunicorn -w3 -b 127.0.0.1:8001 -b 127.0.0.1:8000 -b [::1]:8000 test:app

fix #444
2012-12-14 10:18:39 +01:00
sib
771aae85e0 fixed: PWD comparison in arbiter using incorrect attribute names 2012-11-22 23:29:25 -05:00
benoitc
46e041b9f1 don't use map 2012-11-16 11:08:02 +01:00
Andrew Gorcester
f7b9a08c9c resolve py3 bytes issue for django apps 2012-10-28 06:33:07 +01:00
benoitc
8d453fb341 all tests pass under python 3 2012-10-24 22:07:35 +02:00
benoitc
53ce50bc7b obvious syntax fixes preparing python3 support 2012-10-24 12:11:15 +02:00
Xie Shi
274e43489b Workers won't be killed if timeout set to 0 2012-09-27 19:14:41 +02:00
Djoume Salvetti
97b43bd20a Create a pidfile before executing on_starting().
This will let a standard init script (or any script that look for a
pidfile) know that gunicorn is already running and won't attempt to run
it twice.
This would also enable the script to stop gunicorn even in it's startup
phase.
2012-08-03 21:27:36 +02:00
benoitc
3cd1a9acd9 log it as an exception 2012-08-03 06:04:08 +02:00
benoitc
67bd75f7b3 don't try to reopen files on initial startup. fix #358 2012-06-24 17:25:43 +02:00
benoitc
a68618c824 breaking change: take the control on graceful reload back
We really shouldn't allow the people to override the way we spawn the
new workers on reload. Graceful is about launching new worker and kill
olders after the graceful time.
2012-06-18 11:02:30 +02:00
benoitc
cd3f9f076e logs are already reopened in self.setup 2012-06-04 11:55:29 +02:00
benoitc
188fa3e109 add the graceful timeout option. close #352
This change add gtraceful timeout option. This timeout is different than
the worker timeout and can be extended to handled a longer delay before
closing a running connection.

Patch based on the one given by @sirkonst with some edit + support of
the eventlet worker.
2012-06-01 09:07:43 +02:00
Benoit Chesneau
1c27d369b4 display traceback when the work fails to boot (close #338) 2012-04-26 17:40:09 +02:00
benoitc
ff1dfa1780 reopen log files after initialization . close #309
make sure we reopen logfiles after initialization so we are sure we can
use it.
2012-03-24 09:46:05 +01:00
Chris Forbes
feb200d807 Fix typo in docstring for kill_workers 2012-03-20 15:53:32 +13:00
benoitc
f168a21dae fix whitespaces 2012-02-19 11:27:46 +01:00
Sergey Rublev
8bf793d2e5 Fix missed argument during refactoring 2012-02-01 11:59:53 -05:00
Evan Mezeske
d53112bbb2 iremove reap_workers from signaling . 2011-11-10 05:53:02 +01:00
Evan Mezeske
3c1f1cb126 Don't call logging functions in the signal handler.
The standard logger uses locking functions which are NOT guaranteed to
be re-entrant [1], so this could (potentially) result in deadlock or a
crash.

[1] http://docs.python.org/library/logging.html Section 15.7.8.
2011-10-25 21:54:26 +02:00
Randall Leeds
58c3c5680d typo 2011-10-05 14:11:55 -07:00
Randall Leeds
4b53236034 fix #245 - try to prevent leaking fds on reexec 2011-09-19 13:42:07 -07:00
benoitc
824801d017 make the Logger pluggable. Allows people to use their own logger by
giving to gunicorn an entry point or a module path.
2011-09-09 00:43:00 +02:00
Phil Schanely
d6560726c5 New on_reload server hook to customize how SIGHUPs spawn new workers. 2011-08-22 09:45:06 +02:00