Advertisement
SamJustice

Untitled

Oct 17th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | None | 0 0
  1. from __future__ import print_function
  2. import os, sys, traceback
  3. import logging.config
  4.  
  5. APP_CONFIG = "/home/.../production.ini"
  6.  
  7. logging.config.fileConfig(APP_CONFIG)
  8.  
  9.  
  10. def _get_log():
  11.     return open("/home/.../passenger_wsgi.log", 'a')
  12.  
  13.  
  14. log = _get_log()
  15. print("running %s" % sys.executable, file=log)
  16.  
  17. INTERP = "/home/.../bin/python"
  18.  
  19. if sys.executable != INTERP:
  20.     print("Detected wrong interpreter location , swapping to %s" % INTERP, file=log)
  21.     log.flush()
  22.     log.close()
  23.     os.execl(INTERP, INTERP, *sys.argv)
  24.  
  25. from paste.deploy import loadapp
  26. from paste.exceptions.errormiddleware import ErrorMiddleware
  27. log.flush()
  28. log.close()
  29.  
  30.  
  31. def application(environ, start_response):
  32.     log = _get_log()
  33.     print("Application called:", file=log)
  34.     print("environ: %s" % str(environ), file=log)
  35.     results = []
  36.     try:
  37.         app = loadapp("config:/home/.../production.ini")
  38.         print("App loaded, attempting to run", file=log)
  39.         log.flush()
  40.         results = app(environ, start_response)
  41.         print("App executed successfully", file=log)
  42.     except Exception:  # ignoring the broad exception as this is intended to catch and log any uncaught errors
  43.         traceback.print_exc(file=log)
  44.         log.flush()
  45.     finally:
  46.         log.close()
  47.     print("Returning results.")
  48.     return results
  49.  
  50.  
  51. application = ErrorMiddleware(application, debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement