r445 - in zope-common/trunk: . debian

Fabio Tranchitella kobold at alioth.debian.org
Thu Nov 2 23:12:21 CET 2006


Author: kobold
Date: 2006-11-02 23:12:21 +0100 (Thu, 02 Nov 2006)
New Revision: 445

Modified:
   zope-common/trunk/debian/README.Debian
   zope-common/trunk/debian/changelog
   zope-common/trunk/dzhandle
Log:
Implemented non-root usage.


Modified: zope-common/trunk/debian/README.Debian
===================================================================
--- zope-common/trunk/debian/README.Debian	2006-11-02 20:57:40 UTC (rev 444)
+++ zope-common/trunk/debian/README.Debian	2006-11-02 22:12:21 UTC (rev 445)
@@ -124,4 +124,37 @@
 Manually installed products and 'copied' products are not removed from
 the instances.
 
- -- Matthias Klose <doko at ubuntu.com>, Sun, 13 Feb 2005 23:31:07 +0100
+
+Using dzhandle with non-root users
+----------------------------------
+
+Starting from zope-common 0.5.26 it is possible to use dzhandle as non-root
+users to create and manage zope and zeo instances; these personal instances
+won't be started at system start-up by the init script.
+
+The default paths for personal zope and zeo instances are:
+
+  $HOME/zope-instances
+  $HOME/zeo-instances
+
+These paths can be overridden creating a file ~/.dzhandle.conf within the
+home directory of the user with the following syntax:
+
+  # this is a comment
+  instances: /home/user1/zope/instances
+  zeoinstances: /home/user1/zope/zeo
+
+dzhandle detects when it is used with a non-root user and reads the
+configuration file in the home directory (or use the defaults). This
+is an example usage of this feature:
+
+  $ whoami
+  user1
+  $ dzhandle -z2.9 make-instance testing -m manual -u admin:pwd
+  $ dzhandle -z2.9 add-product testing CMFPlone
+  $ dzhandle -z2.9 zopectl testing start
+  $ dzhandle -z2.9 zopectl testing stop
+  $ dzhandle -z2.9 purge-instance testing
+  
+  this instance will be created in:
+      /home/user1/zope-instances/zope2.9/testing

Modified: zope-common/trunk/debian/changelog
===================================================================
--- zope-common/trunk/debian/changelog	2006-11-02 20:57:40 UTC (rev 444)
+++ zope-common/trunk/debian/changelog	2006-11-02 22:12:21 UTC (rev 445)
@@ -5,14 +5,16 @@
   * debian/templates: fixed two typos. (Closes: #385882)
   * debian/control: sb-release and po-debconf should be in Build-Depends.
     (Closes: #392653)
+  * debian/po/cs.po: updated. (Closes: #396759)
   * dzhandle: restart only running instances on upgrades.
     (Closes: #388253, #378364)
   * dzhandle: use the atechnique from instance if not specified on the
     command-line. (Closes: #382773)
-  * debian/po/cs.po: updated. (Closes: #396759)
+  * dzhandle: implemented basic normal-user personal instances handling.
+    (Closes: #359256)
   * debian/rules: mv dzhandle from /usr/sbin to /usr/bin. (Closes: #379169)
 
- -- Fabio Tranchitella <kobold at debian.org>  Thu,  2 Nov 2006 21:44:49 +0100
+ -- Fabio Tranchitella <kobold at debian.org>  Thu,  2 Nov 2006 23:10:54 +0100
 
 zope-common (0.5.25) unstable; urgency=low
 

Modified: zope-common/trunk/dzhandle
===================================================================
--- zope-common/trunk/dzhandle	2006-11-02 20:57:40 UTC (rev 444)
+++ zope-common/trunk/dzhandle	2006-11-02 22:12:21 UTC (rev 445)
@@ -76,6 +76,10 @@
 def addon_technique_code(name):
     return addon_options.index(name)
 
+personal_conf = {}
+def is_root():
+    return os.getuid() == 0
+
 known_actions = {}
 def register_action(action_class):
     known_actions[action_class.name] = action_class
@@ -201,7 +205,8 @@
         else:
             self.read_dzfile()
         if self.type == None:
-            if path.startswith('/usr/share/zope') or path.startswith('/usr/lib/zope'):
+            if path.startswith('/usr/share/zope') or \
+               path.startswith('/usr/lib/zope'):
                 self.type = ADDON_MASTER
             elif os.path.islink(path):
                 self.type = ADDON_LINKED
@@ -732,9 +737,6 @@
         self.mode = self.mode_args[0]
         del self.mode_args[0]
         package, directory, addon_name = self.args
-
-        #instances = locate_instances(versions=global_options.zversion)
-
         return self.errors_occured
     
     def run(self, global_options):
@@ -1400,7 +1402,12 @@
         if self.options.user and not ":" in self.options.user:
             self.error('user must be specified as name:password')
 
-        if not ":" in self.options.srvuser:
+        if not is_root() and self.options.srvuser == 'zope:zope':
+            self.uid = os.getuid()
+            self.gid = os.getgid()
+            self.options.srvuser = "%s:%s" % \
+                (pwd.getpwuid(os.getuid())[0], grp.getgrgid(os.getgid())[0])
+        elif not ":" in self.options.srvuser:
             self.error('service user must be specified as user:group')
         else:
             try:
@@ -1425,7 +1432,10 @@
             self.error("unknown restart policy `%s'" % self.options.restart)
 
         self.zope = filter_zope_version(version=self.zversion)
-        self.instance_home = os.path.join(self.zope['instance'], self.instance_name)
+        if is_root():
+            self.instance_home = os.path.join(self.zope['instance'], self.instance_name)
+        else:
+            self.instance_home = os.path.join(personal_conf['instances'], self.zope['name'], self.instance_name)
         if os.path.exists(self.instance_home):
             self.error("instance home `%s' already exists" % self.instance_home)
         return self.errors_occured
@@ -1435,9 +1445,8 @@
             cmd = [os.path.join(self.zope['prefix'], 'bin', 'mkzopeinstance.py')]
         else:
             cmd = [os.path.join(self.zope['prefix'], 'bin', 'mkzopeinstance'), '--password-manager=MD5']
-        cmd.append('--layout=fhs')
         cmd.append('--dir=%s' % self.instance_home)
-        cmd.append('--layout=fhs')
+        cmd.append('--layout=%s' % (is_root() and 'fhs' or 'zope'))
         if self.options.user:
             cmd.append('--user=' + self.options.user)
         if self.options.srvuser:
@@ -1503,7 +1512,11 @@
         else:
             self.port = None
         self.zope = filter_zope_version(version=self.zversion)
-        self.instance_home = os.path.join(self.zope['zeoinstance'], self.instance_name)
+
+        if is_root():
+            self.instance_home = os.path.join(self.zope['zeoinstance'], self.instance_name)
+        else:
+            self.instance_home = os.path.join(personal_conf['zeoinstances'], self.zope['name'], self.instance_name)
         if os.path.exists(self.instance_home):
             self.error("instance home `%s' already exists" % self.instance_home)
         return self.errors_occured
@@ -2039,7 +2052,11 @@
     pkgs = [(z['version'], z['instance']) for z in zope_packages
             if not versions or z['version'] in versions]
     for version, instance_dir in pkgs:
-        for home in glob.glob(os.path.join(instance_dir, '*')):
+        inst_list = glob.glob(os.path.join(instance_dir, '*'))
+        if not is_root():
+            inst_list.extend(glob.glob(os.path.join(
+                personal_conf['instances'], 'zope%s' % version, '*')))
+        for home in inst_list:
             if os.path.isdir(os.path.join(home, 'var')):
                 instance = ZopeInstance(home, version)
                 instances.append(instance)
@@ -2050,7 +2067,11 @@
     pkgs = [(z['version'], z['zeoinstance']) for z in zope_packages
             if not versions or z['version'] in versions]
     for version, instance_dir in pkgs:
-        for home in glob.glob(os.path.join(instance_dir, '*')):
+        inst_list = glob.glob(os.path.join(instance_dir, '*'))
+        if not is_root():
+            inst_list.extend(glob.glob(os.path.join(
+                personal_conf['zeoinstances'], 'zope%s' % version, '*')))
+        for home in inst_list:
             if os.path.isdir(os.path.join(home, 'var')):
                 instance = ZeoInstance(home, version)
                 instances.append(instance)
@@ -2193,6 +2214,9 @@
         else:
             user = global_options.user
             group = None
+    elif not is_root():
+        user = pwd.getpwuid(os.getuid())[0]
+        group = grp.getgrgid(os.getgid())[0]
     else:
         user = 'zope'
         group = 'zope'
@@ -2268,6 +2292,17 @@
         print >>sys.stderr, msg
         sys.exit(1)
 
+    # read personal configuration file
+    uid = os.getuid()
+    if not is_root():
+        home_dir = pwd.getpwuid(uid)[5]
+        conf = os.path.join(home_dir, '.dzhandle.conf')
+        if os.path.exists(conf):
+            personal_conf.update(read_config_file(conf))
+        else:
+            personal_conf['instances'] = os.path.join(home_dir, 'zope-instances')
+            personal_conf['zeoinstances'] = os.path.join(home_dir, 'zeo-instances')
+
     # setup logging stuff
     setup_logging(config.get('logfile', None),
                   config.get('logfilelevel', logging.INFO),




More information about the pkg-zope-commits mailing list