def wrapped_cmdline(self, cwd): cmdline = self.cmdline() # If mesos-containerizer is not set, we only need to wrap the cmdline in a bash invocation. if self._mesos_containerizer_path is None: return ['/bin/bash', '-c', cmdline] else: return wrap_with_mesos_containerizer(cmdline, self._user, cwd, self._mesos_containerizer_path)
def wrapped_cmdline(self, cwd): cmdline = self.cmdline() # If mesos-containerizer is not set, we only need to wrap the cmdline in a bash invocation. if self._mesos_containerizer_path is None: return ['/bin/bash', '-c', cmdline] else: return wrap_with_mesos_containerizer( cmdline, self._user, cwd, self._mesos_containerizer_path)
def wrapper(cmd): return wrap_with_mesos_containerizer( cmd, health_check_user, sandbox.container_root, self._mesos_containerizer_path)
def from_assigned_task(self, assigned_task, sandbox): """ :param assigned_task: :param sandbox: :return: Instance of a HealthChecker. """ mesos_task = mesos_task_instance_from_assigned_task(assigned_task) health_check_config = mesos_task.health_check_config().get() health_checker = health_check_config.get('health_checker', {}) timeout_secs = health_check_config.get('timeout_secs') if SHELL_HEALTH_CHECK in health_checker: shell_command = health_checker.get(SHELL_HEALTH_CHECK, {}).get('shell_command') # Filling in variables e.g. thermos.ports[http] that could have been passed in as part of # shell_command. interpolated_command = HealthCheckerProvider.interpolate_cmd( task=assigned_task, cmd=shell_command) # If we do not want the health check to execute as the user from the job's role # --nosetuid-health-checks should be passed as an argument to the executor. demote_to_job_role_user = None if not self._nosetuid_health_checks and not sandbox.is_filesystem_image: pw_entry = pwd.getpwnam(assigned_task.task.job.role) def demote_to_job_role_user(): os.setgid(pw_entry.pw_gid) os.setuid(pw_entry.pw_uid) # If the task is executing in an isolated filesystem we'll want to wrap the health check # command within a mesos-containerizer invocation so that it's executed within that # filesystem. if sandbox.is_filesystem_image: health_check_user = (getpass.getuser() if self._nosetuid_health_checks else assigned_task.task.job.role) wrapped_cmd = wrap_with_mesos_containerizer( interpolated_command, health_check_user, sandbox.container_root, self._mesos_containerizer_path) else: wrapped_cmd = ['/bin/bash', '-c', interpolated_command] shell_signaler = ShellHealthCheck( raw_cmd=interpolated_command, wrapped_cmd=wrapped_cmd, preexec_fn=demote_to_job_role_user, timeout_secs=timeout_secs) a_health_checker = lambda: shell_signaler() else: portmap = resolve_ports(mesos_task, assigned_task.assignedPorts) if 'health' not in portmap: log.warning('No health-checks defined, will use a no-op health-checker.') return NoopHealthChecker() http_config = health_checker.get(HTTP_HEALTH_CHECK, {}) http_endpoint = http_config.get('endpoint') http_expected_response = http_config.get('expected_response') http_expected_response_code = http_config.get('expected_response_code') http_signaler = HttpSignaler( portmap['health'], timeout_secs=timeout_secs) a_health_checker = lambda: http_signaler( endpoint=http_endpoint, expected_response=http_expected_response, expected_response_code=http_expected_response_code ) health_checker = HealthChecker( a_health_checker, sandbox, interval_secs=health_check_config.get('interval_secs'), grace_period_secs=health_check_config.get('initial_interval_secs'), max_consecutive_failures=health_check_config.get('max_consecutive_failures'), min_consecutive_successes=health_check_config.get('min_consecutive_successes')) return health_checker
def from_assigned_task(self, assigned_task, sandbox): """ :param assigned_task: :param sandbox: :return: Instance of a HealthChecker. """ mesos_task = mesos_task_instance_from_assigned_task(assigned_task) health_check_config = mesos_task.health_check_config().get() health_checker = health_check_config.get('health_checker', {}) timeout_secs = health_check_config.get('timeout_secs') if SHELL_HEALTH_CHECK in health_checker: shell_command = health_checker.get(SHELL_HEALTH_CHECK, {}).get('shell_command') # Filling in variables e.g. thermos.ports[http] that could have been passed in as part of # shell_command. interpolated_command = HealthCheckerProvider.interpolate_cmd( task=assigned_task, cmd=shell_command) # If we do not want the health check to execute as the user from the job's role # --nosetuid-health-checks should be passed as an argument to the executor. demote_to_job_role_user = None if not self._nosetuid_health_checks and not sandbox.is_filesystem_image: pw_entry = pwd.getpwnam(assigned_task.task.job.role) def demote_to_job_role_user(): os.setgid(pw_entry.pw_gid) os.setuid(pw_entry.pw_uid) # If the task is executing in an isolated filesystem we'll want to wrap the health check # command within a mesos-containerizer invocation so that it's executed within that # filesystem. if sandbox.is_filesystem_image: health_check_user = (os.getusername() if self._nosetuid_health_checks else assigned_task.task.job.role) wrapped_cmd = wrap_with_mesos_containerizer( interpolated_command, health_check_user, sandbox.container_root, self._mesos_containerizer_path) else: wrapped_cmd = ['/bin/bash', '-c', interpolated_command] shell_signaler = ShellHealthCheck( raw_cmd=interpolated_command, wrapped_cmd=wrapped_cmd, preexec_fn=demote_to_job_role_user, timeout_secs=timeout_secs) a_health_checker = lambda: shell_signaler() else: portmap = resolve_ports(mesos_task, assigned_task.assignedPorts) if 'health' not in portmap: log.warning( 'No health-checks defined, will use a no-op health-checker.' ) return NoopHealthChecker() http_config = health_checker.get(HTTP_HEALTH_CHECK, {}) http_endpoint = http_config.get('endpoint') http_expected_response = http_config.get('expected_response') http_expected_response_code = http_config.get( 'expected_response_code') http_signaler = HttpSignaler(portmap['health'], timeout_secs=timeout_secs) a_health_checker = lambda: http_signaler( endpoint=http_endpoint, expected_response=http_expected_response, expected_response_code=http_expected_response_code) health_checker = HealthChecker( a_health_checker, sandbox, interval_secs=health_check_config.get('interval_secs'), grace_period_secs=health_check_config.get('initial_interval_secs'), max_consecutive_failures=health_check_config.get( 'max_consecutive_failures'), min_consecutive_successes=health_check_config.get( 'min_consecutive_successes')) return health_checker