Perform a service dump.

        :param service: Service to dump.
        :param grep: Grep for this string.
        :returns: Dump, optionally grepped.
514931
def _dump(self, service, grep=None):
        
        if grep:
            return self.adb_shell('dumpsys {0} | grep "{1}"'.format(service, grep))
        return self.adb_shell('dumpsys {0}'.format(service))
1058154
def offload_service_containers(self, service):
        
        def anonymous(anonymous_service):
            if not isinstance(anonymous_service, Service):
                raise TypeError("service must be an instance of Service.")

            if anonymous_service.containers:
                logger.info("Deleting service: {0} containers.".format(anonymous_service.name))
                for container_name in list(anonymous_service.containers.keys()):
                    del anonymous_service.containers[container_name]

        self._service_map(service, anonymous, descending=True)
906018
def _get_service_exec():
    '''
    
    '''
    contextkey = 'systemd._get_service_exec'
    if contextkey not in __context__:
        executables = ('update-rc.d', 'chkconfig')
        for executable in executables:
            service_exec = salt.utils.path.which(executable)
            if service_exec is not None:
                break
        else:
            raise CommandExecutionError(
                'Unable to find sysv service manager (tried {0})'.format(
                    ', '.join(executables)
                )
            )
        __context__[contextkey] = service_exec
    return __context__[contextkey]
987807
def createService(self, service):
        
        url = self._url + "/createService"
        params = {
            "f" : "json"
        }
        if isinstance(service, str):
            params['service'] = service
        elif isinstance(service, dict):
            params['service'] = json.dumps(service)
        return self._post(url=url,
                             param_dict=params,
                             securityHandler=self._securityHandler,
                             proxy_url=self._proxy_url,
                             proxy_port=self._proxy_port)
1204901
def _dumps(cnf, **kwargs):
    
    return os.linesep.join(l for l in _dumps_itr(cnf))
748069
def _find_service_name(self):
        
        space = predix.admin.cf.spaces.Space()
        services = space.get_services()
        for service in services:
            if service.startswith('logstash'):
                return service

        return 'logstash-3'
1145636
def register_service(cls, service):
        
        logger.debug('Registering service {0}'.format(service.name))
        return local_store.instance.register(service)
875033
def StartService(service_name):
  
  try:
    win32serviceutil.StartService(service_name)
    logging.info("Service '%s' started.", service_name)
  except pywintypes.error as e:
    if getattr(e, "winerror", None) == winerror.ERROR_SERVICE_DOES_NOT_EXIST:
      logging.debug("Tried to start '%s', but the service is not installed.",
                    service_name)
    else:
      logging.exception("Encountered error trying to start '%s':", service_name)
832419
def recall_service(self, service):
        
        if not isinstance(service, Service):
            raise TypeError("service must be of type Service.")

        logger.warning("The deployment for {0} on {1} failed starting the rollback.".format(service.alias, self.url.geturl()))

        def anonymous(anonymous_service):
            if not isinstance(anonymous_service, Service):
                raise TypeError("service must be an instance of Service.")

            containers = self.find_previous_service_containers(anonymous_service)
            if containers:
                for name in list(anonymous_service.containers.keys()):
                    del anonymous_service.containers[name]

                anonymous_service.cargo.delete()

                for name, container in six.iteritems(containers):
                    # TODO: add function to container obj to see if its running.
                    if container.state().get('running'):
                        logger.info(
                            "is already running... Might want to investigate.",
                            extra={'formatter': 'container', 'container': container.name}
                        )
                    else:
                        if container.start():
                            logger.info(
                                "is restarted and healthy.",
                                extra={'formatter': 'container', 'container': container.name}
                            )
                        else:
                            logger.error(
                                "failed to start.",
                                extra={'formatter': 'container', 'container': container.name}
                            )

                            container.dump_logs()
                            raise Exception(
                                "The deployment for {0} on {1} went horribly wrong".format(container.name, self.url.geturl())
                            )

        self._service_map(service, anonymous, descending=False)
212509
def _loadServices(self):
        
        servicesPath = os.path.join(self.path, "service")
        if not os.path.isdir(servicesPath):
            return

        self._scanDirectoryForServices(servicesPath)
395170
def run(ctx, service, args, show_args, daemon, editable, integration):
    """"""
    home = ctx.obj["HOME"]
    service_path = plugin_utils.get_plugin_path(home, SERVICES, service, editable)
    service_log_path = os.path.join(service_path, LOGS_DIR)

    logger.debug("running command %s (%s)", ctx.command.name, ctx.params,
                 extra={"command": ctx.command.name, "params": ctx.params})

    logger.debug("loading {} ({})".format(service, service_path))
    service = register_service(service_path)

    if show_args:
        return plugin_utils.print_plugin_args(service_path)

    # get our service class instance
    service_module = get_service_module(service_path)
    service_args = plugin_utils.parse_plugin_args(args, config_utils.get_config_parameters(service_path))
    service_obj = service_module.service_class(alert_types=service.alert_types, service_args=service_args)

    if not os.path.exists(service_log_path):
        os.mkdir(service_log_path)

    # prepare runner
    if daemon:
        runner = myRunner(service_obj,
                          pidfile=service_path + ".pid",
                          stdout=open(os.path.join(service_log_path, STDOUTLOG), "ab"),
                          stderr=open(os.path.join(service_log_path, STDERRLOG), "ab"))

        files_preserve = []
        for handler in logging.getLogger().handlers:
            if hasattr(handler, "stream"):
                if hasattr(handler.stream, "fileno"):
                    files_preserve.append(handler.stream.fileno())
            if hasattr(handler, "socket"):
                files_preserve.append(handler.socket.fileno())

        runner.daemon_context.files_preserve = files_preserve
        runner.daemon_context.signal_map.update({
            signal.SIGTERM: service_obj._on_server_shutdown,
            signal.SIGINT: service_obj._on_server_shutdown,
        })
        logger.debug("daemon_context", extra={"daemon_context": vars(runner.daemon_context)})

    for integration_name in integration:
        integration_path = plugin_utils.get_plugin_path(home, INTEGRATIONS, integration_name, editable)
        configure_integration(integration_path)

    click.secho("[+] Launching {} {}".format(service.name, "in daemon mode" if daemon else ""))
    try:
        # save service_args for external reference (see test)
        with open(os.path.join(service_path, ARGS_JSON), "w") as f:
            f.write(json.dumps(service_args))
        runner._start() if daemon else service_obj.run()
    except KeyboardInterrupt:
        service_obj._on_server_shutdown()

    click.secho("[*] {} has stopped".format(service.name))
939076
def diff_sevice_by_text(service_name, service, environment, cf_client, repo_root):
    
    global ret_code

    logger.info('Investigating textual diff for `%s`:`%s` in environment `%s`',
                service['type'], service_name, environment)

    try:
        local_template = render_local_template(service_name, environment,
                                               repo_root, service['template_file'])

        current_template = fetch_current_cloudformation_template(
            service_name, environment, cf_client)

    except Exception as e:
        ret_code = 2
        logger.error(e)
        return

    ret = diff_string_templates(local_template, current_template)
    if not ret:
        logger.info('Deployed service `%s` in environment `%s` matches '
                    'the local template.', service_name, environment)
    else:
        ret_code = 1
        logger.error('Service `%s` in environment `%s` differs from '
                     'the local template.',
                     service_name, environment)
        logger.info('Change details:\n        %s', indentify(ret))
248727
def p_service(self, p):
        '''
        '''

        if len(p) == 7:
            p[0] = ast.Service(
                name=p[2],
                functions=p[4],
                parent=None,
                annotations=p[6],
                lineno=p.lineno(2),
            )
        else:
            p[0] = ast.Service(
                name=p[2],
                functions=p[6],
                parent=ast.ServiceReference(p[4], p.lineno(4)),
                annotations=p[8],
                lineno=p.lineno(2),
            )
510375
def removeService(self, service):
        
        for name, wrapper in self.services.iteritems():
            if service in (name, wrapper.service):
                del self.services[name]
                return

        raise NameError("Service %r not found" % (service,))
170440
def service_restart(name):
    '''
    
    '''
    cmd = 'restart ' + name

    # Send the command to execute
    out, err = DETAILS['server'].sendline(cmd)

    # "scrape" the output and return the right fields as a dict
    return parse(out)
379702
def dump(data, stream=None, Dumper=Dumper, **kwds):
    
    return dump_all([data], stream, Dumper=Dumper, **kwds)
839322
private void dumpCache(){
        if (CacheDumpLogger.isDebugEnabled()) {
            try {
                StringBuilder sb = new StringBuilder();
                sb.append("LookupManager dumped Service Cache at: ").append(System.currentTimeMillis()).append("\n");
                ModelService service = getData();
                sb.append(service==null ? "Cache is empty" : new String(serialize(service))).append("\n");
                CacheDumpLogger.debug(sb.toString());
            } catch (Exception e) {
                LOGGER.warn("Dump Service Cache failed. Set Logger {} to INFO to disable this message.",
                            CacheDumpLogger.getName());
                LOGGER.trace("Dump Service Cache failed. ", e);
            }
        }
    }