225 Commits

Author SHA1 Message Date
Berker Peksag
51f49f4887 Remove unused import and pass True instead of 1
The logging module checks exc_info as

    if exc_info:
        # ...

so passing True would be more readable.
2016-02-12 09:20:55 +02:00
bloodearnest
0acfb55d5f Let logging module handle traceback printing
Manually including the traceback in the log msg causes some issues when
interacting with log formats, and in one case was causing the traceback
to be printed twice.
2016-02-09 14:05:18 +00:00
Semyon Maryasin
46da49fd5a Fixed log message for listener reloading
Fixes #1181
2016-01-09 15:01:27 +03:00
Randall Leeds
2ac41c406b Merge pull request #1095 from danc86/handle-HaltServer-in-manage_workers
handle HaltServer in manage_workers
2015-12-26 14:35:55 -08:00
benoitc
2221225969 makes sure that file handles are correctly reopened on HUP
This change makes sure we don't recreate the Logger class here so we
don't reinitialise the log handlers.

fix #627
2015-09-23 14:00:35 -07:00
Dan Callaghan
d6429233d9 handle HaltServer in manage_workers 2015-08-11 17:10:12 +10:00
Robert Estelle
e028710872 Make last logged worker count an explicit instance var. 2015-07-23 18:14:02 -04:00
Robert Estelle
6f6ec92c4e Store last logged worker count.
This is easier and safer than only logging when we detect that
self.WORKERS has changed or that `spawn_worker` or `kill_worker` has
been done.
2015-07-19 16:09:27 -04:00
Robert Estelle
09357ed3c4 Only log '[num] workers' message when it changes.
Otherwise when debug logging is on, the message prints every second even
with no system activity.
2015-07-19 15:56:58 -04:00
Gaurav Jain
eed65c63f1 PEP8 fixes 2015-06-22 03:10:52 -07:00
Gaurav Jain
09007c7f0a Catch OSError as well as ValueError on race condition
The fix for issue #863 was incomplete as both OSError or ValueError could be
raised by os.fstat(). Thus we need to catch both types of exceptions
2015-06-22 03:10:30 -07:00
Benoit Chesneau
eb485d2134 make worker check_config method optionnal 2015-03-06 10:10:42 +01:00
Benoit Chesneau
e5f6b8024d add check_config instance method to workers
Add a method to check if config requirements are OK for a specific worker by
adding the `check_config` instance method. This method takes 2 arguments: the
config instance followed by the logger instance to log.

This method is right now used in the thread worker to display a warning in
the case it can't handle keep alive connections. This change is related to #979.
2015-03-06 10:01:31 +01:00
benoitc
41f14bf46e remove dynamic timeout temporarely
this change is removing the dynamic timeout to make it sure it doesn't have
any side effect in the worker monitored like reported in #942
2014-12-19 09:00:35 +01:00
benoitc
d1a0973225 send SIGQUIT/SIGTERM only once to the workers
there is no need to send more than once the signal to the workers when
exiting. With this patch we are sending once the QUIT/TERM signal and  then
wait until the graceful timeout or until there are workers alive.

fix #655
2014-12-19 08:03:22 +01:00
Collin Anderson
bfae0c91de sys.stderr.write -> print(msg, file=sys.stderr) 2014-09-16 15:38:56 -04:00
Collin Anderson
0d3045bb41 cleaned some code 2014-09-10 20:34:22 -04:00
Randall Leeds
0e31ed3dde Merge pull request #865 from benoitc/fix/863
fix race condition error
2014-09-08 23:25:26 -07:00
benoitc
34eb1b63f9 only get last update of the worker once when checking oldest
spotted by @tilgovi, a race condition is possible when making 2
consecutive calls to the last_update function, so only get it once.
2014-09-09 07:23:56 +02:00
root
f7151821c6 arbiter: reopen log files first then signal workers
Workers may run under different uid/gid and don't have permission
to create log files. After master opens log files and makes them
rw-able when default umask is used, workers will be able to open
them upon receiving USR1.
2014-09-04 15:47:14 -07:00
benoitc
4fe426cd66 fix race condition error
When the worker exited the tempfile is not available anymore so we can't
get the last update and calculate the dynamic timeout introduced in
d76bab4d716fed3f965fbde4ba1a1bba975f03d1 .

This changes fix it by catching the IO error.

fix #863
2014-08-30 09:41:08 +02:00
Alexis Le-Quoc
7db45868e0 Typo 2014-08-04 15:36:14 -04:00
Alexis Lê-Quôc
6cb67e49ca Restore number of workers in DEBUG log 2014-08-04 15:30:12 -04:00
Alexis Le-Quoc
bc2e132bce Rework logging to allow for empty log message while pushing metrics 2014-08-03 17:15:13 -04:00
Alexis Le-Quoc
c3421a833d Merge branch 'master' of https://github.com/benoitc/gunicorn into statsd-logger 2014-06-18 11:23:36 -04:00
Andrew Burdo
ed2d2a8ab3 Change the rest of QUIT and TERM signals.
This will restore graceful shutdown of workers by master.
Also worker_int callback is moved from handle_exit (INT and TERM before switching) to handle_quit(INT and QUIT).
2014-06-13 14:32:11 +03:00
Randall Leeds
ae14150cad Merge pull request #727 from benoitc/feature/threaded-worker
Feature/threaded worker
2014-06-01 14:16:44 -07:00
benoitc
d9b7e32d34 try to log what happened in the worker after a timeout.
fix #518
2014-06-01 11:22:19 +02:00
Ben Oswald
9ade14ae78 add on_exit hook 2014-06-01 09:53:36 +02:00
Alexis Le-Quoc
4bf1e1d468 Fix silent exception in response code capture 2014-05-31 00:48:27 -04:00
Alexis Le-Quoc
89a3c96700 Incorporate feedback from PR
Use extra keyword in logger, more pythonic
capture response code as a rate metric
2014-05-31 00:10:51 -04:00
Alexis Le-Quoc
de9b05c774 Merge branch 'master' of https://github.com/benoitc/gunicorn into statsd-logger 2014-05-30 23:10:35 -04:00
benoitc
7f9d745eb5 reuse asyncio code in the threaded worker 2014-05-30 11:07:35 +02:00
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
07a7e5b9e5 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-14 19:52:48 +02: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
Alexis Le-Quoc
8a3a3fcfa3 Merge branch 'master' of https://github.com/benoitc/gunicorn into statsd-logger 2014-05-12 17:51:02 +02: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
Alexis Le-Quoc
0b5cc1e293 First cut of logger-based statsd 2014-05-05 15:50:13 -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