system.services.service_status

Here are the examples of the python api system.services.service_status taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

4 Examples 7

Example 1

Project: rockstor-core Source File: base_service.py
Function: get_status
    def _get_status(self, service):
        try:
            config = None
            if (service.config is not None):
                config = self._get_config(service)

            o, e, rc = service_status(service.name, config)
            if (rc == 0):
                return True
            return False
        except Exception, e:
            msg = ('Exception while querying status of service(%s): %s' %
                   (service.name, e.__str__()))
            logger.error(msg)
            logger.exception(e)
            return False

Example 2

Project: rockstor-core Source File: data_collector.py
    def send_service_statuses(self):
        while True:
            data = {}
            for service in Service.objects.all():
                config = None
                if (service.config is not None):
                    try:
                        config = json.loads(service.config)
                    except Exception, e:
                        logger.error('Exception while loading config of '
                                     'Service(%s): %s' %
                                     (service.name, e.__str__()))
                data[service.name] = {}
                output, error, return_code = service_status(service.name, config=config)
                data[service.name]['running'] = return_code

            self.emit('services:get_services', {
                'data': data, 'key': 'services:get_services'
            })
            gevent.sleep(15)

Example 3

Project: rockstor-core Source File: samba_service.py
    @transaction.commit_on_success
    def post(self, request, command):
        """
        execute a command on the service
        """
        service = Service.objects.get(name=self.service_name)
        
        if (command == 'config'):
            try:
                config = request.data.get('config', {})
                global_config = {}
                gc_lines = config['global_config'].split('\n')
                for l in gc_lines:
                    gc_param = l.strip().split('=')
                    if (len(gc_param) == 2):
                        global_config[gc_param[0].strip().lower()] = gc_param[1].strip()
                #Default set current workgroup to one got via samba config page
                global_config['workgroup'] = config['workgroup']
                #Check Active Directory config and status
                #if AD configured and ON set workgroup to AD retrieved workgroup
                #else AD not running and leave workgroup to one choosen by user
                adso = Service.objects.get(name='active-directory')
                adconfig = {}
                adso_status = 1
                if (adso.config is not None):
                    adconfig = self._get_config(adso)
                    adso_out, adso_err, adso_status = service_status('active-directory', adconfig)
                    if adso_status == 0:
                        global_config['workgroup'] = adconfig['workgroup']
                    else:
                        adconfig = None

                self._save_config(service, global_config)
                update_global_config(global_config, adconfig)
                restart_samba(hard=True)
            except Exception, e:
                e_msg = ('Samba could not be configured. Try again. '
                         'Exception: %s' % e.__str__())
                handle_exception(Exception(e_msg), request)
        else:
            try:
                if (command == 'stop'):
                    systemctl('smb', 'disable')
                    systemctl('nmb', 'disable')
                else:
                    systemd_name = '%s.service' % self.service_name
                    ss_dest = ('/etc/systemd/system/%s' % systemd_name)
                    ss_src = ('%s/%s' % (settings.CONFROOT, systemd_name))
                    sum1 = md5sum(ss_dest)
                    sum2 = md5sum(ss_src)
                    if (sum1 != sum2):
                        shutil.copy(ss_src, ss_dest)
                    systemctl('smb', 'enable')
                    systemctl('nmb', 'enable')
                systemctl('nmb', command)
                systemctl('smb', command)
            except Exception, e:
                e_msg = ('Failed to %s samba due to a system error: %s' % (command, e.__str__()))
                handle_exception(Exception(e_msg), request)
        return Response()

Example 4

Project: rockstor-core Source File: rockon_helpers.py
def docker_status():
    o, e, rc = service_status('docker')
    if (rc != 0):
        return False
    return True