コード例 #1
0
 def _get_status(self, service):
     try:
         o, e, rc = service_status(service.name)
         if rc == 0:
             return True
         return False
     except Exception, e:
         msg = "Exception while querying status of service: %s" % service.name
         logger.error(msg)
         logger.exception(e)
         return False
コード例 #2
0
 def _get_status(self, service):
     try:
         o, e, rc = service_status(service.name)
         if (rc == 0):
             return True
         return False
     except Exception, e:
         msg = ('Exception while querying status of service: %s' %
                service.name)
         logger.error(msg)
         logger.exception(e)
         return False
コード例 #3
0
    def send_service_statuses(self):
        # Iterate through the collection and assign the values accordingly
        services = [s.name for s in Service.objects.all()]
        while True:
            data = {}
            for service in services:
                data[service] = {}
                output, error, return_code = service_status(service)
                data[service]['running'] = return_code

            self.emit('services:get_services', {
                'data': data, 'key': 'services:get_services'
            })
            gevent.sleep(5)
コード例 #4
0
    def send_service_statuses(self):
        # Iterate through the collection and assign the values accordingly
        services = [s.name for s in Service.objects.all()]
        while True:
            data = {}
            for service in services:
                data[service] = {}
                output, error, return_code = service_status(service)
                data[service]['running'] = return_code

            self.emit('services:get_services', {
                'data': data,
                'key': 'services:get_services'
            })
            gevent.sleep(5)
コード例 #5
0
    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)
            return False
コード例 #6
0
    def shutdown_status(self):

        while self.start:
            data = {}
            output, error, return_code = service_status("systemd-shutdownd")
            data["status"] = return_code
            if return_code == 0:
                for row in output:
                    if re.search("Status", row) is not None:
                        data["message"] = row.split(":", 1)[1]

            self.emit(
                "shutdown_status", {"key": "sysinfo:shutdown_status", "data": data}
            )

            gevent.sleep(30)
コード例 #7
0
    def shutdown_status(self):

        while self.start:
            data = {}
            output, error, return_code = service_status('systemd-shutdownd')
            data['status'] = return_code
            if (return_code == 0):
                for row in output:
                    if (re.search('Status', row) is not None):
                        data['message'] = row.split(':', 1)[1]

            self.emit('shutdown_status', {
                'key': 'sysinfo:shutdown_status',
                'data': data
            })

            gevent.sleep(30)
コード例 #8
0
    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):
                        if '=' in gc_param[0]:
                            raise Exception(
                                'Syntax error, one param has wrong spaces around equal signs, '
                                'please check syntax of \'%s\'' %
                                ''.join(gc_param))
                        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 = None
                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)
コード例 #9
0
    def shutdown_status(self):

        while self.start:
            data = {}
            output, error, return_code = service_status('systemd-shutdownd')
            data['status'] = return_code
            if (return_code == 0):
                for row in output:
                    if (re.search('Status', row) is not None):
                        data['message'] = row.split(':', 1)[1]

            self.emit('shutdown_status',
                      {
                          'key': 'sysinfo:shutdown_status',
                          'data': data
                      })

            gevent.sleep(30)
コード例 #10
0
    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 as e:
            msg = "Exception while querying status of service(%s): %s" % (
                service.name,
                e.__str__(),
            )
            logger.error(msg)
            logger.exception(e)
            return False
コード例 #11
0
    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)
コード例 #12
0
ファイル: dc2.py プロジェクト: Type-of-iframe/rockstor-core
    def send_service_statuses(self):
        # Iterate through the collection and assign the values accordingly
        services = ('nfs', 'smb', 'ntpd', 'winbind', 'netatalk',
                    'snmpd', 'docker', 'smartd', 'replication',
                    'nis', 'ldap', 'sftp', 'data-collector', 'smartd',
                    'service-monitor', 'docker', 'task-scheduler')
        while True:
            data = {}
            for service in services:
                data[service] = {}
                output, error, return_code = service_status(service)
                if (return_code == 0):
                    data[service]['running'] = return_code
                else:
                    data[service]['running'] = return_code

            self.emit('services:get_services', {
                'data': data, 'key': 'services:get_services'
            })
            gevent.sleep(5)
コード例 #13
0
    def send_service_statuses(self):
        # Iterate through the collection and assign the values accordingly
        services = ('nfs', 'smb', 'ntpd', 'netatalk',
                    'snmpd', 'docker', 'smartd', 'replication',
                    'nis', 'ldap', 'sftp', 'data-collector', 'smartd',
                    'service-monitor', 'docker', 'task-scheduler')
        while True:
            data = {}
            for service in services:
                data[service] = {}
                output, error, return_code = service_status(service)
                if (return_code == 0):
                    data[service]['running'] = return_code
                else:
                    data[service]['running'] = return_code

            self.emit('services:get_services', {
                'data': data, 'key': 'services:get_services'
            })
            gevent.sleep(5)
コード例 #14
0
    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):
                        if '=' in gc_param[0]:
                            raise Exception('Syntax error, one param has wrong spaces around equal signs, '
                                            'please check syntax of \'%s\'' % ''.join(gc_param))
                        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 = None
                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)
コード例 #15
0
ファイル: services.py プロジェクト: aliamir/rockstor-core
    def run(self):
        try:
            while (True):
                if (os.getppid() != self.ppid):
                    msg = ('Parent process(smd) exited. I am exiting too.')
                    return logger.error(msg)

                if (self.q.qsize() < 1000):
                    for s in Service.objects.all():
                        sso = ServiceStatus(service=s, status=False)
                        try:
                            out, err, rc = service_status(s.name)
                            if (rc == 0):
                                sso.status = True
                        except Exception, e:
                            msg = ('Exception while getting status of '
                                   'service: %s' % s.name)
                            logger.error(msg)
                            logger.exception(e)
                        finally:
                            self.q.put(sso)
コード例 #16
0
    def send_service_statuses(self):

        while self.start:

            data = {}
            for service in Service.objects.all():
                config = None
                if service.config is not None:
                    try:
                        config = json.loads(service.config)
                    except Exception as 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("get_services", {"data": data, "key": "services:get_services"})
            gevent.sleep(15)
コード例 #17
0
ファイル: services.py プロジェクト: rcgade/rockstor-core
    def run(self):
        first_loop = True
        try:
            while (True):
                if (os.getppid() != self.ppid):
                    msg = ('Parent process(smd) exited. I am exiting too.')
                    return logger.error(msg)

                ts = datetime.utcnow().replace(tzinfo=utc)
                for s in Service.objects.all():
                    sso = None
                    if (first_loop is not True):
                        try:
                            sso = ServiceStatus.objects.filter(
                                service=s).latest('id')
                        except ObjectDoesNotExist:
                            pass

                    status = False
                    try:
                        out, err, rc = service_status(s.name)
                        if (rc == 0):
                            status = True
                    except Exception, e:
                        msg = ('Exception while getting status of '
                               'service: %s' % s.name)
                        logger.error(msg)
                        logger.exception(e)
                    finally:
                        if (sso is None or sso.status != status):
                            sso = ServiceStatus(service=s,
                                                status=status,
                                                ts=ts)
                        else:
                            sso.ts = ts
                            sso.count = sso.count + 1
                        sso.save()
                        first_loop = False
コード例 #18
0
ファイル: services.py プロジェクト: sujeetsr/rockstor-core
    def run(self):
        first_loop = True
        op_err_count = 0
        op_err_sleep = 5
        while True:
            try:
                if os.getppid() != self.ppid:
                    msg = "Parent process(smd) exited. I am exiting too."
                    return logger.error(msg)

                ts = datetime.utcnow().replace(tzinfo=utc)
                for s in Service.objects.all():
                    sso = None
                    if first_loop is not True:
                        try:
                            sso = ServiceStatus.objects.filter(service=s).latest("id")
                        except ObjectDoesNotExist:
                            pass

                    status = False
                    try:
                        out, err, rc = service_status(s.name)
                        if rc == 0:
                            status = True
                    except Exception, e:
                        msg = "Exception while getting status of " "service: %s" % s.name
                        logger.error(msg)
                        logger.exception(e)
                    finally:
                        if sso is None or sso.status != status:
                            sso = ServiceStatus(service=s, status=status, ts=ts)
                        else:
                            sso.ts = ts
                            sso.count = sso.count + 1
                        sso.save()
                        first_loop = False
                time.sleep(self.interval)
コード例 #19
0
ファイル: services.py プロジェクト: kamal-gade/rockstor-core
    def run(self):
        first_loop = True
        try:
            while (True):
                if (os.getppid() != self.ppid):
                    msg = ('Parent process(smd) exited. I am exiting too.')
                    return logger.error(msg)

                ts = datetime.utcnow().replace(tzinfo=utc)
                for s in Service.objects.all():
                    sso = None
                    if (first_loop is not True):
                        try:
                            sso = ServiceStatus.objects.filter(service=s).latest('id')
                        except ObjectDoesNotExist:
                            pass

                    status = False
                    try:
                        out, err, rc = service_status(s.name)
                        if (rc == 0):
                            status = True
                    except Exception, e:
                        msg = ('Exception while getting status of '
                               'service: %s' % s.name)
                        logger.error(msg)
                        logger.exception(e)
                    finally:
                        if (sso is None or sso.status != status):
                            sso = ServiceStatus(service=s,
                                                status=status, ts=ts)
                        else:
                            sso.ts = ts
                            sso.count = sso.count + 1
                        sso.save()
                        first_loop = False
コード例 #20
0
ファイル: services.py プロジェクト: sigkill/rockstor-core
    def run(self):
        context = zmq.Context()
        sink_socket = context.socket(zmq.PUSH)
        sink_socket.connect('tcp://%s:%d' % settings.SPROBE_SINK)
        try:
            while (True):
                if (os.getppid() != self.ppid):
                    msg = ('Parent process(smd) exited. I am exiting too.')
                    return logger.error(msg)

                ts = datetime.utcnow().replace(tzinfo=utc)
                for s in Service.objects.all():
                    sso = ServiceStatus(service=s, status=False, ts=ts)
                    try:
                        out, err, rc = service_status(s.name)
                        if (rc == 0):
                            sso.status = True
                    except Exception, e:
                        msg = ('Exception while getting status of '
                               'service: %s' % s.name)
                        logger.error(msg)
                        logger.exception(e)
                    finally:
                        self._sink_put(sink_socket, sso)
コード例 #21
0
def docker_status():
    o, e, rc = service_status("docker")
    if rc != 0:
        return False
    return True
コード例 #22
0
def docker_status():
    o, e, rc = service_status('docker')
    if (rc != 0):
        return False
    return True
コード例 #23
0
ファイル: samba_service.py プロジェクト: xxl33p/rockstor-core
    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 = {}
                if 'global_config' in config:
                    gc_lines = config['global_config'].split('\n')
                    for l in gc_lines:
                        gc_param = l.strip().split(' = ')
                        if (len(gc_param) == 2):
                            if '=' in gc_param[0]:
                                raise Exception(
                                    'Syntax error, one param has wrong '
                                    'spaces around equal signs, '
                                    'please check syntax of '
                                    '\'%s\'' % ''.join(gc_param))
                            global_config[gc_param[0].strip().lower(
                            )] = gc_param[1].strip()  # noqa
                    # #E501 Default set current workgroup to one got via samba
                    # config page
                    global_config['workgroup'] = config['workgroup']
                else:
                    global_config = config
                # 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 = None
                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 as 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 as e:
                e_msg = ('Failed to %s samba due to a system error: %s' %
                         (command, e.__str__()))
                handle_exception(Exception(e_msg), request)
        return Response()
コード例 #24
0
ファイル: samba_service.py プロジェクト: MFlyer/rockstor-core
    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 = {}
                if 'global_config' in config:
                    gc_lines = config['global_config'].split('\n')
                    for l in gc_lines:
                        gc_param = l.strip().split(' = ')
                        if (len(gc_param) == 2):
                            if '=' in gc_param[0]:
                                raise Exception(
                                    'Syntax error, one param has wrong '
                                    'spaces around equal signs, '
                                    'please check syntax of '
                                    '\'%s\'' % ''.join(gc_param))
                            global_config[gc_param[0].strip().lower()] = gc_param[1].strip()  # noqa
                    # #E501 Default set current workgroup to one got via samba
                    # config page
                    global_config['workgroup'] = config['workgroup']
                else:
                    global_config = config
                # 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 = None
                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 as 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 as e:
                e_msg = ('Failed to %s samba due to a system error: %s'
                         % (command, e.__str__()))
                handle_exception(Exception(e_msg), request)
        return Response()
コード例 #25
0
def docker_status():
    o, e, rc = service_status('docker')
    if (rc != 0):
        return False
    return True
コード例 #26
0
    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 = {}
                if "global_config" in config:
                    gc_lines = config["global_config"].split("\n")
                    for l in gc_lines:
                        gc_param = l.strip().split(" = ")
                        if len(gc_param) == 2:
                            if "=" in gc_param[0]:
                                raise Exception(
                                    "Syntax error, one param has wrong "
                                    "spaces around equal signs, "
                                    "please check syntax of "
                                    "'%s'" % "".join(gc_param))
                            global_config[gc_param[0].strip().lower(
                            )] = gc_param[1].strip()  # noqa
                    # #E501 Default set current workgroup to one got via samba
                    # config page
                    global_config["workgroup"] = config["workgroup"]
                else:
                    global_config = config
                # 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 = None
                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)
                _, _, smb_rc = service_status(self.service_name)
                # Restart samba only if already ON
                # rc == 0 if service is ON, rc != 0 otherwise
                if smb_rc == 0:
                    restart_samba(hard=True)
            except Exception as 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 = "{}.service".format(self.service_name)
                    distro_id = settings.OS_DISTRO_ID
                    self._write_smb_service(systemd_name, distro_id)
                    systemctl("smb", "enable")
                    systemctl("nmb", "enable")
                systemctl("nmb", command)
                systemctl("smb", command)
            except Exception as e:
                e_msg = "Failed to {} samba due to a system error: {}".format(
                    command, e.__str__())
                handle_exception(Exception(e_msg), request)
        return Response()