From 411212fb650b6537f4b4e5291389cc1203ae5750 Mon Sep 17 00:00:00 2001 From: Julien Muchembled <jm@nexedi.com> Date: Mon, 12 Feb 2018 18:57:10 +0100 Subject: [PATCH] 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. --- slapos/recipe/apacheperl/__init__.py | 7 ++- slapos/recipe/apachephp/__init__.py | 9 ++-- slapos/recipe/apacheproxy/__init__.py | 7 ++- slapos/recipe/boinc/__init__.py | 12 ++--- slapos/recipe/bonjourgrid/__init__.py | 14 +++-- .../recipe/certificate_authority/__init__.py | 7 ++- slapos/recipe/cloud9/__init__.py | 5 +- slapos/recipe/davstorage/__init__.py | 5 +- slapos/recipe/dcron.py | 7 ++- slapos/recipe/dropbear.py | 12 +---- slapos/recipe/duplicity.py | 3 +- slapos/recipe/equeue.py | 17 +++---- slapos/recipe/erp5testnode/__init__.py | 12 ++--- slapos/recipe/generic_mysql/__init__.py | 15 +++--- slapos/recipe/haproxy/__init__.py | 5 +- slapos/recipe/lampgeneric/__init__.py | 7 ++- slapos/recipe/librecipe/generic.py | 51 ++++++++++--------- slapos/recipe/logrotate.py | 7 ++- slapos/recipe/mioga/instantiate.py | 21 ++++---- slapos/recipe/mysql/__init__.py | 7 ++- slapos/recipe/neoppod.py | 13 ++--- slapos/recipe/notifier.py | 18 +++---- slapos/recipe/novnc/__init__.py | 11 ++-- slapos/recipe/pbs.py | 7 ++- slapos/recipe/redis/__init__.py | 5 +- slapos/recipe/reverse_proxy_nginx/__init__.py | 10 ++-- slapos/recipe/shell.py | 9 ++-- slapos/recipe/sphinx/__init__.py | 7 ++- slapos/recipe/squid/__init__.py | 14 +++-- slapos/recipe/sshkeys_authority.py | 7 ++- slapos/recipe/stunnel/__init__.py | 5 +- slapos/recipe/tidstorage/__init__.py | 14 +++-- slapos/recipe/wrapper.py | 17 +------ slapos/recipe/zeo/__init__.py | 7 ++- 34 files changed, 151 insertions(+), 223 deletions(-) diff --git a/slapos/recipe/apacheperl/__init__.py b/slapos/recipe/apacheperl/__init__.py index fe5d06dd5..36b38bc5b 100644 --- a/slapos/recipe/apacheperl/__init__.py +++ b/slapos/recipe/apacheperl/__init__.py @@ -57,10 +57,9 @@ class Recipe(GenericBaseRecipe): ) path_list.append(httpd_conf) - wrapper = self.createPythonScript(self.options['wrapper'], - 'slapos.recipe.librecipe.execute.generic_exec', - ((self.options['httpd-binary'], '-f', self.options['httpd-conf'], - '-DFOREGROUND'),) + wrapper = self.createWrapper(self.options['wrapper'], + (self.options['httpd-binary'], '-f', self.options['httpd-conf'], + '-DFOREGROUND'), ) path_list.append(wrapper) diff --git a/slapos/recipe/apachephp/__init__.py b/slapos/recipe/apachephp/__init__.py index 670dcd4f5..2a701f865 100644 --- a/slapos/recipe/apachephp/__init__.py +++ b/slapos/recipe/apachephp/__init__.py @@ -92,14 +92,13 @@ class Recipe(GenericBaseRecipe): ) path_list.append(httpd_conf) - wrapper = self.createWrapper(name=self.options['wrapper'], - command=self.options['httpd-binary'], - parameters=[ + wrapper = self.createWrapper(self.options['wrapper'], + (self.options['httpd-binary'], '-f', self.options['httpd-conf'], '-DFOREGROUND' - ], - environment=self.environ) + ), + self.environ) path_list.append(wrapper) secret_key_filename = os.path.join(self.buildout['buildout']['directory'], diff --git a/slapos/recipe/apacheproxy/__init__.py b/slapos/recipe/apacheproxy/__init__.py index 0d6b35286..4c9a019ff 100644 --- a/slapos/recipe/apacheproxy/__init__.py +++ b/slapos/recipe/apacheproxy/__init__.py @@ -49,13 +49,12 @@ class Recipe(GenericBaseRecipe): ) path_list.append(httpd_conf) - wrapper = self.createWrapper(name=self.options['wrapper'], - command=self.options['httpd-binary'], - parameters=[ + wrapper = self.createWrapper(self.options['wrapper'], + (self.options['httpd-binary'], '-f', self.options['httpd-conf'], '-DFOREGROUND', - ]) + )) path_list.append(wrapper) diff --git a/slapos/recipe/boinc/__init__.py b/slapos/recipe/boinc/__init__.py index 0cedf1594..7f79accf1 100644 --- a/slapos/recipe/boinc/__init__.py +++ b/slapos/recipe/boinc/__init__.py @@ -124,9 +124,8 @@ class Recipe(GenericBaseRecipe): #Generate wrapper for php wrapperphp = os.path.join(self.home, 'bin/php') - php_wrapper = self.createPythonScript(wrapperphp, - 'slapos.recipe.librecipe.execute.generic_exec', - ((self.phpbin, '-c', self.phpini),) + php_wrapper = self.createWrapper(wrapperphp, + (self.phpbin, '-c', self.phpini), ) path_list.append(php_wrapper) @@ -406,11 +405,10 @@ class Client(GenericBaseRecipe): path_list.append(cmd) #Generate BOINC client wrapper - boinc = self.createPythonScript(boinc_wrapper, - 'slapos.recipe.librecipe.execute.generic_exec', - ((boincbin, '--allow_multiple_clients', '--gui_rpc_port', + boinc = self.createWrapper(boinc_wrapper, + (boincbin, '--allow_multiple_clients', '--gui_rpc_port', 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) diff --git a/slapos/recipe/bonjourgrid/__init__.py b/slapos/recipe/bonjourgrid/__init__.py index 5fcb965fa..0664a332e 100644 --- a/slapos/recipe/bonjourgrid/__init__.py +++ b/slapos/recipe/bonjourgrid/__init__.py @@ -73,16 +73,15 @@ class Recipe(GenericBaseRecipe): bg_wrapper = self.options['wrapper'].strip() log = self.options['log_file'].strip() pid_file = self.options['pid_file'].strip() - wrapper = self.createPythonScript(bg_wrapper, - 'slapos.recipe.librecipe.execute.generic_exec', - ((python, bonjourgrid_master, '--log_file', log, + wrapper = self.createWrapper(bg_wrapper, + (python, bonjourgrid_master, '--log_file', log, '--pid_file', pid_file, '--master_wrapper', grid_wrapper, '--directory', self.options['work_dir'].strip(), '--server', self.options['redis-url'].strip(), '--port', self.options['redis-port'].strip(), '--num_workers', self.options['nworkers'].strip(), - ),) + ), ) path_list.append(wrapper) @@ -113,9 +112,8 @@ class Client(GenericBaseRecipe): bg_wrapper = self.options['wrapper'].strip() log = self.options['log_file'].strip() pid_file = self.options['pid_file'].strip() - wrapper = self.createPythonScript(bg_wrapper, - 'slapos.recipe.librecipe.execute.generic_exec', - ((python, bonjourgrid_client, '--log_file', log, + wrapper = self.createWrapper(bg_wrapper, + (python, bonjourgrid_client, '--log_file', log, '--pid_file', pid_file, '--boinc_wrapper', boinc_script, '--condor_wrapper', condor_script, @@ -123,7 +121,7 @@ class Client(GenericBaseRecipe): '--install_directory', self.options['install_dir'].strip(), '--server', self.options['redis-url'].strip(), '--port', self.options['redis-port'].strip(), - ),) + ), ) path_list.append(wrapper) diff --git a/slapos/recipe/certificate_authority/__init__.py b/slapos/recipe/certificate_authority/__init__.py index 76ee32957..14a66cf92 100644 --- a/slapos/recipe/certificate_authority/__init__.py +++ b/slapos/recipe/certificate_authority/__init__.py @@ -137,11 +137,10 @@ class Request(Recipe): path_list = [key_file, cert_file] if request_needed: - wrapper = self.createPythonScript( + wrapper = self.createWrapper( self.options['wrapper'], - 'slapos.recipe.librecipe.execute.generic_exec', - ((self.options['executable'],),), - {'wait_list': (certificate, key)}, + (self.options['executable'],), + wait_list=(certificate, key), ) path_list.append(wrapper) diff --git a/slapos/recipe/cloud9/__init__.py b/slapos/recipe/cloud9/__init__.py index 09a0bc7c6..2135aec95 100644 --- a/slapos/recipe/cloud9/__init__.py +++ b/slapos/recipe/cloud9/__init__.py @@ -49,7 +49,4 @@ class Recipe(GenericBaseRecipe): cloud9_args = [self.node_executable, self.cloud9, '-l', self.ip, '-p', self.port, '-w', self.workdir] - return self.createPythonScript(self.wrapper, - 'slapos.recipe.librecipe.execute.generic_exec', - (cloud9_args, environment) - ) + return self.createWrapper(self.wrapper, cloud9_args, environment) diff --git a/slapos/recipe/davstorage/__init__.py b/slapos/recipe/davstorage/__init__.py index 1b956909f..64b0e41e2 100644 --- a/slapos/recipe/davstorage/__init__.py +++ b/slapos/recipe/davstorage/__init__.py @@ -98,9 +98,8 @@ class Recipe(GenericBaseRecipe): ) path_list.append(config_file) - wrapper = self.createPythonScript(self.options['wrapper'], - 'slapos.recipe.librecipe.execute.generic_exec', - ((self.options['apache-binary'], '-f', config_file, '-DFOREGROUND'),)) + wrapper = self.createWrapper(self.options['wrapper'], + (self.options['apache-binary'], '-f', config_file, '-DFOREGROUND')) path_list.append(wrapper) promise = self.createPythonScript(self.options['promise'], diff --git a/slapos/recipe/dcron.py b/slapos/recipe/dcron.py index e274cc486..0478448f3 100644 --- a/slapos/recipe/dcron.py +++ b/slapos/recipe/dcron.py @@ -35,15 +35,14 @@ class Recipe(GenericBaseRecipe): self.logger.info("Installing dcron...") options = self.options - script = self.createWrapper(name=options['binary'], - command=options['dcrond-binary'].strip(), - parameters=[ + script = self.createWrapper(options['binary'], + (options['dcrond-binary'].strip(), '-s', options['cron-entries'], '-c', options['crontabs'], '-t', options['cronstamps'], '-f', '-l', '5', '-M', options['catcher'] - ]) + )) self.logger.debug('Main cron executable created at : %r', script) diff --git a/slapos/recipe/dropbear.py b/slapos/recipe/dropbear.py index be53710cc..53a7db3d0 100644 --- a/slapos/recipe/dropbear.py +++ b/slapos/recipe/dropbear.py @@ -93,11 +93,7 @@ class Recipe(GenericBaseRecipe): if 'shell' in self.options: env['DROPBEAR_OVERRIDE_SHELL'] = self.options['shell'] - return self.createPythonScript( - self.options['wrapper'], - 'slapos.recipe.librecipe.execute.generic_exec', - (dropbear_cmd, env) - ) + return self.createWrapper(self.options['wrapper'], dropbear_cmd, env) class Client(GenericBaseRecipe): @@ -115,11 +111,7 @@ class Client(GenericBaseRecipe): if 'identity-file' in self.options: dropbear_cmd.extend(['-i', self.options['identity-file']]) - return self.createPythonScript( - self.options['wrapper'], - 'slapos.recipe.librecipe.execute.generic_exec', - (dropbear_cmd, env) - ) + return self.createWrapper(self.options['wrapper'], dropbear_cmd, env) class AddAuthorizedKey(GenericBaseRecipe): diff --git a/slapos/recipe/duplicity.py b/slapos/recipe/duplicity.py index fc3eaceac..1fc97c5ca 100644 --- a/slapos/recipe/duplicity.py +++ b/slapos/recipe/duplicity.py @@ -46,5 +46,4 @@ class Recipe(GenericBaseRecipe): cmd.extend(options) cmd.extend([backup_directory, remote_url]) - return self.createPythonScript(self.options['wrapper'], - 'slapos.recipe.librecipe.execute.generic_exec', (cmd,)) + return self.createWrapper(self.options['wrapper'], cmd) diff --git a/slapos/recipe/equeue.py b/slapos/recipe/equeue.py index fb3f1fe11..8a7221bf1 100644 --- a/slapos/recipe/equeue.py +++ b/slapos/recipe/equeue.py @@ -30,23 +30,20 @@ class Recipe(GenericBaseRecipe): def install(self): - parameters = [ + args = [ + self.options['equeue-binary'], '--database', self.options['database'], '--logfile', self.options['log'], '--lockfile', self.options['lockfile'] ] 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: - parameters.extend(['--loglevel', self.options['loglevel']]) + args += '--loglevel', self.options['loglevel'] - parameters.append(self.options['socket']) - - wrapper = self.createWrapper(name=self.options['wrapper'], - command=self.options['equeue-binary'], - parameters=parameters) - - return [wrapper] + args.append(self.options['socket']) + return self.createWrapper(self.options['wrapper'], args) diff --git a/slapos/recipe/erp5testnode/__init__.py b/slapos/recipe/erp5testnode/__init__.py index c70a2f219..c556a2b28 100644 --- a/slapos/recipe/erp5testnode/__init__.py +++ b/slapos/recipe/erp5testnode/__init__.py @@ -68,17 +68,14 @@ class Recipe(GenericBaseRecipe): ) self.path_list.append(configuration_file) self.path_list.append( - self.createPythonScript( - self.options['wrapper'], - 'slapos.recipe.librecipe.execute.generic_exec', - ( # Command + self.createWrapper(self.options['wrapper'], + # Command ( self.options['testnode'], '-l', self.options['log-file'], configuration_file), # Environment { 'GIT_SSL_NO_VERIFY': '1', } - ), ) ) self.installApache() @@ -106,9 +103,8 @@ class Recipe(GenericBaseRecipe): apache_config) ) self.path_list.append(config_file) - wrapper = self.createPythonScript(self.options['httpd-wrapper'], - 'slapos.recipe.librecipe.execute.generic_exec', - ((self.options['apache-binary'], '-f', config_file, '-DFOREGROUND'),)) + wrapper = self.createWrapper(self.options['httpd-wrapper'], + (self.options['apache-binary'], '-f', config_file, '-DFOREGROUND')) self.path_list.append(wrapper) # create empty html page to not allow listing of / page = open(os.path.join(self.options['log-directory'], "index.html"), "w") diff --git a/slapos/recipe/generic_mysql/__init__.py b/slapos/recipe/generic_mysql/__init__.py index 30e1772d2..16cd9f676 100644 --- a/slapos/recipe/generic_mysql/__init__.py +++ b/slapos/recipe/generic_mysql/__init__.py @@ -165,15 +165,13 @@ class Recipe(GenericBaseRecipe): '--defaults-file=%s' % mysql_conf_file, '--socket=%s' % socket.strip(), '--user=root', '--ibbackup=%s'% self.options['xtrabackup-binary']] - innobackupex_incremental = self.createPythonScript( + innobackupex_incremental = self.createWrapper( 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) - innobackupex_full = self.createPythonScript( + innobackupex_full = self.createWrapper( self.options['innobackupex-full'], - 'slapos.recipe.librecipe.execute.generic_exec', - (innobackupex_argument_list, environment)) + innobackupex_argument_list, environment) path_list.append(innobackupex_full) backup_controller = self.createPythonScript(self.options['backup-script'], __name__ + '.innobackupex.controller', [innobackupex_incremental, innobackupex_full, full_backup, incremental_backup]) path_list.append(backup_controller) @@ -221,10 +219,9 @@ class Recipe(GenericBaseRecipe): '--defaults-file=%s' % mysql_conf_file, '--socket=%s' % socket.strip(), '--user=root', ] - pt_exe = self.createPythonScript( + pt_exe = self.createWrapper( 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) return path_list diff --git a/slapos/recipe/haproxy/__init__.py b/slapos/recipe/haproxy/__init__.py index b80673e75..50b6d718c 100644 --- a/slapos/recipe/haproxy/__init__.py +++ b/slapos/recipe/haproxy/__init__.py @@ -120,10 +120,9 @@ class Recipe(GenericBaseRecipe): 'server_text': server_snippet}, ) ) - wrapper_path = self.createPythonScript( + wrapper_path = self.createWrapper( 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( self.options['ctl-path'], __name__ + '.haproxy.haproxyctl', diff --git a/slapos/recipe/lampgeneric/__init__.py b/slapos/recipe/lampgeneric/__init__.py index 662f70bf1..695a72c4d 100644 --- a/slapos/recipe/lampgeneric/__init__.py +++ b/slapos/recipe/lampgeneric/__init__.py @@ -71,13 +71,12 @@ class Recipe(GenericBaseRecipe): ) path_list.append(httpd_conf) - wrapper = self.createWrapper(name=self.options['wrapper'], - command=self.options['httpd-binary'], - parameters=[ + wrapper = self.createWrapper(self.options['wrapper'], + (self.options['httpd-binary'], '-f', self.options['httpd-conf'], '-DFOREGROUND' - ]) + )) path_list.append(wrapper) diff --git a/slapos/recipe/librecipe/generic.py b/slapos/recipe/librecipe/generic.py index 4556d782b..cf2af11d8 100644 --- a/slapos/recipe/librecipe/generic.py +++ b/slapos/recipe/librecipe/generic.py @@ -136,34 +136,39 @@ class GenericBaseRecipe(object): [(filename, module, function)], self._ws, sys.executable, path, arguments=', '.join(args))[0] - def createWrapper(self, name, command, parameters, environment=None): - """ - Creates a basic shell script for process replacement. - Takes care of quoting. - - This must be kept minimal to avoid code duplication with generic_exec. - In particular, do not implement workaround for shebang size limitation here - (note that this can't be done correctly with a POSIX shell, because the - process can't be given a name). - """ - lines = [ '#!/bin/sh' ] - - for key in environment or (): - lines.append('export %s=%s' % (key, shlex.quote(environment[key]))) - - lines.append('exec ' + shlex.quote(command)) - - parameters = map(shlex.quote, parameters) - parameters.append('"$@"') - for param in parameters: + def createWrapper(self, path, args, env=None, **kw): + """Create a wrapper script for process replacement""" + assert args + if kw: + return self.createPythonScript(path, + 'slapos.recipe.librecipe.execute.generic_exec', + (args, env) if env else (args,), kw) + + # Simple case: creates a basic shell script for process replacement. + # This must be kept minimal to avoid code duplication with generic_exec. + # In particular, do not implement workaround for shebang size limitation + # here (note that this can't be done correctly with a POSIX shell, because + # the process can't be given a name). + + lines = ['#!/bin/sh'] + + if env: + for k, v in sorted(env.iteritems()): + lines.append('export %s=%s' % (k, shlex.quote(v))) + + lines.append('exec') + + args = map(shlex.quote, args) + args.append('"$@"') + for arg in args: if len(lines[-1]) < 40: - lines[-1] += ' ' + param + lines[-1] += ' ' + arg else: lines[-1] += ' \\' - lines.append('\t' + param) + lines.append('\t' + arg) 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): path = os.path.join(parent, name) diff --git a/slapos/recipe/logrotate.py b/slapos/recipe/logrotate.py index c9f013d4f..fdfc09655 100644 --- a/slapos/recipe/logrotate.py +++ b/slapos/recipe/logrotate.py @@ -46,11 +46,10 @@ class Recipe(GenericBaseRecipe): state_file = self.options['state-file'] - logrotate = self.createPythonScript( + logrotate = self.createWrapper( self.options['wrapper'], - 'slapos.recipe.librecipe.execute.generic_exec', - ((self.options['logrotate-binary'], - '-s', state_file, logrotate_conf_file),) + (self.options['logrotate-binary'], + '-s', state_file, logrotate_conf_file), ) return [logrotate, logrotate_conf_file] diff --git a/slapos/recipe/mioga/instantiate.py b/slapos/recipe/mioga/instantiate.py index a0978325a..13a4ec8ce 100644 --- a/slapos/recipe/mioga/instantiate.py +++ b/slapos/recipe/mioga/instantiate.py @@ -203,11 +203,10 @@ Include conf/extra/httpd-autoindex.conf services_dir = self.options['services_dir'] - httpd_wrapper = self.createPythonScript( + httpd_wrapper = self.createWrapper( os.path.join(services_dir, 'httpd_wrapper'), - 'slapos.recipe.librecipe.execute.generic_exec', - ((self.options['httpd_binary'], - '-f', self.options['httpd_conf'], '-DFOREGROUND'),) + (self.options['httpd_binary'], + '-f', self.options['httpd_conf'], '-DFOREGROUND'), ) path_list.append(httpd_wrapper) @@ -220,19 +219,17 @@ Include conf/extra/httpd-autoindex.conf site_perl_bin = os.path.join(self.options['site_perl'], 'bin') 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'), - 'slapos.recipe.librecipe.execute.generic_exec', - ((os.path.join(site_perl_bin, 'notifier.pl'), - mioga_conf_path),) + (os.path.join(site_perl_bin, 'notifier.pl'), + mioga_conf_path), ) path_list.append(notifier_wrapper) - searchengine_wrapper = self.createPythonScript( + searchengine_wrapper = self.createWrapper( os.path.join(services_dir, 'searchengine'), - 'slapos.recipe.librecipe.execute.generic_exec', - ((os.path.join(site_perl_bin, 'searchengine.pl'), - mioga_conf_path),) + (os.path.join(site_perl_bin, 'searchengine.pl'), + mioga_conf_path), ) path_list.append(searchengine_wrapper) diff --git a/slapos/recipe/mysql/__init__.py b/slapos/recipe/mysql/__init__.py index 6b962f323..a83cc50a2 100644 --- a/slapos/recipe/mysql/__init__.py +++ b/slapos/recipe/mysql/__init__.py @@ -53,11 +53,10 @@ class Recipe(GenericBaseRecipe): mysql_binary = self.options['mysql-binary'] socket = self.options['socket'], - post_rotate = self.createPythonScript( + post_rotate = self.createWrapper( self.options['logrotate-post'], - 'slapos.recipe.librecipe.execute.generic_exec', - ((mysql_binary, '--no-defaults', '-B', '-u', 'root', - '--socket=%s' % socket, '-e', 'FLUSH LOGS'),) + (mysql_binary, '--no-defaults', '-B', '-u', 'root', + '--socket=%s' % socket, '-e', 'FLUSH LOGS'), ) path_list.append(post_rotate) diff --git a/slapos/recipe/neoppod.py b/slapos/recipe/neoppod.py index a277945e8..4c0bcf521 100644 --- a/slapos/recipe/neoppod.py +++ b/slapos/recipe/neoppod.py @@ -42,7 +42,8 @@ class NeoBaseRecipe(GenericBaseRecipe): # Only then can this recipe start succeeding and actually doing anything # useful, as per NEO deploying constraints. raise UserError('"masters" parameter is mandatory') - option_list = [ + args = [ + options['binary'], # Keep the -l option first, as expected by logrotate snippets. '-l', options['logfile'], '-m', options['masters'], @@ -53,17 +54,13 @@ class NeoBaseRecipe(GenericBaseRecipe): ] if options['ssl']: etc = os.path.join(self.buildout['buildout']['directory'], 'etc', '') - option_list += ( + args += ( '--ca', etc + 'ca.crt', '--cert', etc + 'neo.crt', '--key', etc + 'neo.key', ) - option_list.extend(self._getOptionList()) - return [self.createWrapper( - options['wrapper'], - options['binary'], - option_list - )] + args += self._getOptionList() + return self.createWrapper(options['wrapper'], args) def _getBindingAddress(self): options = self.options diff --git a/slapos/recipe/notifier.py b/slapos/recipe/notifier.py index a63374fa6..281c4f0ab 100644 --- a/slapos/recipe/notifier.py +++ b/slapos/recipe/notifier.py @@ -33,16 +33,14 @@ class Recipe(GenericBaseRecipe): def install(self): options = self.options # Script that execute the callback(s) upon receiving a notification. - script = self.createWrapper(name=options['wrapper'], - command=options['server-binary'], - parameters=[ + return self.createWrapper(options['wrapper'], + (options['server-binary'], '--callbacks', options['callbacks'], '--feeds', options['feeds'], '--equeue-socket', options['equeue-socket'], options['host'], options['port'] - ], + ), ) - return [script] class Callback(GenericBaseRecipe): @@ -98,16 +96,12 @@ class Notify(GenericBaseRecipe): '--status-item-directory', status_item_directory, ) + kw = {} if pidfile: - return self.createPythonScript(wrapper, - 'slapos.recipe.librecipe.execute.generic_exec', - (cmd,), {'pidfile': pidfile}) + kw['pidfile'] = pidfile # Script that call an executable and send notification(s). - return self.createWrapper(name=wrapper, - command=cmd[0], - parameters=cmd[1:], - ) + return self.createWrapper(wrapper, cmd, **kw) def install(self): diff --git a/slapos/recipe/novnc/__init__.py b/slapos/recipe/novnc/__init__.py index 5e114bb46..af06ddf86 100644 --- a/slapos/recipe/novnc/__init__.py +++ b/slapos/recipe/novnc/__init__.py @@ -35,10 +35,9 @@ class Recipe(GenericBaseRecipe): """ def install(self): - return self.createPythonScript( + return self.createWrapper( self.options['path'], - 'slapos.recipe.librecipe.execute.generic_exec', - (( + ( self.options['websockify-path'], '--web', self.options['novnc-location'], @@ -47,7 +46,7 @@ class Recipe(GenericBaseRecipe): '--ssl-only', '%s:%s' % (self.options['ip'], self.options['port']), '%s:%s' % (self.options['vnc-ip'], self.options['vnc-port']), - ),), - {'wait_list': (self.options['ssl-key-path'], - self.options['ssl-cert-path'])}, + ), + wait_list=(self.options['ssl-key-path'], + self.options['ssl-cert-path']), ) diff --git a/slapos/recipe/pbs.py b/slapos/recipe/pbs.py index 23c191600..e1ee60cbe 100644 --- a/slapos/recipe/pbs.py +++ b/slapos/recipe/pbs.py @@ -320,12 +320,11 @@ class Recipe(GenericSlapRecipe, Notify, Callback): else: self.logger.info("Server mode") - wrapper = self.createWrapper(name=self.options['wrapper'], - command=self.options['rdiffbackup-binary'], - parameters=[ + wrapper = self.createWrapper(self.options['wrapper'], + (self.options['rdiffbackup-binary'], '--restrict', self.options['path'], '--server' - ]) + )) path_list.append(wrapper) return path_list diff --git a/slapos/recipe/redis/__init__.py b/slapos/recipe/redis/__init__.py index 428db90dd..49559455f 100644 --- a/slapos/recipe/redis/__init__.py +++ b/slapos/recipe/redis/__init__.py @@ -56,10 +56,9 @@ class Recipe(GenericBaseRecipe): configuration)) path_list.append(config) - redis = self.createPythonScript( + redis = self.createWrapper( 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) diff --git a/slapos/recipe/reverse_proxy_nginx/__init__.py b/slapos/recipe/reverse_proxy_nginx/__init__.py index 61a244bb9..785bca1af 100644 --- a/slapos/recipe/reverse_proxy_nginx/__init__.py +++ b/slapos/recipe/reverse_proxy_nginx/__init__.py @@ -70,14 +70,12 @@ class Recipe(GenericSlapRecipe): path_list.append(nginx_configuration_file) # Generate Nginx wrapper - wrapper = self.createWrapper( - name=self.options['wrapper'], - command=self.options['nginx-executable'], - parameters=[ + path_list.append(self.createWrapper( + self.options['wrapper'], + (self.options['nginx-executable'], '-c', self.options['configuration-file'], '-p', self.options['home-directory'] - ] - ) + ))) # TODO: reload configuration or have feature like apache_map diff --git a/slapos/recipe/shell.py b/slapos/recipe/shell.py index dda292729..f64d9685d 100644 --- a/slapos/recipe/shell.py +++ b/slapos/recipe/shell.py @@ -32,14 +32,11 @@ class Recipe(GenericBaseRecipe): def install(self): ps1 = self.options.get('ps1') + shell = self.options['shell'] env = { 'HOME': self.options['home'], 'PATH': ':'.join(self.options['path'].split('\n')), 'PS1': str(json.loads(ps1)) if ps1 else os.getenv('PS1', '> '), - 'SHELL': self.options['shell'], + 'SHELL': shell, } - return self.createPythonScript( - self.options['wrapper'], - 'slapos.recipe.librecipe.execute.generic_exec', - ((self.options['shell'],), env), - ) + return self.createWrapper(self.options['wrapper'], (shell,), env) diff --git a/slapos/recipe/sphinx/__init__.py b/slapos/recipe/sphinx/__init__.py index de7bd4685..bac224d84 100644 --- a/slapos/recipe/sphinx/__init__.py +++ b/slapos/recipe/sphinx/__init__.py @@ -48,11 +48,10 @@ class Recipe(GenericBaseRecipe): ) # Create init script - wrapper = self.createPythonScript( + wrapper = self.createWrapper( self.options['wrapper'], - 'slapos.recipe.librecipe.execute.generic_exec', - ((self.options['sphinx-searchd-binary'].strip(), '-c', - sphinx_conf_path, '--nodetach'),), + (self.options['sphinx-searchd-binary'].strip(), '-c', + sphinx_conf_path, '--nodetach'), ) return [wrapper, sphinx_conf_path] diff --git a/slapos/recipe/squid/__init__.py b/slapos/recipe/squid/__init__.py index 17c31dae1..3f54b8261 100644 --- a/slapos/recipe/squid/__init__.py +++ b/slapos/recipe/squid/__init__.py @@ -78,17 +78,15 @@ class Recipe(GenericBaseRecipe): self.substituteTemplate(template_filename, config)) # Prepare directories - prepare_path = self.createPythonScript( + prepare_path = self.createWrapper( self.options['prepare-path'], - 'slapos.recipe.librecipe.execute.generic_exec', - ((self.options['binary-path'].strip(), - '-z', '-f', configuration_path),)) + (self.options['binary-path'].strip(), + '-z', '-f', configuration_path)) # Create running wrapper - wrapper_path = self.createPythonScript( + wrapper_path = self.createWrapper( self.options['wrapper-path'], - 'slapos.recipe.librecipe.execute.generic_exec', - ((self.options['binary-path'].strip(), - '-N', '-f', configuration_path),)) + (self.options['binary-path'].strip(), + '-N', '-f', configuration_path)) return [configuration_path, wrapper_path, prepare_path] diff --git a/slapos/recipe/sshkeys_authority.py b/slapos/recipe/sshkeys_authority.py index 82855ee26..e8751ab43 100644 --- a/slapos/recipe/sshkeys_authority.py +++ b/slapos/recipe/sshkeys_authority.py @@ -152,10 +152,9 @@ class Request(GenericBaseRecipe): os.symlink(self.private_key, private_key_link) # end-XXX - wrapper = self.createPythonScript( + wrapper = self.createWrapper( self.options['wrapper'], - 'slapos.recipe.librecipe.execute.generic_exec', - ((self.options['executable'],),), - {'wait_list': (self.private_key, self.public_key)}) + (self.options['executable'],), + wait_list=(self.private_key, self.public_key)) return [request_file, wrapper, public_key_link, private_key_link] diff --git a/slapos/recipe/stunnel/__init__.py b/slapos/recipe/stunnel/__init__.py index 124aefbdc..eb4b27526 100644 --- a/slapos/recipe/stunnel/__init__.py +++ b/slapos/recipe/stunnel/__init__.py @@ -79,10 +79,9 @@ class Recipe(GenericBaseRecipe): self.substituteTemplate(template, conf)) path_list.append(conf_file) - wrapper = self.createPythonScript( + wrapper = self.createWrapper( 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) diff --git a/slapos/recipe/tidstorage/__init__.py b/slapos/recipe/tidstorage/__init__.py index 5f2d15966..672abdf84 100644 --- a/slapos/recipe/tidstorage/__init__.py +++ b/slapos/recipe/tidstorage/__init__.py @@ -36,19 +36,17 @@ class Recipe(GenericBaseRecipe): r = [configuration_file] wrapper = self.options.get('tidstorage-wrapper') - wrapper and r.append(self.createPythonScript(wrapper, - 'slapos.recipe.librecipe.execute.generic_exec', - ((self.options['tidstoraged-binary'], - '--nofork', '--config', configuration_file),))) + wrapper and r.append(self.createWrapper(wrapper, + (self.options['tidstoraged-binary'], + '--nofork', '--config', configuration_file))) - r.append(self.createPythonScript( + r.append(self.createWrapper( self.options['repozo-wrapper'], - 'slapos.recipe.librecipe.execute.generic_exec', - ((self.options['tidstorage-repozo-binary'], + (self.options['tidstorage-repozo-binary'], '--config', configuration_file, '--repozo', self.options['repozo-binary'], '--gzip', '--quick', - ),))) + ))) return r diff --git a/slapos/recipe/wrapper.py b/slapos/recipe/wrapper.py index e47d0f376..2f4dab0e2 100644 --- a/slapos/recipe/wrapper.py +++ b/slapos/recipe/wrapper.py @@ -40,7 +40,7 @@ class Recipe(GenericBaseRecipe): :param bool reserve-cpu: command will ask for an exclusive CPU core """ def install(self): - command_line = shlex.split(self.options['command-line']) + args = shlex.split(self.options['command-line']) wrapper_path = self.options['wrapper-path'] wait_files = self.options.get('wait-for-files') pidfile = self.options.get('pidfile') @@ -60,17 +60,4 @@ class Recipe(GenericBaseRecipe): if self.isTrueValue(self.options.get('reserve-cpu')): kw['reserve_cpu'] = True - if 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) + return self.createWrapper(wrapper_path, args, environment, **kw) diff --git a/slapos/recipe/zeo/__init__.py b/slapos/recipe/zeo/__init__.py index 8ac035f4d..184714f8d 100644 --- a/slapos/recipe/zeo/__init__.py +++ b/slapos/recipe/zeo/__init__.py @@ -89,10 +89,9 @@ class Recipe(GenericBaseRecipe): self.substituteTemplate(template_filename, config)) # Create running wrapper - wrapper_path = self.createPythonScript( + wrapper_path = self.createWrapper( self.options['wrapper-path'], - 'slapos.recipe.librecipe.execute.generic_exec', - ((self.options['binary-path'].strip(), - '-C', self.options['conf-path']),)) + (self.options['binary-path'].strip(), + '-C', self.options['conf-path'])) return [configuration_path, wrapper_path] -- 2.30.9