Commit 411212fb authored by Julien Muchembled's avatar Julien Muchembled

Always use GenericBaseRecipe.createWrapper for executable wrappers

This moves most of the wrapper recipe to GenericBaseRecipe so that
createWrapper automatically switches to Python scripts for complex cases.

Recipes should not use slapos.recipe.librecipe.execute.generic_exec directly
anymore.
parent a5d31970
...@@ -57,10 +57,9 @@ class Recipe(GenericBaseRecipe): ...@@ -57,10 +57,9 @@ class Recipe(GenericBaseRecipe):
) )
path_list.append(httpd_conf) path_list.append(httpd_conf)
wrapper = self.createPythonScript(self.options['wrapper'], wrapper = self.createWrapper(self.options['wrapper'],
'slapos.recipe.librecipe.execute.generic_exec', (self.options['httpd-binary'], '-f', self.options['httpd-conf'],
((self.options['httpd-binary'], '-f', self.options['httpd-conf'], '-DFOREGROUND'),
'-DFOREGROUND'),)
) )
path_list.append(wrapper) path_list.append(wrapper)
......
...@@ -92,14 +92,13 @@ class Recipe(GenericBaseRecipe): ...@@ -92,14 +92,13 @@ class Recipe(GenericBaseRecipe):
) )
path_list.append(httpd_conf) path_list.append(httpd_conf)
wrapper = self.createWrapper(name=self.options['wrapper'], wrapper = self.createWrapper(self.options['wrapper'],
command=self.options['httpd-binary'], (self.options['httpd-binary'],
parameters=[
'-f', '-f',
self.options['httpd-conf'], self.options['httpd-conf'],
'-DFOREGROUND' '-DFOREGROUND'
], ),
environment=self.environ) self.environ)
path_list.append(wrapper) path_list.append(wrapper)
secret_key_filename = os.path.join(self.buildout['buildout']['directory'], secret_key_filename = os.path.join(self.buildout['buildout']['directory'],
......
...@@ -49,13 +49,12 @@ class Recipe(GenericBaseRecipe): ...@@ -49,13 +49,12 @@ class Recipe(GenericBaseRecipe):
) )
path_list.append(httpd_conf) path_list.append(httpd_conf)
wrapper = self.createWrapper(name=self.options['wrapper'], wrapper = self.createWrapper(self.options['wrapper'],
command=self.options['httpd-binary'], (self.options['httpd-binary'],
parameters=[
'-f', '-f',
self.options['httpd-conf'], self.options['httpd-conf'],
'-DFOREGROUND', '-DFOREGROUND',
]) ))
path_list.append(wrapper) path_list.append(wrapper)
......
...@@ -124,9 +124,8 @@ class Recipe(GenericBaseRecipe): ...@@ -124,9 +124,8 @@ class Recipe(GenericBaseRecipe):
#Generate wrapper for php #Generate wrapper for php
wrapperphp = os.path.join(self.home, 'bin/php') wrapperphp = os.path.join(self.home, 'bin/php')
php_wrapper = self.createPythonScript(wrapperphp, php_wrapper = self.createWrapper(wrapperphp,
'slapos.recipe.librecipe.execute.generic_exec', (self.phpbin, '-c', self.phpini),
((self.phpbin, '-c', self.phpini),)
) )
path_list.append(php_wrapper) path_list.append(php_wrapper)
...@@ -406,11 +405,10 @@ class Client(GenericBaseRecipe): ...@@ -406,11 +405,10 @@ class Client(GenericBaseRecipe):
path_list.append(cmd) path_list.append(cmd)
#Generate BOINC client wrapper #Generate BOINC client wrapper
boinc = self.createPythonScript(boinc_wrapper, boinc = self.createWrapper(boinc_wrapper,
'slapos.recipe.librecipe.execute.generic_exec', (boincbin, '--allow_multiple_clients', '--gui_rpc_port',
((boincbin, '--allow_multiple_clients', '--gui_rpc_port',
str(self.options['rpc-port']), '--allow_remote_gui_rpc', str(self.options['rpc-port']), '--allow_remote_gui_rpc',
'--dir', installdir, '--redirectio', '--check_all_logins'),) '--dir', installdir, '--redirectio', '--check_all_logins'),
) )
path_list.append(boinc) path_list.append(boinc)
......
...@@ -73,16 +73,15 @@ class Recipe(GenericBaseRecipe): ...@@ -73,16 +73,15 @@ class Recipe(GenericBaseRecipe):
bg_wrapper = self.options['wrapper'].strip() bg_wrapper = self.options['wrapper'].strip()
log = self.options['log_file'].strip() log = self.options['log_file'].strip()
pid_file = self.options['pid_file'].strip() pid_file = self.options['pid_file'].strip()
wrapper = self.createPythonScript(bg_wrapper, wrapper = self.createWrapper(bg_wrapper,
'slapos.recipe.librecipe.execute.generic_exec', (python, bonjourgrid_master, '--log_file', log,
((python, bonjourgrid_master, '--log_file', log,
'--pid_file', pid_file, '--pid_file', pid_file,
'--master_wrapper', grid_wrapper, '--master_wrapper', grid_wrapper,
'--directory', self.options['work_dir'].strip(), '--directory', self.options['work_dir'].strip(),
'--server', self.options['redis-url'].strip(), '--server', self.options['redis-url'].strip(),
'--port', self.options['redis-port'].strip(), '--port', self.options['redis-port'].strip(),
'--num_workers', self.options['nworkers'].strip(), '--num_workers', self.options['nworkers'].strip(),
),) ),
) )
path_list.append(wrapper) path_list.append(wrapper)
...@@ -113,9 +112,8 @@ class Client(GenericBaseRecipe): ...@@ -113,9 +112,8 @@ class Client(GenericBaseRecipe):
bg_wrapper = self.options['wrapper'].strip() bg_wrapper = self.options['wrapper'].strip()
log = self.options['log_file'].strip() log = self.options['log_file'].strip()
pid_file = self.options['pid_file'].strip() pid_file = self.options['pid_file'].strip()
wrapper = self.createPythonScript(bg_wrapper, wrapper = self.createWrapper(bg_wrapper,
'slapos.recipe.librecipe.execute.generic_exec', (python, bonjourgrid_client, '--log_file', log,
((python, bonjourgrid_client, '--log_file', log,
'--pid_file', pid_file, '--pid_file', pid_file,
'--boinc_wrapper', boinc_script, '--boinc_wrapper', boinc_script,
'--condor_wrapper', condor_script, '--condor_wrapper', condor_script,
...@@ -123,7 +121,7 @@ class Client(GenericBaseRecipe): ...@@ -123,7 +121,7 @@ class Client(GenericBaseRecipe):
'--install_directory', self.options['install_dir'].strip(), '--install_directory', self.options['install_dir'].strip(),
'--server', self.options['redis-url'].strip(), '--server', self.options['redis-url'].strip(),
'--port', self.options['redis-port'].strip(), '--port', self.options['redis-port'].strip(),
),) ),
) )
path_list.append(wrapper) path_list.append(wrapper)
......
...@@ -137,11 +137,10 @@ class Request(Recipe): ...@@ -137,11 +137,10 @@ class Request(Recipe):
path_list = [key_file, cert_file] path_list = [key_file, cert_file]
if request_needed: if request_needed:
wrapper = self.createPythonScript( wrapper = self.createWrapper(
self.options['wrapper'], self.options['wrapper'],
'slapos.recipe.librecipe.execute.generic_exec', (self.options['executable'],),
((self.options['executable'],),), wait_list=(certificate, key),
{'wait_list': (certificate, key)},
) )
path_list.append(wrapper) path_list.append(wrapper)
......
...@@ -49,7 +49,4 @@ class Recipe(GenericBaseRecipe): ...@@ -49,7 +49,4 @@ class Recipe(GenericBaseRecipe):
cloud9_args = [self.node_executable, self.cloud9, '-l', self.ip, '-p', cloud9_args = [self.node_executable, self.cloud9, '-l', self.ip, '-p',
self.port, '-w', self.workdir] self.port, '-w', self.workdir]
return self.createPythonScript(self.wrapper, return self.createWrapper(self.wrapper, cloud9_args, environment)
'slapos.recipe.librecipe.execute.generic_exec',
(cloud9_args, environment)
)
...@@ -98,9 +98,8 @@ class Recipe(GenericBaseRecipe): ...@@ -98,9 +98,8 @@ class Recipe(GenericBaseRecipe):
) )
path_list.append(config_file) path_list.append(config_file)
wrapper = self.createPythonScript(self.options['wrapper'], wrapper = self.createWrapper(self.options['wrapper'],
'slapos.recipe.librecipe.execute.generic_exec', (self.options['apache-binary'], '-f', config_file, '-DFOREGROUND'))
((self.options['apache-binary'], '-f', config_file, '-DFOREGROUND'),))
path_list.append(wrapper) path_list.append(wrapper)
promise = self.createPythonScript(self.options['promise'], promise = self.createPythonScript(self.options['promise'],
......
...@@ -35,15 +35,14 @@ class Recipe(GenericBaseRecipe): ...@@ -35,15 +35,14 @@ class Recipe(GenericBaseRecipe):
self.logger.info("Installing dcron...") self.logger.info("Installing dcron...")
options = self.options options = self.options
script = self.createWrapper(name=options['binary'], script = self.createWrapper(options['binary'],
command=options['dcrond-binary'].strip(), (options['dcrond-binary'].strip(),
parameters=[
'-s', options['cron-entries'], '-s', options['cron-entries'],
'-c', options['crontabs'], '-c', options['crontabs'],
'-t', options['cronstamps'], '-t', options['cronstamps'],
'-f', '-l', '5', '-f', '-l', '5',
'-M', options['catcher'] '-M', options['catcher']
]) ))
self.logger.debug('Main cron executable created at : %r', script) self.logger.debug('Main cron executable created at : %r', script)
......
...@@ -93,11 +93,7 @@ class Recipe(GenericBaseRecipe): ...@@ -93,11 +93,7 @@ class Recipe(GenericBaseRecipe):
if 'shell' in self.options: if 'shell' in self.options:
env['DROPBEAR_OVERRIDE_SHELL'] = self.options['shell'] env['DROPBEAR_OVERRIDE_SHELL'] = self.options['shell']
return self.createPythonScript( return self.createWrapper(self.options['wrapper'], dropbear_cmd, env)
self.options['wrapper'],
'slapos.recipe.librecipe.execute.generic_exec',
(dropbear_cmd, env)
)
class Client(GenericBaseRecipe): class Client(GenericBaseRecipe):
...@@ -115,11 +111,7 @@ class Client(GenericBaseRecipe): ...@@ -115,11 +111,7 @@ class Client(GenericBaseRecipe):
if 'identity-file' in self.options: if 'identity-file' in self.options:
dropbear_cmd.extend(['-i', self.options['identity-file']]) dropbear_cmd.extend(['-i', self.options['identity-file']])
return self.createPythonScript( return self.createWrapper(self.options['wrapper'], dropbear_cmd, env)
self.options['wrapper'],
'slapos.recipe.librecipe.execute.generic_exec',
(dropbear_cmd, env)
)
class AddAuthorizedKey(GenericBaseRecipe): class AddAuthorizedKey(GenericBaseRecipe):
......
...@@ -46,5 +46,4 @@ class Recipe(GenericBaseRecipe): ...@@ -46,5 +46,4 @@ class Recipe(GenericBaseRecipe):
cmd.extend(options) cmd.extend(options)
cmd.extend([backup_directory, remote_url]) cmd.extend([backup_directory, remote_url])
return self.createPythonScript(self.options['wrapper'], return self.createWrapper(self.options['wrapper'], cmd)
'slapos.recipe.librecipe.execute.generic_exec', (cmd,))
...@@ -30,23 +30,20 @@ class Recipe(GenericBaseRecipe): ...@@ -30,23 +30,20 @@ class Recipe(GenericBaseRecipe):
def install(self): def install(self):
parameters = [ args = [
self.options['equeue-binary'],
'--database', self.options['database'], '--database', self.options['database'],
'--logfile', self.options['log'], '--logfile', self.options['log'],
'--lockfile', self.options['lockfile'] '--lockfile', self.options['lockfile']
] ]
if 'takeover-triggered-file-path' in self.options: if 'takeover-triggered-file-path' in self.options:
parameters.extend(['--takeover-triggered-file-path', self.options['takeover-triggered-file-path']]) args += ('--takeover-triggered-file-path',
self.options['takeover-triggered-file-path'])
if 'loglevel' in self.options: if 'loglevel' in self.options:
parameters.extend(['--loglevel', self.options['loglevel']]) args += '--loglevel', self.options['loglevel']
parameters.append(self.options['socket']) args.append(self.options['socket'])
wrapper = self.createWrapper(name=self.options['wrapper'],
command=self.options['equeue-binary'],
parameters=parameters)
return [wrapper]
return self.createWrapper(self.options['wrapper'], args)
...@@ -68,17 +68,14 @@ class Recipe(GenericBaseRecipe): ...@@ -68,17 +68,14 @@ class Recipe(GenericBaseRecipe):
) )
self.path_list.append(configuration_file) self.path_list.append(configuration_file)
self.path_list.append( self.path_list.append(
self.createPythonScript( self.createWrapper(self.options['wrapper'],
self.options['wrapper'], # Command
'slapos.recipe.librecipe.execute.generic_exec',
( # Command
( self.options['testnode'], '-l', self.options['log-file'], ( self.options['testnode'], '-l', self.options['log-file'],
configuration_file), configuration_file),
# Environment # Environment
{ {
'GIT_SSL_NO_VERIFY': '1', 'GIT_SSL_NO_VERIFY': '1',
} }
),
) )
) )
self.installApache() self.installApache()
...@@ -106,9 +103,8 @@ class Recipe(GenericBaseRecipe): ...@@ -106,9 +103,8 @@ class Recipe(GenericBaseRecipe):
apache_config) apache_config)
) )
self.path_list.append(config_file) self.path_list.append(config_file)
wrapper = self.createPythonScript(self.options['httpd-wrapper'], wrapper = self.createWrapper(self.options['httpd-wrapper'],
'slapos.recipe.librecipe.execute.generic_exec', (self.options['apache-binary'], '-f', config_file, '-DFOREGROUND'))
((self.options['apache-binary'], '-f', config_file, '-DFOREGROUND'),))
self.path_list.append(wrapper) self.path_list.append(wrapper)
# create empty html page to not allow listing of / # create empty html page to not allow listing of /
page = open(os.path.join(self.options['log-directory'], "index.html"), "w") page = open(os.path.join(self.options['log-directory'], "index.html"), "w")
......
...@@ -165,15 +165,13 @@ class Recipe(GenericBaseRecipe): ...@@ -165,15 +165,13 @@ class Recipe(GenericBaseRecipe):
'--defaults-file=%s' % mysql_conf_file, '--defaults-file=%s' % mysql_conf_file,
'--socket=%s' % socket.strip(), '--user=root', '--socket=%s' % socket.strip(), '--user=root',
'--ibbackup=%s'% self.options['xtrabackup-binary']] '--ibbackup=%s'% self.options['xtrabackup-binary']]
innobackupex_incremental = self.createPythonScript( innobackupex_incremental = self.createWrapper(
self.options['innobackupex-incremental'], self.options['innobackupex-incremental'],
'slapos.recipe.librecipe.execute.generic_exec', innobackupex_argument_list + ['--incremental'], environment)
(innobackupex_argument_list + ['--incremental'], environment))
path_list.append(innobackupex_incremental) path_list.append(innobackupex_incremental)
innobackupex_full = self.createPythonScript( innobackupex_full = self.createWrapper(
self.options['innobackupex-full'], self.options['innobackupex-full'],
'slapos.recipe.librecipe.execute.generic_exec', innobackupex_argument_list, environment)
(innobackupex_argument_list, environment))
path_list.append(innobackupex_full) path_list.append(innobackupex_full)
backup_controller = self.createPythonScript(self.options['backup-script'], __name__ + '.innobackupex.controller', [innobackupex_incremental, innobackupex_full, full_backup, incremental_backup]) backup_controller = self.createPythonScript(self.options['backup-script'], __name__ + '.innobackupex.controller', [innobackupex_incremental, innobackupex_full, full_backup, incremental_backup])
path_list.append(backup_controller) path_list.append(backup_controller)
...@@ -221,10 +219,9 @@ class Recipe(GenericBaseRecipe): ...@@ -221,10 +219,9 @@ class Recipe(GenericBaseRecipe):
'--defaults-file=%s' % mysql_conf_file, '--defaults-file=%s' % mysql_conf_file,
'--socket=%s' % socket.strip(), '--user=root', '--socket=%s' % socket.strip(), '--user=root',
] ]
pt_exe = self.createPythonScript( pt_exe = self.createWrapper(
os.path.join(self.options['bin-directory'], pt_script_name), os.path.join(self.options['bin-directory'], pt_script_name),
'slapos.recipe.librecipe.execute.generic_exec', pt_argument_list, environment)
(pt_argument_list, environment))
path_list.append(pt_exe) path_list.append(pt_exe)
return path_list return path_list
......
...@@ -120,10 +120,9 @@ class Recipe(GenericBaseRecipe): ...@@ -120,10 +120,9 @@ class Recipe(GenericBaseRecipe):
'server_text': server_snippet}, 'server_text': server_snippet},
) )
) )
wrapper_path = self.createPythonScript( wrapper_path = self.createWrapper(
self.options['wrapper-path'], self.options['wrapper-path'],
'slapos.recipe.librecipe.execute.generic_exec', (self.options['binary-path'].strip(), '-f', configuration_path))
((self.options['binary-path'].strip(), '-f', configuration_path),))
ctl_path = self.createPythonScript( ctl_path = self.createPythonScript(
self.options['ctl-path'], self.options['ctl-path'],
__name__ + '.haproxy.haproxyctl', __name__ + '.haproxy.haproxyctl',
......
...@@ -71,13 +71,12 @@ class Recipe(GenericBaseRecipe): ...@@ -71,13 +71,12 @@ class Recipe(GenericBaseRecipe):
) )
path_list.append(httpd_conf) path_list.append(httpd_conf)
wrapper = self.createWrapper(name=self.options['wrapper'], wrapper = self.createWrapper(self.options['wrapper'],
command=self.options['httpd-binary'], (self.options['httpd-binary'],
parameters=[
'-f', '-f',
self.options['httpd-conf'], self.options['httpd-conf'],
'-DFOREGROUND' '-DFOREGROUND'
]) ))
path_list.append(wrapper) path_list.append(wrapper)
......
...@@ -136,34 +136,39 @@ class GenericBaseRecipe(object): ...@@ -136,34 +136,39 @@ class GenericBaseRecipe(object):
[(filename, module, function)], self._ws, sys.executable, [(filename, module, function)], self._ws, sys.executable,
path, arguments=', '.join(args))[0] path, arguments=', '.join(args))[0]
def createWrapper(self, name, command, parameters, environment=None): def createWrapper(self, path, args, env=None, **kw):
""" """Create a wrapper script for process replacement"""
Creates a basic shell script for process replacement. assert args
Takes care of quoting. if kw:
return self.createPythonScript(path,
This must be kept minimal to avoid code duplication with generic_exec. 'slapos.recipe.librecipe.execute.generic_exec',
In particular, do not implement workaround for shebang size limitation here (args, env) if env else (args,), kw)
(note that this can't be done correctly with a POSIX shell, because the
process can't be given a name). # Simple case: creates a basic shell script for process replacement.
""" # This must be kept minimal to avoid code duplication with generic_exec.
lines = [ '#!/bin/sh' ] # In particular, do not implement workaround for shebang size limitation
# here (note that this can't be done correctly with a POSIX shell, because
for key in environment or (): # the process can't be given a name).
lines.append('export %s=%s' % (key, shlex.quote(environment[key])))
lines = ['#!/bin/sh']
lines.append('exec ' + shlex.quote(command))
if env:
parameters = map(shlex.quote, parameters) for k, v in sorted(env.iteritems()):
parameters.append('"$@"') lines.append('export %s=%s' % (k, shlex.quote(v)))
for param in parameters:
lines.append('exec')
args = map(shlex.quote, args)
args.append('"$@"')
for arg in args:
if len(lines[-1]) < 40: if len(lines[-1]) < 40:
lines[-1] += ' ' + param lines[-1] += ' ' + arg
else: else:
lines[-1] += ' \\' lines[-1] += ' \\'
lines.append('\t' + param) lines.append('\t' + arg)
lines.append('') lines.append('')
return self.createFile(name, '\n'.join(lines), 0700) return self.createFile(path, '\n'.join(lines), 0700)
def createDirectory(self, parent, name, mode=0700): def createDirectory(self, parent, name, mode=0700):
path = os.path.join(parent, name) path = os.path.join(parent, name)
......
...@@ -46,11 +46,10 @@ class Recipe(GenericBaseRecipe): ...@@ -46,11 +46,10 @@ class Recipe(GenericBaseRecipe):
state_file = self.options['state-file'] state_file = self.options['state-file']
logrotate = self.createPythonScript( logrotate = self.createWrapper(
self.options['wrapper'], self.options['wrapper'],
'slapos.recipe.librecipe.execute.generic_exec', (self.options['logrotate-binary'],
((self.options['logrotate-binary'], '-s', state_file, logrotate_conf_file),
'-s', state_file, logrotate_conf_file),)
) )
return [logrotate, logrotate_conf_file] return [logrotate, logrotate_conf_file]
......
...@@ -203,11 +203,10 @@ Include conf/extra/httpd-autoindex.conf ...@@ -203,11 +203,10 @@ Include conf/extra/httpd-autoindex.conf
services_dir = self.options['services_dir'] services_dir = self.options['services_dir']
httpd_wrapper = self.createPythonScript( httpd_wrapper = self.createWrapper(
os.path.join(services_dir, 'httpd_wrapper'), os.path.join(services_dir, 'httpd_wrapper'),
'slapos.recipe.librecipe.execute.generic_exec', (self.options['httpd_binary'],
((self.options['httpd_binary'], '-f', self.options['httpd_conf'], '-DFOREGROUND'),
'-f', self.options['httpd_conf'], '-DFOREGROUND'),)
) )
path_list.append(httpd_wrapper) path_list.append(httpd_wrapper)
...@@ -220,19 +219,17 @@ Include conf/extra/httpd-autoindex.conf ...@@ -220,19 +219,17 @@ Include conf/extra/httpd-autoindex.conf
site_perl_bin = os.path.join(self.options['site_perl'], 'bin') site_perl_bin = os.path.join(self.options['site_perl'], 'bin')
mioga_conf_path = os.path.join(mioga_base, 'conf', 'Mioga.conf') mioga_conf_path = os.path.join(mioga_base, 'conf', 'Mioga.conf')
notifier_wrapper = self.createPythonScript( notifier_wrapper = self.createWrapper(
os.path.join(services_dir, 'notifier'), os.path.join(services_dir, 'notifier'),
'slapos.recipe.librecipe.execute.generic_exec', (os.path.join(site_perl_bin, 'notifier.pl'),
((os.path.join(site_perl_bin, 'notifier.pl'), mioga_conf_path),
mioga_conf_path),)
) )
path_list.append(notifier_wrapper) path_list.append(notifier_wrapper)
searchengine_wrapper = self.createPythonScript( searchengine_wrapper = self.createWrapper(
os.path.join(services_dir, 'searchengine'), os.path.join(services_dir, 'searchengine'),
'slapos.recipe.librecipe.execute.generic_exec', (os.path.join(site_perl_bin, 'searchengine.pl'),
((os.path.join(site_perl_bin, 'searchengine.pl'), mioga_conf_path),
mioga_conf_path),)
) )
path_list.append(searchengine_wrapper) path_list.append(searchengine_wrapper)
......
...@@ -53,11 +53,10 @@ class Recipe(GenericBaseRecipe): ...@@ -53,11 +53,10 @@ class Recipe(GenericBaseRecipe):
mysql_binary = self.options['mysql-binary'] mysql_binary = self.options['mysql-binary']
socket = self.options['socket'], socket = self.options['socket'],
post_rotate = self.createPythonScript( post_rotate = self.createWrapper(
self.options['logrotate-post'], self.options['logrotate-post'],
'slapos.recipe.librecipe.execute.generic_exec', (mysql_binary, '--no-defaults', '-B', '-u', 'root',
((mysql_binary, '--no-defaults', '-B', '-u', 'root', '--socket=%s' % socket, '-e', 'FLUSH LOGS'),
'--socket=%s' % socket, '-e', 'FLUSH LOGS'),)
) )
path_list.append(post_rotate) path_list.append(post_rotate)
......
...@@ -42,7 +42,8 @@ class NeoBaseRecipe(GenericBaseRecipe): ...@@ -42,7 +42,8 @@ class NeoBaseRecipe(GenericBaseRecipe):
# Only then can this recipe start succeeding and actually doing anything # Only then can this recipe start succeeding and actually doing anything
# useful, as per NEO deploying constraints. # useful, as per NEO deploying constraints.
raise UserError('"masters" parameter is mandatory') raise UserError('"masters" parameter is mandatory')
option_list = [ args = [
options['binary'],
# Keep the -l option first, as expected by logrotate snippets. # Keep the -l option first, as expected by logrotate snippets.
'-l', options['logfile'], '-l', options['logfile'],
'-m', options['masters'], '-m', options['masters'],
...@@ -53,17 +54,13 @@ class NeoBaseRecipe(GenericBaseRecipe): ...@@ -53,17 +54,13 @@ class NeoBaseRecipe(GenericBaseRecipe):
] ]
if options['ssl']: if options['ssl']:
etc = os.path.join(self.buildout['buildout']['directory'], 'etc', '') etc = os.path.join(self.buildout['buildout']['directory'], 'etc', '')
option_list += ( args += (
'--ca', etc + 'ca.crt', '--ca', etc + 'ca.crt',
'--cert', etc + 'neo.crt', '--cert', etc + 'neo.crt',
'--key', etc + 'neo.key', '--key', etc + 'neo.key',
) )
option_list.extend(self._getOptionList()) args += self._getOptionList()
return [self.createWrapper( return self.createWrapper(options['wrapper'], args)
options['wrapper'],
options['binary'],
option_list
)]
def _getBindingAddress(self): def _getBindingAddress(self):
options = self.options options = self.options
......
...@@ -33,16 +33,14 @@ class Recipe(GenericBaseRecipe): ...@@ -33,16 +33,14 @@ class Recipe(GenericBaseRecipe):
def install(self): def install(self):
options = self.options options = self.options
# Script that execute the callback(s) upon receiving a notification. # Script that execute the callback(s) upon receiving a notification.
script = self.createWrapper(name=options['wrapper'], return self.createWrapper(options['wrapper'],
command=options['server-binary'], (options['server-binary'],
parameters=[
'--callbacks', options['callbacks'], '--callbacks', options['callbacks'],
'--feeds', options['feeds'], '--feeds', options['feeds'],
'--equeue-socket', options['equeue-socket'], '--equeue-socket', options['equeue-socket'],
options['host'], options['port'] options['host'], options['port']
], ),
) )
return [script]
class Callback(GenericBaseRecipe): class Callback(GenericBaseRecipe):
...@@ -98,16 +96,12 @@ class Notify(GenericBaseRecipe): ...@@ -98,16 +96,12 @@ class Notify(GenericBaseRecipe):
'--status-item-directory', status_item_directory, '--status-item-directory', status_item_directory,
) )
kw = {}
if pidfile: if pidfile:
return self.createPythonScript(wrapper, kw['pidfile'] = pidfile
'slapos.recipe.librecipe.execute.generic_exec',
(cmd,), {'pidfile': pidfile})
# Script that call an executable and send notification(s). # Script that call an executable and send notification(s).
return self.createWrapper(name=wrapper, return self.createWrapper(wrapper, cmd, **kw)
command=cmd[0],
parameters=cmd[1:],
)
def install(self): def install(self):
......
...@@ -35,10 +35,9 @@ class Recipe(GenericBaseRecipe): ...@@ -35,10 +35,9 @@ class Recipe(GenericBaseRecipe):
""" """
def install(self): def install(self):
return self.createPythonScript( return self.createWrapper(
self.options['path'], self.options['path'],
'slapos.recipe.librecipe.execute.generic_exec', (
((
self.options['websockify-path'], self.options['websockify-path'],
'--web', '--web',
self.options['novnc-location'], self.options['novnc-location'],
...@@ -47,7 +46,7 @@ class Recipe(GenericBaseRecipe): ...@@ -47,7 +46,7 @@ class Recipe(GenericBaseRecipe):
'--ssl-only', '--ssl-only',
'%s:%s' % (self.options['ip'], self.options['port']), '%s:%s' % (self.options['ip'], self.options['port']),
'%s:%s' % (self.options['vnc-ip'], self.options['vnc-port']), '%s:%s' % (self.options['vnc-ip'], self.options['vnc-port']),
),), ),
{'wait_list': (self.options['ssl-key-path'], wait_list=(self.options['ssl-key-path'],
self.options['ssl-cert-path'])}, self.options['ssl-cert-path']),
) )
...@@ -320,12 +320,11 @@ class Recipe(GenericSlapRecipe, Notify, Callback): ...@@ -320,12 +320,11 @@ class Recipe(GenericSlapRecipe, Notify, Callback):
else: else:
self.logger.info("Server mode") self.logger.info("Server mode")
wrapper = self.createWrapper(name=self.options['wrapper'], wrapper = self.createWrapper(self.options['wrapper'],
command=self.options['rdiffbackup-binary'], (self.options['rdiffbackup-binary'],
parameters=[
'--restrict', self.options['path'], '--restrict', self.options['path'],
'--server' '--server'
]) ))
path_list.append(wrapper) path_list.append(wrapper)
return path_list return path_list
...@@ -56,10 +56,9 @@ class Recipe(GenericBaseRecipe): ...@@ -56,10 +56,9 @@ class Recipe(GenericBaseRecipe):
configuration)) configuration))
path_list.append(config) path_list.append(config)
redis = self.createPythonScript( redis = self.createWrapper(
self.options['wrapper'], self.options['wrapper'],
'slapos.recipe.librecipe.execute.generic_exec', (self.options['server_bin'], config_file),
((self.options['server_bin'], config_file),)
) )
path_list.append(redis) path_list.append(redis)
......
...@@ -70,14 +70,12 @@ class Recipe(GenericSlapRecipe): ...@@ -70,14 +70,12 @@ class Recipe(GenericSlapRecipe):
path_list.append(nginx_configuration_file) path_list.append(nginx_configuration_file)
# Generate Nginx wrapper # Generate Nginx wrapper
wrapper = self.createWrapper( path_list.append(self.createWrapper(
name=self.options['wrapper'], self.options['wrapper'],
command=self.options['nginx-executable'], (self.options['nginx-executable'],
parameters=[
'-c', self.options['configuration-file'], '-c', self.options['configuration-file'],
'-p', self.options['home-directory'] '-p', self.options['home-directory']
] )))
)
# TODO: reload configuration or have feature like apache_map # TODO: reload configuration or have feature like apache_map
......
...@@ -32,14 +32,11 @@ class Recipe(GenericBaseRecipe): ...@@ -32,14 +32,11 @@ class Recipe(GenericBaseRecipe):
def install(self): def install(self):
ps1 = self.options.get('ps1') ps1 = self.options.get('ps1')
shell = self.options['shell']
env = { env = {
'HOME': self.options['home'], 'HOME': self.options['home'],
'PATH': ':'.join(self.options['path'].split('\n')), 'PATH': ':'.join(self.options['path'].split('\n')),
'PS1': str(json.loads(ps1)) if ps1 else os.getenv('PS1', '> '), 'PS1': str(json.loads(ps1)) if ps1 else os.getenv('PS1', '> '),
'SHELL': self.options['shell'], 'SHELL': shell,
} }
return self.createPythonScript( return self.createWrapper(self.options['wrapper'], (shell,), env)
self.options['wrapper'],
'slapos.recipe.librecipe.execute.generic_exec',
((self.options['shell'],), env),
)
...@@ -48,11 +48,10 @@ class Recipe(GenericBaseRecipe): ...@@ -48,11 +48,10 @@ class Recipe(GenericBaseRecipe):
) )
# Create init script # Create init script
wrapper = self.createPythonScript( wrapper = self.createWrapper(
self.options['wrapper'], self.options['wrapper'],
'slapos.recipe.librecipe.execute.generic_exec', (self.options['sphinx-searchd-binary'].strip(), '-c',
((self.options['sphinx-searchd-binary'].strip(), '-c', sphinx_conf_path, '--nodetach'),
sphinx_conf_path, '--nodetach'),),
) )
return [wrapper, sphinx_conf_path] return [wrapper, sphinx_conf_path]
...@@ -78,17 +78,15 @@ class Recipe(GenericBaseRecipe): ...@@ -78,17 +78,15 @@ class Recipe(GenericBaseRecipe):
self.substituteTemplate(template_filename, config)) self.substituteTemplate(template_filename, config))
# Prepare directories # Prepare directories
prepare_path = self.createPythonScript( prepare_path = self.createWrapper(
self.options['prepare-path'], self.options['prepare-path'],
'slapos.recipe.librecipe.execute.generic_exec', (self.options['binary-path'].strip(),
((self.options['binary-path'].strip(), '-z', '-f', configuration_path))
'-z', '-f', configuration_path),))
# Create running wrapper # Create running wrapper
wrapper_path = self.createPythonScript( wrapper_path = self.createWrapper(
self.options['wrapper-path'], self.options['wrapper-path'],
'slapos.recipe.librecipe.execute.generic_exec', (self.options['binary-path'].strip(),
((self.options['binary-path'].strip(), '-N', '-f', configuration_path))
'-N', '-f', configuration_path),))
return [configuration_path, wrapper_path, prepare_path] return [configuration_path, wrapper_path, prepare_path]
...@@ -152,10 +152,9 @@ class Request(GenericBaseRecipe): ...@@ -152,10 +152,9 @@ class Request(GenericBaseRecipe):
os.symlink(self.private_key, private_key_link) os.symlink(self.private_key, private_key_link)
# end-XXX # end-XXX
wrapper = self.createPythonScript( wrapper = self.createWrapper(
self.options['wrapper'], self.options['wrapper'],
'slapos.recipe.librecipe.execute.generic_exec', (self.options['executable'],),
((self.options['executable'],),), wait_list=(self.private_key, self.public_key))
{'wait_list': (self.private_key, self.public_key)})
return [request_file, wrapper, public_key_link, private_key_link] return [request_file, wrapper, public_key_link, private_key_link]
...@@ -79,10 +79,9 @@ class Recipe(GenericBaseRecipe): ...@@ -79,10 +79,9 @@ class Recipe(GenericBaseRecipe):
self.substituteTemplate(template, conf)) self.substituteTemplate(template, conf))
path_list.append(conf_file) path_list.append(conf_file)
wrapper = self.createPythonScript( wrapper = self.createWrapper(
self.options['wrapper'], self.options['wrapper'],
'slapos.recipe.librecipe.execute.generic_exec', (self.options['stunnel-binary'], conf_file),
((self.options['stunnel-binary'], conf_file),)
) )
path_list.append(wrapper) path_list.append(wrapper)
......
...@@ -36,19 +36,17 @@ class Recipe(GenericBaseRecipe): ...@@ -36,19 +36,17 @@ class Recipe(GenericBaseRecipe):
r = [configuration_file] r = [configuration_file]
wrapper = self.options.get('tidstorage-wrapper') wrapper = self.options.get('tidstorage-wrapper')
wrapper and r.append(self.createPythonScript(wrapper, wrapper and r.append(self.createWrapper(wrapper,
'slapos.recipe.librecipe.execute.generic_exec', (self.options['tidstoraged-binary'],
((self.options['tidstoraged-binary'], '--nofork', '--config', configuration_file)))
'--nofork', '--config', configuration_file),)))
r.append(self.createPythonScript( r.append(self.createWrapper(
self.options['repozo-wrapper'], self.options['repozo-wrapper'],
'slapos.recipe.librecipe.execute.generic_exec', (self.options['tidstorage-repozo-binary'],
((self.options['tidstorage-repozo-binary'],
'--config', configuration_file, '--config', configuration_file,
'--repozo', self.options['repozo-binary'], '--repozo', self.options['repozo-binary'],
'--gzip', '--gzip',
'--quick', '--quick',
),))) )))
return r return r
...@@ -40,7 +40,7 @@ class Recipe(GenericBaseRecipe): ...@@ -40,7 +40,7 @@ class Recipe(GenericBaseRecipe):
:param bool reserve-cpu: command will ask for an exclusive CPU core :param bool reserve-cpu: command will ask for an exclusive CPU core
""" """
def install(self): def install(self):
command_line = shlex.split(self.options['command-line']) args = shlex.split(self.options['command-line'])
wrapper_path = self.options['wrapper-path'] wrapper_path = self.options['wrapper-path']
wait_files = self.options.get('wait-for-files') wait_files = self.options.get('wait-for-files')
pidfile = self.options.get('pidfile') pidfile = self.options.get('pidfile')
...@@ -60,17 +60,4 @@ class Recipe(GenericBaseRecipe): ...@@ -60,17 +60,4 @@ class Recipe(GenericBaseRecipe):
if self.isTrueValue(self.options.get('reserve-cpu')): if self.isTrueValue(self.options.get('reserve-cpu')):
kw['reserve_cpu'] = True kw['reserve_cpu'] = True
if kw: return self.createWrapper(wrapper_path, args, environment, **kw)
# More complex needs: create a Python script as wrapper
args = [command_line]
if environment:
args.append(environment)
return self.createPythonScript(wrapper_path,
'slapos.recipe.librecipe.execute.generic_exec',
args, kw)
return self.createWrapper(wrapper_path,
command_line[0],
command_line[1:],
environment=environment)
...@@ -89,10 +89,9 @@ class Recipe(GenericBaseRecipe): ...@@ -89,10 +89,9 @@ class Recipe(GenericBaseRecipe):
self.substituteTemplate(template_filename, config)) self.substituteTemplate(template_filename, config))
# Create running wrapper # Create running wrapper
wrapper_path = self.createPythonScript( wrapper_path = self.createWrapper(
self.options['wrapper-path'], self.options['wrapper-path'],
'slapos.recipe.librecipe.execute.generic_exec', (self.options['binary-path'].strip(),
((self.options['binary-path'].strip(), '-C', self.options['conf-path']))
'-C', self.options['conf-path']),))
return [configuration_path, wrapper_path] return [configuration_path, wrapper_path]
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