Commit 86db1df3 authored by Chris McDonough's avatar Chris McDonough

New zopectl feature: adduser. Instead of using the inituser mechanism,

"zopectl adduser <name> <password>" will add a user with the 'Manager' role
to your site.  This is useful both interactively and for packagers.

Bugfix: if zopectl is run as the root user, the debug, run, and adduser
commands will cause the Python process which performs those actions
to switch users to the effective user.  This prevents ZODB index files,
log files, etc. from being written as root, potentially preventing
later startup by the effective user.

Bugfix: allow the zopectl process to ascertain the program that zdrun should
run from the Zope config file.  This is necessary if the file is moved
out of a "single-directory-as-instance" instance home.
parent ecb1cee2
......@@ -45,6 +45,9 @@ from zdaemon.zdoptions import ZDOptions
from zLOG.datatypes import FileHandlerFactory
def string_list(arg):
return arg.split()
class ZopeCtlOptions(ZDOptions):
"""Zope controller options.
......@@ -65,6 +68,8 @@ class ZopeCtlOptions(ZDOptions):
def __init__(self):
ZDOptions.__init__(self)
self.add("program", "runner.program", "p:", "program=",
handler=string_list)
self.add("backofflimit", "runner.backoff_limit",
"b:", "backoff-limit=", int, default=10)
self.add("daemon", "runner.daemon", "d", "daemon", flag=1, default=1)
......@@ -82,6 +87,9 @@ class ZopeCtlOptions(ZDOptions):
config = self.configroot
self.directory = config.instancehome
self.clienthome = config.clienthome
if config.runner and config.runner.program:
self.program = config.runner.program
else:
self.program = [os.path.join(self.directory, "bin", "runzope")]
self.sockname = os.path.join(self.clienthome, "zopectlsock")
self.user = None
......@@ -133,12 +141,14 @@ class ZopeCmd(ZDCmd):
'opts.configfile=\'%s\'; '
'opts.realize(); '
'h.handleConfig(opts.configroot,opts.confighandlers);'
'config.setConfiguration(opts.configroot); ' %
'config.setConfiguration(opts.configroot); '
'from Zope.Startup import do_posix_stuff; '
'do_posix_stuff(opts.configroot); '%
(python, self.options.configfile)
)
return cmdline + more + '\"'
def do_debug( self, arg ):
def do_debug(self, arg):
cmdline = self.get_startup_cmd(self.options.python + ' -i',
'import Zope; app=Zope.app()')
print ('Starting debugger (the name "app" is bound to the top-level '
......@@ -149,7 +159,8 @@ class ZopeCmd(ZDCmd):
print "debug -- run the Zope debugger to inspect your database"
print " manually using a Python interactive shell"
def do_run( self, arg ):
def do_run(self, arg):
self.setuid()
cmdline = self.get_startup_cmd(self.options.python,
'import Zope; app=Zope.app(); execfile(\'%s\')' % arg)
os.system(cmdline)
......@@ -159,6 +170,23 @@ class ZopeCmd(ZDCmd):
print " set up. The script can use the name 'app' to"
print " access the top-level Zope object"
def do_adduser(self, arg):
try:
name, password = arg.split()
except:
print "usage: adduser <name> <password>"
return
cmdline = self.get_startup_cmd(
self.options.python ,
'import Zope; app=Zope.app();'
'app.acl_users._doAddUser(\'%s\', \'%s\', [\'Manager\'], []);'
'get_transaction().commit()'
) % (name, password)
os.system(cmdline)
def help_adduser(self):
print "adduser <name> <password> -- add a Zope management user"
def main(args=None):
# This is exactly like zdctl.main(), but uses ZopeCtlOptions and
......
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