[Checkins] SVN: zc.recipe.rhrc/trunk/ Added ignores.

Jim Fulton jim at zope.com
Thu Jan 11 17:31:20 EST 2007


Log message for revision 71944:
  Added ignores.
  

Changed:
  _U  zc.recipe.rhrc/trunk/
  U   zc.recipe.rhrc/trunk/src/zc/recipe/rhrc/README.txt
  U   zc.recipe.rhrc/trunk/src/zc/recipe/rhrc/__init__.py

-=-

Property changes on: zc.recipe.rhrc/trunk
___________________________________________________________________
Name: svn:ignore
   + develop-eggs
bin
parts
.installed.cfg


Modified: zc.recipe.rhrc/trunk/src/zc/recipe/rhrc/README.txt
===================================================================
--- zc.recipe.rhrc/trunk/src/zc/recipe/rhrc/README.txt	2007-01-11 21:47:09 UTC (rev 71943)
+++ zc.recipe.rhrc/trunk/src/zc/recipe/rhrc/README.txt	2007-01-11 22:31:20 UTC (rev 71944)
@@ -6,9 +6,12 @@
 scripts that start multiple applications.
 
 The recipe has a parts option that takes the names of sections that
-define run-script options, which contain one-line control scripts.  Let's
-look at a simple example.
+define run scripts.  They should either:
 
+- Define a run-script option that contains a one-line shell script, or
+
+- The file /etc/init.d/PART should exist, where PART is the part name.
+
 A simple example will, hopefully make this clearer. 
 
     >>> demo = tmpdir('demo')
@@ -28,7 +31,7 @@
     ... """ % dict(dest=demo))
 
 Normally the recipe writes scripts to /etc/init.d.  We can override
-the destivation, which we've done here, using a demonstration
+the destination, which we've done here, using a demonstration
 directory.  We specified a that it should get run-script source from
 the zope section.  Here the zope section is simply a configuration
 section with a run-script option set directly, but it could have been
@@ -286,7 +289,6 @@
     esac
     <BLANKLINE>
 
-
 A part that defines a run script can also define environment-variable
 settings to be used by the rc script by supplying an env option:
 
@@ -355,6 +357,88 @@
     esac
     <BLANKLINE>
 
+Working with existing control scripts
+-------------------------------------
+
+In the example above, we generated a script based on a command line.
+If we have a part that creates a control script on it's own, ten it
+can ommit the run-script option and it's already created run script
+will be used.  Let's create a run script ourselves:
+
+    >>> write(demo, 'zope', '/opt/zope/bin/zopectl -C /etc/zope.conf $*')
+
+Now we can remove the run-script option from the Zope section:
+
+    >>> write('buildout.cfg',
+    ... """
+    ... [buildout]
+    ... parts = zoperc
+    ...
+    ... [zoperc]
+    ... recipe = zc.recipe.rhrc
+    ... parts = zope
+    ... dest = %(dest)s
+    ... chkconfig = 345 90 10
+    ... chkconfigcommand = echo
+    ... user = zope
+    ...
+    ... [zope]
+    ... env = LD_LIBRARY_PATH=/opt/foolib
+    ... """ % dict(dest=demo))
+
+    >>> print system('bin/buildout'),
+    buildout: Uninstalling zoperc
+    buildout: Running uninstall recipe
+    --del zoperc
+    buildout: Installing zoperc
+    --add zoperc
+
+    >>> cat(demo, 'zoperc')
+    #!/bin/sh 
+    <BLANKLINE>
+    # the next line is for chkconfig
+    # chkconfig: 345 90 10
+    # description: please, please work
+    <BLANKLINE>
+    <BLANKLINE>
+    if [ $(whoami) != "root" ]; then
+      echo "You must be root."
+      exit 1
+    fi
+    <BLANKLINE>
+    case $1 in 
+      stop)
+    <BLANKLINE>
+        /demo/zope "$@" \
+          </dev/null
+    <BLANKLINE>
+        ;;
+      restart)
+    <BLANKLINE>
+        ${0} stop
+        sleep 1
+        ${0} start
+    <BLANKLINE>
+        ;;
+      *) 
+    <BLANKLINE>
+        /demo/zope "$@" \
+          </dev/null
+    <BLANKLINE>
+        ;;
+    esac
+    <BLANKLINE>
+
+Here we just invoke the existing script.  Note that don't pay any
+reflect the env or user options in the script.  When an existing
+script is used, it is assumed to be complete.
+
+    >>> import os
+    >>> os.remove(join(demo, 'zope'))
+
+Multiple processes
+------------------
+
 Sometimes, you need to start multiple processes.  You can specify
 multiple parts. For example, suppose we wanted to start 2 Zope
 instances:
@@ -377,10 +461,12 @@
     ... env = LD_LIBRARY_PATH=/opt/foolib
     ...
     ... [instance2]
-    ... run-script = /opt/zope/bin/zopectl -C /etc/instance2.conf
-    ... env = LD_LIBRARY_PATH=/opt/foolib
     ... """ % dict(dest=demo))
+    
+    >>> write(demo, 'instance2', '')
 
+Note that for instance 2, we are arranging for the script to pre-exist.
+
     >>> print system('bin/buildout'),
     buildout: Uninstalling zoperc
     buildout: Running uninstall recipe
@@ -404,9 +490,7 @@
     case $1 in 
       stop)
     <BLANKLINE>
-        LD_LIBRARY_PATH=/opt/foolib \
-          su zope -c \
-          "/opt/zope/bin/zopectl -C /etc/instance2.conf $*" \
+        /demo/instance2 "$@" \
           </dev/null
     <BLANKLINE>
         LD_LIBRARY_PATH=/opt/foolib \
@@ -429,9 +513,7 @@
           "/opt/zope/bin/zopectl -C /etc/instance1.conf $*" \
           </dev/null
     <BLANKLINE>
-        LD_LIBRARY_PATH=/opt/foolib \
-          su zope -c \
-          "/opt/zope/bin/zopectl -C /etc/instance2.conf $*" \
+        /demo/instance2 "$@" \
           </dev/null
     <BLANKLINE>
         ;;
@@ -442,12 +524,13 @@
 reverese order.  This isn't so important in a case like this, but
 would be more important if a later script depended on an earlier one.
 
-In addition to the zoperc script, we got scripts for each instance:
+In addition to the zoperc script, we got scripts for the instance with
+the run-script option:
 
     >>> ls(demo)
+    -  instance2
     -  zoperc
     -  zoperc-instance1
-    -  zoperc-instance2
 
     >>> cat(demo, 'zoperc-instance1')
     #!/bin/sh 
@@ -488,11 +571,14 @@
 
 The individual scripts don't have chkconfig information.
 
+Deployments
+-----------
+
 The zc.recipe.rhrc recipe is designed to work with the
 zc.recipe.deployment recipe.  You can specify the name of a deployment
 section.  If a deployment section is specified, then that name will be
 used for the rc scripts and the user from the deployment section will
-be used if a user isn't specified in the rc script's own section:
+be used if a user isn't specified in the rc script's own section.
 
     >>> write('buildout.cfg',
     ... """
@@ -515,10 +601,14 @@
     ... env = LD_LIBRARY_PATH=/opt/foolib
     ...
     ... [instance2]
-    ... run-script = /opt/zope/bin/zopectl -C /etc/instance2.conf
-    ... env = LD_LIBRARY_PATH=/opt/foolib
     ... """ % dict(dest=demo))
 
+If a deployment is used, then any existing scripts must be
+prefixed with the deployment name.  We'll rename the instance2 script
+to reflect that:
+
+    >>> os.rename(join(demo, 'instance2'), join(demo, 'acme-instance2'))
+
     >>> print system('bin/buildout'),
     buildout: Uninstalling zoperc
     buildout: Running uninstall recipe
@@ -547,9 +637,7 @@
     case $1 in 
       stop)
     <BLANKLINE>
-        LD_LIBRARY_PATH=/opt/foolib \
-          su acme -c \
-          "/opt/zope/bin/zopectl -C /etc/instance2.conf $*" \
+        /demo/acme-instance2 "$@" \
           </dev/null
     <BLANKLINE>
         LD_LIBRARY_PATH=/opt/foolib \
@@ -572,9 +660,7 @@
           "/opt/zope/bin/zopectl -C /etc/instance1.conf $*" \
           </dev/null
     <BLANKLINE>
-        LD_LIBRARY_PATH=/opt/foolib \
-          su acme -c \
-          "/opt/zope/bin/zopectl -C /etc/instance2.conf $*" \
+        /demo/acme-instance2 "$@" \
           </dev/null
     <BLANKLINE>
         ;;

Modified: zc.recipe.rhrc/trunk/src/zc/recipe/rhrc/__init__.py
===================================================================
--- zc.recipe.rhrc/trunk/src/zc/recipe/rhrc/__init__.py	2007-01-11 21:47:09 UTC (rev 71943)
+++ zc.recipe.rhrc/trunk/src/zc/recipe/rhrc/__init__.py	2007-01-11 22:31:20 UTC (rev 71944)
@@ -16,24 +16,28 @@
 $Id: __init__.py 15402 2006-12-01 15:58:08Z jim $
 """
 
-import os, shutil, stat
+import logging, os, shutil, stat
+import zc.buildout
 
+logger = logging.getLogger('zc.recipe.rhrc')
+
 class Recipe:
 
     def __init__(self, buildout, name, options):
         self.name, self.options = name, options
-        deployment = options.get('deployment')
+        deployment = self.deployment = options.get('deployment')
         if deployment:
             self.name = deployment
             if 'user' not in options:
                 options['user'] = buildout[deployment].get('user', '')
 
-        options['scripts'] = '\n'.join([buildout[part]['run-script']
+        options['scripts'] = '\n'.join([buildout[part].get('run-script', '')
                                         for part in options['parts'].split()
                                         ])
         options['envs'] = '\n'.join([buildout[part].get('env', '')
                                      for part in options['parts'].split()
                                      ])
+        options['dest'] = self.options.get('dest', '/etc/init.d')
 
     def install(self):
         options = self.options
@@ -51,32 +55,41 @@
             if len(scripts) == 1:
                 # No mongo script
                 script = scripts[0]
-                if user:
-                    script = 'su %s -c \\\n      "%s $*"' % (user, script)
-                else:
-                    script += ' $*'
-                    
-                env = envs[0]
-                if env:
-                    script = env + ' \\\n      ' + script
-                if chkconfig:
-                    script += ' \\\n      </dev/null'
-                self.output(chkconfig, script, self.name, created)
-            else:
-                cooked = []
-                for env, script in zip(envs, scripts):
+                if script:
                     if user:
                         script = 'su %s -c \\\n      "%s $*"' % (user, script)
                     else:
                         script += ' $*'
 
+                    env = envs[0]
                     if env:
                         script = env + ' \\\n      ' + script
+                else:
+                    script = self.no_script(parts[0])
 
+                if chkconfig:
+                    script += ' \\\n      </dev/null'
+                self.output(chkconfig, script, self.name, created)
+            else:
+                cooked = []
+                for part, env, script in zip(parts, envs, scripts):
+                    if script:
+
+                        if user:
+                            script = 'su %s -c \\\n      "%s $*"' % (
+                                user, script)
+                        else:
+                            script += ' $*'
+
+                        if env:
+                            script = env + ' \\\n      ' + script
+
+                        self.output('', script, self.name+'-'+part, created)
+
+                    else:
+                        script = self.no_script(part)
+                                              
                     cooked.append(script)
-                    
-                for part, script in zip(parts, cooked):
-                    self.output('', script, self.name+'-'+part, created)
 
                 if chkconfig:
                     cooked = [s + ' \\\n      </dev/null'
@@ -91,6 +104,21 @@
             [os.remove(f) for f in created]
             raise
 
+    def no_script(self, part):
+        options = self.options
+        if self.deployment:
+            script = os.path.join(options['dest'], self.name+'-'+part)
+        else:
+            script = os.path.join(options['dest'], part)
+            
+        if not os.path.exists(script):
+            logger.error("Part %s doesn't define run-script "
+                         "and %s doesn't exist."
+                         % (part, script))
+            raise zc.buildout.UserError("No script for %s", part)
+
+        return script + ' "$@"'
+
     def output(self, chkconfig, script, ctl, created, rscript=None):
         if rscript is None:
             rscript = script



More information about the Checkins mailing list