[Checkins] SVN: zc.zodbrecipes/trunk/zc/zodbrecipes/ New Feature:
Jim Fulton
jim at zope.com
Thu Jan 3 14:07:50 EST 2008
Log message for revision 82650:
New Feature:
If you install a general ZEO script, using a zdaemon part::
[zdaemon]
recipe = zc.recipe.egg:script
eggs = zdaemon
you can request that shell scripts be generated that use the generic
zdaemon script. This can make updating software for deployed systems
easier since instance-specific scripts don't depend on paths, like
egg names, that are likely to change.
Changed:
U zc.zodbrecipes/trunk/zc/zodbrecipes/__init__.py
U zc.zodbrecipes/trunk/zc/zodbrecipes/zeo.txt
-=-
Modified: zc.zodbrecipes/trunk/zc/zodbrecipes/__init__.py
===================================================================
--- zc.zodbrecipes/trunk/zc/zodbrecipes/__init__.py 2008-01-03 19:07:48 UTC (rev 82649)
+++ zc.zodbrecipes/trunk/zc/zodbrecipes/__init__.py 2008-01-03 19:07:50 UTC (rev 82650)
@@ -52,11 +52,21 @@
buildout['buildout']['bin-directory'],
options.get('runzeo', 'runzeo'),
)
+
+ options['zdaemon'] = os.path.join(
+ buildout['buildout']['bin-directory'],
+ options.get('zdaemon', 'zdaemon'),
+ )
+
options['zeopack'] = os.path.join(
buildout['buildout']['bin-directory'],
options.get('zeopack', 'zeopack'),
)
+ if options.get('shell-script', '') not in ('true', 'false', ''):
+ raise zc.buildout.UserError(
+ 'The shell-script option value must be "true", "false" or "".')
+
def install(self):
options = self.options
@@ -82,7 +92,8 @@
rc=os.path.join(options['rc-directory'], rc),
conf=zdaemon_conf_path,
))
-
+
+
creating = [zeo_conf_path, zdaemon_conf_path, logrotate,
os.path.join(options['rc-directory'], rc),
]
@@ -176,21 +187,41 @@
open(zeo_conf_path, 'w').write(str(zeo_conf))
open(zdaemon_conf_path, 'w').write(str(zdaemon_conf))
- self.egg.install()
- requirements, ws = self.egg.working_set()
+ if options.get('shell-script') == 'true':
+ if not os.path.exists(options['zdaemon']):
+ logger.warn(no_zdaemon % options['zdaemon'])
+ if options.get('user'):
+ su = 'su %s -c' % options['user']
+ else:
+ su = ''
- zc.buildout.easy_install.scripts(
- [(rc, 'zdaemon.zdctl', 'main')],
- ws, options['executable'], options['rc-directory'],
- arguments = ('['
- '\n %r, %r,'
- '\n ]+sys.argv[1:]'
- '\n '
- % ('-C', zdaemon_conf_path,
- )
- ),
- )
+ dest = os.path.join(options['rc-directory'], rc)
+ contents = shell_script_template % dict(
+ zdaemon = options['zdaemon'],
+ conf = zdaemon_conf_path,
+ su = su,
+ )
+ if not (os.path.exists(dest) and open(dest).read() == contents):
+ open(dest, 'w').write(contents)
+ os.chmod(dest, 0755)
+ logger.info("Generated shell script %r.", dest)
+
+ else:
+ self.egg.install()
+ requirements, ws = self.egg.working_set()
+ zc.buildout.easy_install.scripts(
+ [(rc, 'zdaemon.zdctl', 'main')],
+ ws, options['executable'], options['rc-directory'],
+ arguments = ('['
+ '\n %r, %r,'
+ '\n ]+sys.argv[1:]'
+ '\n '
+ % ('-C', zdaemon_conf_path,
+ )
+ ),
+ )
+
if pack:
address, = zeo_section['address']
if ':' in address:
@@ -243,7 +274,20 @@
to specify the location of a script using the runzeo option.
"""
+no_zdaemon = """
+A zdaemon script couldn't be found at:
+ %r
+
+You may need to generate a zdaemon script using the
+zc.recipe.eggs:script recipe and the zdaemon egg.
+"""
+
+shell_script_template = r"""#!/bin/sh
+%(su)s %(zdaemon)s \
+ -C "%(conf)s" $*
+"""
+
def event_log(path, *data):
return ZConfig.schemaless.Section(
'eventlog', '', None,
Modified: zc.zodbrecipes/trunk/zc/zodbrecipes/zeo.txt
===================================================================
--- zc.zodbrecipes/trunk/zc/zodbrecipes/zeo.txt 2008-01-03 19:07:48 UTC (rev 82649)
+++ zc.zodbrecipes/trunk/zc/zodbrecipes/zeo.txt 2008-01-03 19:07:50 UTC (rev 82650)
@@ -331,8 +331,23 @@
Instead, the control script will be in the rc directory:
- >>> ls('rc')
- - demo-server
+ >>> cat('rc', 'demo-server')
+ #!/usr/local/bin/python2.4
+ <BLANKLINE>
+ import sys
+ sys.path[0:0] = [
+ '/sample-buildout/eggs/zdaemon-2.0-py2.4.egg',
+ '/sample-buildout/eggs/setuptools-0.6-py2.4.egg',
+ '/sample-buildout/eggs/ZConfig-2.4-py2.4.egg',
+ ]
+ <BLANKLINE>
+ import zdaemon.zdctl
+ <BLANKLINE>
+ if __name__ == '__main__':
+ zdaemon.zdctl.main([
+ '-C', '/sample-buildout/etc/server-zdaemon.conf',
+ ]+sys.argv[1:]
+ )
The run-control script name now combines the deployment name and the
script name.
@@ -380,6 +395,9 @@
their part names. Also note that the deployment user is set in the
zdaemon configuration.
+Packing cron job
+================
+
We can request definition of a cron job to pack the databases by
specifying a pack option. This option takes 5 to 7 values. The
first 5 values are the time and date fields defined by Unix crontab
@@ -485,3 +503,69 @@
This causes email to be sent to the given address, rather than to the
user specified in the crontab file.
+
+shell start scripts
+===================
+
+By default, the startup scripts are generated Python scripts that use
+the zdaemon module. Sometimes, this is inconvenient. In particular,
+when deploying software, generated Python scripts may break after a
+software update because they contain pasths to software eggs. We can
+request shell scripts that invoke a generic zdaemon script. The shell
+script only depends on the path to the zdaemon script, which generally
+doesn't change when updating softawre.
+
+To request a shell script, add a shell-script option with a true
+value. We also need to cause a zdaemon script to be generated:
+
+ >>> write('buildout.cfg',
+ ... '''
+ ... [buildout]
+ ... parts = zodb zdaemon server
+ ...
+ ... [zodb]
+ ... recipe = zc.recipe.egg:script
+ ... eggs = ZODB3
+ ...
+ ... [zdaemon]
+ ... recipe = zc.recipe.egg:script
+ ... eggs = zdaemon
+ ...
+ ... [server]
+ ... recipe = zc.zodbrecipes:server
+ ... zeo.conf =
+ ... <zeo>
+ ... address 8100
+ ... monitor-address 8101
+ ... transaction-timeout 300
+ ... </zeo>
+ ... %%import foo
+ ... <foo main>
+ ... path /databases/Data.fs
+ ... </foo>
+ ... deployment = demo
+ ... pack = 1 1 * * 0 3 jim at zope.com
+ ... shell-script = true
+ ...
+ ... [demo]
+ ... crontab-directory = %(cron)s
+ ... etc-directory = %(etc)s
+ ... log-directory = %(log)s
+ ... logrotate-directory = %(rotate)s
+ ... rc-directory = %(rc)s
+ ... run-directory = %(run)s
+ ... user = bob
+ ... ''' % globals())
+
+ >>> print system(buildout+' -D'),
+ Uninstalling server.
+ Updating zodb.
+ Installing zdaemon.
+ Generated script '/sample-buildout/bin/zdaemon'.
+ Installing server.
+ zc.zodbrecipes: Generated shell script '/sample-buildout/rc/demo-server'.
+
+ >>> cat('rc', 'demo-server')
+ #!/bin/sh
+ su bob -c /sample-buildout/bin/zdaemon \
+ -C "/sample-buildout/etc/server-zdaemon.conf" $*
More information about the Checkins
mailing list