diff options
5 files changed, 16 insertions, 5 deletions
@@ -253,6 +253,7 @@ InstanceSetup | set\_multiqueue | `false` skips multiqueue driver sup IpForwarding | ethernet\_proto\_id | Protocol ID string for daemon added routes. IpForwarding | ip\_aliases | `false` disables setting up alias IP routes. IpForwarding | target\_instance\_ips | `false` disables internal IP address load balancing. +MetadataScripts | default\_shell | String with the default shell to execute scripts. MetadataScripts | run\_dir | String base directory where metadata scripts are executed. MetadataScripts | startup | `false` disables startup script execution. MetadataScripts | shutdown | `false` disables shutdown script execution. diff --git a/google_compute_engine/instance_setup/instance_config.py b/google_compute_engine/instance_setup/instance_config.py index c71a3ac..782f6b0 100644 --- a/google_compute_engine/instance_setup/instance_config.py +++ b/google_compute_engine/instance_setup/instance_config.py @@ -89,6 +89,7 @@ class InstanceConfig(config_manager.ConfigManager): 'run_dir': '', 'startup': 'true', 'shutdown': 'true', + 'default_shell': '/bin/bash', }, 'NetworkInterfaces': { 'setup': 'true', diff --git a/google_compute_engine/metadata_scripts/script_executor.py b/google_compute_engine/metadata_scripts/script_executor.py index e90cfac..3523f72 100644 --- a/google_compute_engine/metadata_scripts/script_executor.py +++ b/google_compute_engine/metadata_scripts/script_executor.py @@ -25,15 +25,17 @@ from google_compute_engine import constants class ScriptExecutor(object): """A class for executing user provided metadata scripts.""" - def __init__(self, logger, script_type): + def __init__(self, logger, script_type, default_shell=None): """Constructor. Args: logger: logger object, used to write to SysLog and serial port. script_type: string, the type of the script we are running. + default_shell: string, the default shell to execute the script. """ self.logger = logger self.script_type = script_type + self.default_shell = default_shell or '/bin/bash' def _MakeExecutable(self, metadata_script): """Add executable permissions to a file. @@ -53,7 +55,7 @@ class ScriptExecutor(object): """ process = subprocess.Popen( metadata_script, shell=True, - executable=constants.LOCALBASE + '/bin/bash', + executable=self.default_shell, stderr=subprocess.STDOUT, stdout=subprocess.PIPE) while True: for line in iter(process.stdout.readline, b''): diff --git a/google_compute_engine/metadata_scripts/script_manager.py b/google_compute_engine/metadata_scripts/script_manager.py index 641b29d..32c1452 100755 --- a/google_compute_engine/metadata_scripts/script_manager.py +++ b/google_compute_engine/metadata_scripts/script_manager.py @@ -48,20 +48,24 @@ def _CreateTempDir(prefix, run_dir=None): class ScriptManager(object): """A class for retrieving and executing metadata scripts.""" - def __init__(self, script_type, run_dir=None, debug=False): + def __init__( + self, script_type, default_shell=None, run_dir=None, debug=False): """Constructor. Args: script_type: string, the metadata script type to run. + default_shell: string, the default shell to execute the script. run_dir: string, the base directory location of the temporary directory. debug: bool, True if debug output should write to the console. """ self.script_type = script_type + self.default_shell = default_shell name = '%s-script' % self.script_type facility = logging.handlers.SysLogHandler.LOG_DAEMON self.logger = logger.Logger(name=name, debug=debug, facility=facility) self.retriever = script_retriever.ScriptRetriever(self.logger, script_type) - self.executor = script_executor.ScriptExecutor(self.logger, script_type) + self.executor = script_executor.ScriptExecutor( + self.logger, script_type, default_shell=default_shell) self._RunScripts(run_dir=run_dir) def _RunScripts(self, run_dir=None): @@ -99,6 +103,8 @@ def main(): if instance_config.GetOptionBool('MetadataScripts', script_type): ScriptManager( script_type, + default_shell=instance_config.GetOptionString( + 'MetadataScripts', 'default_shell'), run_dir=instance_config.GetOptionString('MetadataScripts', 'run_dir'), debug=bool(options.debug)) diff --git a/google_compute_engine/metadata_scripts/tests/script_manager_test.py b/google_compute_engine/metadata_scripts/tests/script_manager_test.py index ec7d61f..f932a92 100644 --- a/google_compute_engine/metadata_scripts/tests/script_manager_test.py +++ b/google_compute_engine/metadata_scripts/tests/script_manager_test.py @@ -54,7 +54,8 @@ class ScriptManagerTest(unittest.TestCase): mock.call.logger.Logger( name=script_name, debug=False, facility=mock.ANY), mock.call.retriever.ScriptRetriever(mock_logger_instance, script_type), - mock.call.executor.ScriptExecutor(mock_logger_instance, script_type), + mock.call.executor.ScriptExecutor( + mock_logger_instance, script_type, default_shell=None), mock.call.mkdir(prefix=script_prefix, dir=run_dir), mock.call.logger.Logger().info(mock.ANY, script_type), mock.call.retriever.ScriptRetriever().GetScripts(test_dir), |