Commit a5bcdcfd authored by Amos Latteier's avatar Amos Latteier

Added a -r switch for read-only operation. In read-only mode ZServer won't...

Added a -r switch for read-only operation. In read-only mode ZServer won't write any pid or log files. The mode is only really good for running in weird environments, like off a CD.
parent 93c273a0
...@@ -185,6 +185,14 @@ Options: ...@@ -185,6 +185,14 @@ Options:
log file will be written to the 'var' directory. The default is log file will be written to the 'var' directory. The default is
%(LOG_FILE)s. %(LOG_FILE)s.
-r
Run ZServer is read-only mode. ZServer won't write anything to disk.
No log files, no pid files, nothing. This means that you can't do a
lot of stuff like use PCGI, and zdaemon. ZServer will log hits to
STDOUT and zLOG will log to STDERR.
Environment settings are of the form: NAME=VALUE. Environment settings are of the form: NAME=VALUE.
Note: you *must* use Python 1.5.2 or later! Note: you *must* use Python 1.5.2 or later!
...@@ -261,8 +269,9 @@ try: ...@@ -261,8 +269,9 @@ try:
if string.split(sys.version)[0] < '1.5.2': if string.split(sys.version)[0] < '1.5.2':
raise 'Invalid python version', string.split(sys.version)[0] raise 'Invalid python version', string.split(sys.version)[0]
opts, args = getopt.getopt(sys.argv[1:], 'hz:Z:t:a:d:u:w:f:p:m:Sl:2DP:') opts, args = getopt.getopt(sys.argv[1:], 'hz:Z:t:a:d:u:w:f:p:m:Sl:2DP:r')
DEBUG=0 DEBUG=0
READ_ONLY=0
# Get environment variables # Get environment variables
for a in args: for a in args:
...@@ -279,6 +288,7 @@ try: ...@@ -279,6 +288,7 @@ try:
for o, v in opts: for o, v in opts:
if o=='-z': here=v if o=='-z': here=v
elif o=='-Z': Zpid=v elif o=='-Z': Zpid=v
elif o=='-r': READ_ONLY=1
elif o=='-t': elif o=='-t':
try: v=string.atoi(v) try: v=string.atoi(v)
except: raise 'Invalid number of threads', v except: raise 'Invalid number of threads', v
...@@ -355,7 +365,7 @@ sys.path=[os.path.join(here,'lib','python'),here ...@@ -355,7 +365,7 @@ sys.path=[os.path.join(here,'lib','python'),here
# official one. # official one.
import ZServer import ZServer
if Zpid: if Zpid and not READ_ONLY:
import zdaemon, App.FindHomes, posix import zdaemon, App.FindHomes, posix
sys.ZMANAGED=1 sys.ZMANAGED=1
...@@ -367,7 +377,10 @@ exec "import "+MODULE in {} ...@@ -367,7 +377,10 @@ exec "import "+MODULE in {}
import zLOG import zLOG
from Zope import ZLogger from Zope import ZLogger
zLOG.log_write = ZLogger.ZLogger.log_write if READ_ONLY:
zLOG._stupid_dest=sys.stderr
else:
zLOG.log_write = ZLogger.ZLogger.log_write
# Location of the ZServer log file. This file logs all ZServer activity. # Location of the ZServer log file. This file logs all ZServer activity.
...@@ -402,7 +415,11 @@ if DNS_IP: ...@@ -402,7 +415,11 @@ if DNS_IP:
rs = resolver.caching_resolver(DNS_IP) rs = resolver.caching_resolver(DNS_IP)
else: else:
rs=None rs=None
lg = logger.file_logger(LOG_PATH)
if READ_ONLY:
lg = logger.file_logger('-') # log to stdout
else:
lg = logger.file_logger(LOG_PATH)
# HTTP Server # HTTP Server
if HTTP_PORT: if HTTP_PORT:
...@@ -435,7 +452,7 @@ if FTP_PORT: ...@@ -435,7 +452,7 @@ if FTP_PORT:
logger_object=lg) logger_object=lg)
# PCGI Server # PCGI Server
if PCGI_FILE: if PCGI_FILE and not READ_ONLY:
PCGI_FILE=os.path.join(here, PCGI_FILE) PCGI_FILE=os.path.join(here, PCGI_FILE)
if os.path.exists(PCGI_FILE): if os.path.exists(PCGI_FILE):
zpcgi = PCGIServer( zpcgi = PCGIServer(
...@@ -473,12 +490,13 @@ except: ...@@ -473,12 +490,13 @@ except:
# if it hasn't failed at this point, create a .pid file. # if it hasn't failed at this point, create a .pid file.
pf = open(PID_FILE, 'w') if not READ_ONLY:
pid=str(os.getpid()) pf = open(PID_FILE, 'w')
try: pid=str(os.getppid())+' '+pid pid=str(os.getpid())
except: pass try: pid=str(os.getppid())+' '+pid
pf.write(pid) except: pass
pf.close() pf.write(pid)
pf.close()
# Start Medusa, Ye Hass! # Start Medusa, Ye Hass!
sys.ZServerExitCode=0 sys.ZServerExitCode=0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment