Browse Source

Print out WSGI environment on DB init failure

tags/nilmdb-1.4.5
Jim Paris 11 years ago
parent
commit
95ca55aa7e
1 changed files with 7 additions and 2 deletions
  1. +7
    -2
      nilmdb/server/server.py

+ 7
- 2
nilmdb/server/server.py View File

@@ -11,6 +11,7 @@ from nilmdb.utils.time import string_to_timestamp
import cherrypy
import sys
import os
import socket
import simplejson as json
import decorator
import psutil
@@ -629,17 +630,21 @@ def wsgi_application(dbpath, basepath): # pragma: no cover
basepath = basepath.rstrip('/'))
except Exception:
# Build an error message on failure
import pprint
err = sprintf("Initializing database at path '%s' failed:\n\n",
dbpath)
err += traceback.format_exc()
try:
import pwd
import grp
err += sprintf("\nRunning as: uid=%d (%s), gid=%d (%s)\n",
err += sprintf("\nRunning as: uid=%d (%s), gid=%d (%s) "
"on host %s, pid %d\n",
os.getuid(), pwd.getpwuid(os.getuid())[0],
os.getgid(), grp.getgrgid(os.getgid())[0])
os.getgid(), grp.getgrgid(os.getgid())[0],
socket.gethostname(), os.getpid())
except ImportError:
pass
err += sprintf("\nEnvironment:\n%s\n", pprint.pformat(environ))
if server[0] is None:
# Serve up the error with our own mini WSGI app.
headers = [ ('Content-type', 'text/plain'),


Loading…
Cancel
Save