gunicorn.conf.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. # Sample Gunicorn configuration file.
  2. #
  3. # Server socket
  4. #
  5. # bind - The socket to bind.
  6. #
  7. # A string of the form: 'HOST', 'HOST:PORT', 'unix:PATH'.
  8. # An IP is a valid HOST.
  9. #
  10. # backlog - The number of pending connections. This refers
  11. # to the number of clients that can be waiting to be
  12. # served. Exceeding this number results in the client
  13. # getting an error when attempting to connect. It should
  14. # only affect servers under significant load.
  15. #
  16. # Must be a positive integer. Generally set in the 64-2048
  17. # range.
  18. #
  19. bind = '0.0.0.0:80'
  20. backlog = 2048
  21. #
  22. # Worker processes
  23. #
  24. # workers - The number of worker processes that this server
  25. # should keep alive for handling requests.
  26. #
  27. # A positive integer generally in the 2-4 x $(NUM_CORES)
  28. # range. You'll want to vary this a bit to find the best
  29. # for your particular application's work load.
  30. #
  31. # worker_class - The type of workers to use. The default
  32. # sync class should handle most 'normal' types of work
  33. # loads. You'll want to read
  34. # http://docs.gunicorn.org/en/latest/design.html#choosing-a-worker-type
  35. # for information on when you might want to choose one
  36. # of the other worker classes.
  37. #
  38. # A string referring to a Python path to a subclass of
  39. # gunicorn.workers.base.Worker. The default provided values
  40. # can be seen at
  41. # http://docs.gunicorn.org/en/latest/settings.html#worker-class
  42. #
  43. # worker_connections - For the eventlet and gevent worker classes
  44. # this limits the maximum number of simultaneous clients that
  45. # a single process can handle.
  46. #
  47. # A positive integer generally set to around 1000.
  48. #
  49. # timeout - If a worker does not notify the master process in this
  50. # number of seconds it is killed and a new worker is spawned
  51. # to replace it.
  52. #
  53. # Generally set to thirty seconds. Only set this noticeably
  54. # higher if you're sure of the repercussions for sync workers.
  55. # For the non sync workers it just means that the worker
  56. # process is still communicating and is not tied to the length
  57. # of time required to handle a single request.
  58. #
  59. # keepalive - The number of seconds to wait for the next request
  60. # on a Keep-Alive HTTP connection.
  61. #
  62. # A positive integer. Generally set in the 1-5 seconds range.
  63. #
  64. workers = 2
  65. worker_class = 'sync'
  66. worker_connections = 1000
  67. timeout = 15
  68. keepalive = 2
  69. #
  70. # spew - Install a trace function that spews every line of Python
  71. # that is executed when running the server. This is the
  72. # nuclear option.
  73. #
  74. # True or False
  75. #
  76. spew = False
  77. #
  78. # Server mechanics
  79. #
  80. # daemon - Detach the main Gunicorn process from the controlling
  81. # terminal with a standard fork/fork sequence.
  82. #
  83. # True or False
  84. #
  85. # raw_env - Pass environment variables to the execution environment.
  86. #
  87. # pidfile - The path to a pid file to write
  88. #
  89. # A path string or None to not write a pid file.
  90. #
  91. # user - Switch worker processes to run as this user.
  92. #
  93. # A valid user id (as an integer) or the name of a user that
  94. # can be retrieved with a call to pwd.getpwnam(value) or None
  95. # to not change the worker process user.
  96. #
  97. # group - Switch worker process to run as this group.
  98. #
  99. # A valid group id (as an integer) or the name of a user that
  100. # can be retrieved with a call to pwd.getgrnam(value) or None
  101. # to change the worker processes group.
  102. #
  103. # umask - A mask for file permissions written by Gunicorn. Note that
  104. # this affects unix socket permissions.
  105. #
  106. # A valid value for the os.umask(mode) call or a string
  107. # compatible with int(value, 0) (0 means Python guesses
  108. # the base, so values like "0", "0xFF", "0022" are valid
  109. # for decimal, hex, and octal representations)
  110. #
  111. # tmp_upload_dir - A directory to store temporary request data when
  112. # requests are read. This will most likely be disappearing soon.
  113. #
  114. # A path to a directory where the process owner can write. Or
  115. # None to signal that Python should choose one on its own.
  116. #
  117. daemon = False
  118. raw_env = []
  119. pidfile = None
  120. umask = 0
  121. user = None
  122. group = None
  123. tmp_upload_dir = None
  124. #
  125. # Logging
  126. #
  127. # logfile - The path to a log file to write to.
  128. #
  129. # A path string. "-" means log to stdout.
  130. #
  131. # loglevel - The granularity of log output
  132. #
  133. # A string of "debug", "info", "warning", "error", "critical"
  134. #
  135. errorlog = '-'
  136. loglevel = 'info'
  137. accesslog = '-'
  138. access_log_format = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"'
  139. #
  140. # Process naming
  141. #
  142. # proc_name - A base to use with setproctitle to change the way
  143. # that Gunicorn processes are reported in the system process
  144. # table. This affects things like 'ps' and 'top'. If you're
  145. # going to be running more than one instance of Gunicorn you'll
  146. # probably want to set a name to tell them apart. This requires
  147. # that you install the setproctitle module.
  148. #
  149. # A string or None to choose a default of something like 'gunicorn'.
  150. #
  151. proc_name = None
  152. #
  153. # Server hooks
  154. #
  155. # post_fork - Called just after a worker has been forked.
  156. #
  157. # A callable that takes a server and worker instance
  158. # as arguments.
  159. #
  160. # pre_fork - Called just prior to forking the worker subprocess.
  161. #
  162. # A callable that accepts the same arguments as after_fork
  163. #
  164. # pre_exec - Called just prior to forking off a secondary
  165. # master process during things like config reloading.
  166. #
  167. # A callable that takes a server instance as the sole argument.
  168. #
  169. def post_fork(server, worker):
  170. server.log.info("Worker spawned (pid: %s)", worker.pid)
  171. def pre_fork(server, worker):
  172. pass
  173. def pre_exec(server):
  174. server.log.info("Forked child, re-executing.")
  175. def when_ready(server):
  176. server.log.info("Server is ready. Spawning workers")
  177. def worker_int(worker):
  178. worker.log.info("worker received INT or QUIT signal")
  179. ## get traceback info
  180. import threading, sys, traceback
  181. id2name = {th.ident: th.name for th in threading.enumerate()}
  182. code = []
  183. for threadId, stack in sys._current_frames().items():
  184. code.append("\n# Thread: %s(%d)" % (id2name.get(threadId, ""),
  185. threadId))
  186. for filename, lineno, name, line in traceback.extract_stack(stack):
  187. code.append('File: "%s", line %d, in %s' % (filename,
  188. lineno, name))
  189. if line:
  190. code.append(" %s" % (line.strip()))
  191. worker.log.debug("\n".join(code))
  192. def worker_abort(worker):
  193. worker.log.info("worker received SIGABRT signal")