Setting permissions on log files to 600 for privacy reasons. Also naming log files to include username on Linux.
This commit is contained in:
parent
9e1ae2abb6
commit
c0d512920e
|
@ -4,6 +4,10 @@ import cherrypy
|
||||||
from tempfile import gettempdir
|
from tempfile import gettempdir
|
||||||
|
|
||||||
|
|
||||||
|
username_postfix = os.environ.get( "USER" )
|
||||||
|
username_postfix = username_postfix and "_%s" % username_postfix or ""
|
||||||
|
|
||||||
|
|
||||||
settings = {
|
settings = {
|
||||||
"global": {
|
"global": {
|
||||||
"server.thread_pool": 4,
|
"server.thread_pool": 4,
|
||||||
|
@ -11,8 +15,8 @@ settings = {
|
||||||
"session_filter.timeout": 60 * 24 * 365, # one year
|
"session_filter.timeout": 60 * 24 * 365, # one year
|
||||||
"static_filter.root": os.getcwd(),
|
"static_filter.root": os.getcwd(),
|
||||||
"server.log_to_screen": False,
|
"server.log_to_screen": False,
|
||||||
"server.log_file": os.path.join( gettempdir(), "luminotes_error.log" ),
|
"server.log_file": os.path.join( gettempdir(), "luminotes_error%s.log" % username_postfix ),
|
||||||
"server.log_access_file": os.path.join( gettempdir(), "luminotes.log" ),
|
"server.log_access_file": os.path.join( gettempdir(), "luminotes%s.log" % username_postfix ),
|
||||||
"server.log_tracebacks": True,
|
"server.log_tracebacks": True,
|
||||||
"luminotes.launch_browser": True,
|
"luminotes.launch_browser": True,
|
||||||
"luminotes.db_host": None, # use local SQLite database
|
"luminotes.db_host": None, # use local SQLite database
|
||||||
|
|
33
luminotes.py
33
luminotes.py
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import stat
|
||||||
import socket
|
import socket
|
||||||
import os.path
|
import os.path
|
||||||
import urllib2 as urllib
|
import urllib2 as urllib
|
||||||
|
@ -77,11 +78,16 @@ def main( args ):
|
||||||
|
|
||||||
# remove the existing log files, if any
|
# remove the existing log files, if any
|
||||||
try:
|
try:
|
||||||
os.remove( cherrypy.config.configMap[ u"global" ].get( u"server.log_access_file" ) )
|
log_access_file = cherrypy.config.configMap[ u"global" ].get( u"server.log_access_file" )
|
||||||
|
if log_access_file:
|
||||||
|
os.remove( log_access_file )
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.remove( cherrypy.config.configMap[ u"global" ].get( u"server.log_file" ) )
|
log_file = cherrypy.config.configMap[ u"global" ].get( u"server.log_file" )
|
||||||
|
if log_file:
|
||||||
|
os.remove( log_file )
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -96,10 +102,25 @@ def main( args ):
|
||||||
root = Root( database, cherrypy.config.configMap )
|
root = Root( database, cherrypy.config.configMap )
|
||||||
cherrypy.root = root
|
cherrypy.root = root
|
||||||
|
|
||||||
if launch_browser is True:
|
cherrypy.server.start_with_callback( callback, ( log_access_file, log_file, server_url, launch_browser ) )
|
||||||
cherrypy.server.start_with_callback( webbrowser.open_new, ( server_url, ) )
|
|
||||||
else:
|
|
||||||
cherrypy.server.start()
|
def callback( log_access_file, log_file, server_url, launch_browser = False ):
|
||||||
|
# this causes cherrypy to create the access log
|
||||||
|
if log_access_file:
|
||||||
|
try:
|
||||||
|
urllib.urlopen( "%sping" % server_url )
|
||||||
|
except urllib.URLError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# give the cherrypy log files appropriate permissions
|
||||||
|
if log_access_file and os.path.exists( log_access_file ):
|
||||||
|
os.chmod( log_access_file, stat.S_IRUSR | stat.S_IWUSR )
|
||||||
|
if log_file and os.path.exists( log_file ):
|
||||||
|
os.chmod( log_file, stat.S_IRUSR | stat.S_IWUSR )
|
||||||
|
|
||||||
|
if launch_browser:
|
||||||
|
webbrowser.open_new( server_url )
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Reference in New Issue