当前位置: 首页>>代码示例>>Python>>正文


Python services.systemctl函数代码示例

本文整理汇总了Python中system.services.systemctl函数的典型用法代码示例。如果您正苦于以下问题:Python systemctl函数的具体用法?Python systemctl怎么用?Python systemctl使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了systemctl函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: delete

 def delete(self, request):
     update_sasl('', '', '', revert=True)
     update_forward('', revert=True)
     update_postfix('', revert=True)
     systemctl('postfix', 'restart')
     EmailClient.objects.all().delete()
     return Response()
开发者ID:WebSpider,项目名称:rockstor-core,代码行数:7,代码来源:email.py

示例2: post

    def post(self, request, command=None):
        with self._handle_exception(request):

            if (command is not None):
                if (command != 'send-test-email'):
                    e_msg = ('unknown command(%s) is not supported.' %
                             command)
                    handle_exception(Exception(e_msg), request)

                if (EmailClient.objects.count() == 0):
                    e_msg = ('E-mail account must be setup first before test '
                             'e-mail could be sent')
                    handle_exception(Exception(e_msg), request)

                eco = EmailClient.objects.all()[0]
                subject = ('Test message from Rockstor. Appliance id: %s' %
                           Appliance.objects.get(current_appliance=True).uuid)
                send_test_email(eco, subject)
                return Response()

            sender = request.data.get('sender')
            username = sender.split('@')[0]
            smtp_server = request.data.get('smtp_server')
            name = request.data.get('name')
            password = request.data.get('password')
            receiver = request.data.get('receiver')
            eco = EmailClient(smtp_server=smtp_server, name=name, sender=sender, receiver=receiver)
            eco.save()
            update_sasl(smtp_server, sender, password)
            update_forward(receiver)
            update_generic(sender)
            update_postfix(smtp_server)
            systemctl('postfix', 'restart')
            return Response(EmailClientSerializer(eco).data)
开发者ID:Mchakravartula,项目名称:rockstor-core,代码行数:34,代码来源:email_client.py

示例3: post

    def post(self, request, command=None):
        with self._handle_exception(request):

            commands_list = ['send-test-email', 'check-smtp-auth']
            if (command is not None):
                if (command not in commands_list):
                    e_msg = ('unknown command(%s) is not supported.' %
                             command)
                    handle_exception(Exception(e_msg), request)

                if (command == 'send-test-email'):
                    if (EmailClient.objects.count() == 0):
                        e_msg = ('E-mail account must be setup first before '
                                 'test e-mail could be sent')
                        handle_exception(Exception(e_msg), request)

                    eco = EmailClient.objects.all()[0]
                    subject = ('Test message from Rockstor. Appliance id: %s' %
                               Appliance.objects.get(current_appliance=True).uuid)  # noqa E501
                    send_test_email(eco, subject)
                    return Response()

                elif (command == 'check-smtp-auth'):
                    mail_auth = {}
                    sender = request.data.get('sender')
                    username = request.data.get('username')
                    mail_auth['username'] = sender if not username else username  # noqa E501
                    mail_auth['password'] = request.data.get('password')
                    mail_auth['smtp_server'] = request.data.get('smtp_server')
                    mail_auth['port'] = int(request.data.get('port', 587))

                    return Response(
                        json.dumps({'smtp_auth': test_smtp_auth(mail_auth)}),
                        content_type="application/json")

            sender = request.data.get('sender')
            # collect new username field
            username = request.data.get('username')
            # smtp auth - use username or if empty use sender
            username = sender if not username else username
            smtp_server = request.data.get('smtp_server')
            port = int(request.data.get('port', 587))
            name = request.data.get('name')
            password = request.data.get('password')
            receiver = request.data.get('receiver')
            eco = EmailClient(smtp_server=smtp_server, port=port, name=name,
                              sender=sender, receiver=receiver,
                              username=username)
            eco.save()
            update_sasl(smtp_server, port, username, password)
            update_forward(receiver)
            update_generic(sender)
            update_postfix(smtp_server, port)
            systemctl('postfix', 'restart')
            return Response(EmailClientSerializer(eco).data)
开发者ID:priyaganti,项目名称:rockstor-core,代码行数:55,代码来源:email_client.py

示例4: _switch_ntpd

 def _switch_ntpd(switch):
     if (switch == 'start'):
         systemctl('ntpd', 'enable')
         systemctl('ntpd', 'start')
     else:
         systemctl('ntpd', 'disable')
         systemctl('ntpd', 'stop')
开发者ID:YukihitoHARA,项目名称:rockstor-core,代码行数:7,代码来源:ntp_service.py

示例5: _switch_snmp

 def _switch_snmp(cls, switch):
     if (switch == 'start'):
         systemctl(cls.service_name, 'enable')
         systemctl(cls.service_name, 'start')
     else:
         systemctl(cls.service_name, 'disable')
         systemctl(cls.service_name, 'stop')
开发者ID:Ajunboys,项目名称:rockstor-core,代码行数:7,代码来源:snmp_service.py

示例6: post

    def post(self, request, command):
        """
        execute a command on the service
        """
        service = Service.objects.get(name='nfs')
        service_name = 'nfs-server'
        if (command == 'config'):
            # nothing to really configure atm. just save the model
            try:
                config = request.data['config']
                self._save_config(service, config)
            except Exception as e:
                e_msg = ('NFS could not be configured due to the following '
                         'exception. You could try again. %s' % e.__str__())
                handle_exception(Exception(e_msg), request)

        else:
            try:
                if (command == 'stop'):
                    systemctl(service_name, 'disable')
                    systemctl(service_name, 'stop')
                else:
                    systemctl(service_name, 'enable')
                    # chkconfig('rpcbind', 'on')
                    # init_service_op('rpcbind', command)
                    systemctl(service_name, 'restart')
                # init_service_op('nfs', command)
            except Exception as e:
                e_msg = ('Failed to %s NFS due to this error: %s'
                         % (command, e.__str__()))
                handle_exception(Exception(e_msg), request)

        return Response()
开发者ID:MFlyer,项目名称:rockstor-core,代码行数:33,代码来源:nfs_service.py

示例7: post

 def post(self, request):
     with self._handle_exception(request):
         sender = request.data.get('sender')
         username = sender.split('@')[0]
         smtp_server = request.data.get('smtp_server')
         name = request.data.get('name')
         password = request.data.get('password')
         receiver = request.data.get('receiver')
         eco = EmailClient(smtp_server=smtp_server, name=name, sender=sender, receiver=receiver)
         eco.save()
         update_sasl(smtp_server, sender, password)
         update_forward(receiver)
         update_postfix(smtp_server)
         systemctl('postfix', 'restart')
         return Response(EmailClientSerializer(eco).data)
开发者ID:WebSpider,项目名称:rockstor-core,代码行数:15,代码来源:email.py

示例8: _refresh_and_reload

 def _refresh_and_reload(request):
     try:
         refresh_afp_config(list(NetatalkShare.objects.all()))
         return systemctl('netatalk', 'reload-or-restart')
     except Exception as e:
         e_msg = ('Failed to reload Netatalk server. Exception: %s' % e.__str__())
         handle_exception(Exception(e_msg), request)
开发者ID:sfranzen,项目名称:rockstor-core,代码行数:7,代码来源:netatalk.py

示例9: _refresh_and_reload

 def _refresh_and_reload(request):
     try:
         refresh_afp_config(list(NetatalkShare.objects.all()))
         return systemctl('netatalk', 'reload')
     except Exception, e:
         logger.exception(e)
         e_msg = ('System error occured while reloading Netatalk server')
         handle_exception(Exception(e_msg), request)
开发者ID:Type-of-iframe,项目名称:rockstor-core,代码行数:8,代码来源:netatalk.py

示例10: post

    def post(self, request, command):
        service = Service.objects.get(name=self.name)

        if command == 'config':
            config = request.data.get('config', None)
            root_share = config['root_share']
            self._validate_root(request, root_share)
            self._save_config(service, config)

        elif command == 'start':
            try:
                config = self._get_config(service)
            except Exception as e:
                logger.exception(e)
                e_msg = ('Cannot start without configuration. '
                         'Please configure (System->Services) and try again.')
                handle_exception(Exception(e_msg), request)

            share = self._validate_root(request, config['root_share'])
            mnt_pt = '{}{}'.format(settings.MNT_PT, share.name)
            if not share.is_mounted:
                mount_share(share, mnt_pt)

            docker_wrapper = '{}bin/docker-wrapper'.format(settings.ROOT_DIR)
            distro_id = distro.id()  # for Leap 15 <--> Tumbleweed moves.
            if distro_id not in KNOWN_DISTRO_IDS:
                distro_id = 'generic'
            # TODO: Consider sourcing /usr/lib/systemd/system/docker.service
            inf = '{}/docker-{}.service'.format(settings.CONFROOT, distro_id)
            outf = '/etc/systemd/system/docker.service'
            with open(inf) as ino, open(outf, 'w') as outo:
                for l in ino.readlines():
                    if re.match('ExecStart=', l) is not None:
                        outo.write('{} {}\n'.format(
                            l.strip().replace(DOCKERD, docker_wrapper, 1),
                            mnt_pt))
                    elif re.match('Type=notify', l) is not None:
                        # Our docker wrapper use need NotifyAccess=all: avoids
                        # "Got notification message from PID ####1, but
                        # reception only permitted for main PID ####2"
                        outo.write(l)
                        outo.write('NotifyAccess=all\n')
                    elif re.match('After=', l) is not None:
                        outo.write('{} {}\n'.format(
                            l.strip(), 'rockstor-bootstrap.service'))
                    else:
                        outo.write(l)
            if distro_id == 'rockstor':
                socket_file = '{}/docker.socket'.format(settings.CONFROOT)
                shutil.copy(socket_file, '/etc/systemd/system/docker.socket')
            systemctl(self.name, 'enable')
            systemctl(self.name, 'start')
        elif command == 'stop':
            systemctl(self.name, 'stop')
            systemctl(self.name, 'disable')
        return Response()
开发者ID:MFlyer,项目名称:rockstor-core,代码行数:56,代码来源:docker_service.py

示例11: _rockon_check

    def _rockon_check(request, sname, force):
        s = Service.objects.get(name='docker')
        if (s.config is None):
            return

        config = json.loads(s.config)
        if (config.get('root_share') == sname):
            if (force):
                #turn off docker service, nullify config.
                systemctl(s.name, 'stop')
                systemctl(s.name, 'disable')
                s.config = None
                return s.save()
            e_msg = ('Share(%s) cannot be deleted because it is in use '
                     'by Rock-on service. If you must delete anyway, select '
                     'the force checkbox and try again.' % sname)
            handle_exception(Exception(e_msg), request)
开发者ID:Lorgne,项目名称:rockstor-core,代码行数:17,代码来源:share.py

示例12: post

    def post(self, request, command):
        service = Service.objects.get(name=self.name)

        if (command == 'start'):
            systemctl(self.name, 'enable')
            systemctl(self.name, 'start')
        elif (command == 'stop'):
            systemctl(self.name, 'stop')
            systemctl(self.name, 'disable')
        return Response()
开发者ID:Ajunboys,项目名称:rockstor-core,代码行数:10,代码来源:bootstrap_service.py

示例13: post

    def post(self, request):
        if ('shares' not in request.data):
            e_msg = ('Must provide share names')
            handle_exception(Exception(e_msg), request)

        shares = [validate_share(s, request) for s in request.data['shares']]
        description = request.data.get('description', '')
        if (description == ''):
            description = self.def_description

        time_machine = request.data.get('time_machine', 'yes')
        if (time_machine != 'yes' and time_machine != 'no'):
            e_msg = ('time_machine must be yes or now. not %s' %
                     time_machine)
            handle_exception(Exception(e_msg), request)

        for share in shares:
            if (NetatalkShare.objects.filter(share=share).exists()):
                e_msg = ('Share(%s) is already exported via AFP' % share.name)
                handle_exception(Exception(e_msg), request)

        try:
            for share in shares:
                mnt_pt = ('%s%s' % (settings.MNT_PT, share.name))
                cur_description = '%s %s' % (share.name, description)
                if (len(shares) == 1 and description != self.def_description):
                    cur_description = description
                afpo = NetatalkShare(share=share, path=mnt_pt,
                                     description=cur_description,
                                     time_machine=time_machine)
                afpo.save()
                if (not is_share_mounted(share.name)):
                    pool_device = Disk.objects.filter(pool=share.pool)[0].name
                    mount_share(share, pool_device, mnt_pt)
            refresh_afp_config(list(NetatalkShare.objects.all()))
            systemctl('netatalk', 'reload')
            return Response()
        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)
开发者ID:Type-of-iframe,项目名称:rockstor-core,代码行数:41,代码来源:netatalk.py

示例14: _rockon_check

    def _rockon_check(request, sname, force):
        s = Service.objects.get(name='docker')
        if (s.config is None):
            return

        config = json.loads(s.config)
        if (config.get('root_share') == sname):
            if (force):
                # turn off docker service, nullify config.
                systemctl(s.name, 'stop')
                systemctl(s.name, 'disable')
                s.config = None
                s.save()

                # delete all rockon metadata.
                RockOn.objects.all().delete()
                return
            e_msg = ('Share ({}) cannot be deleted because it is in use '
                     'by the Rock-on service. To override this block select '
                     'the force checkbox and try again.').format(sname)
            handle_exception(Exception(e_msg), request)
开发者ID:MFlyer,项目名称:rockstor-core,代码行数:21,代码来源:share.py

示例15: _update_sssd

 def _update_sssd(domain):
     #add enumerate = True in sssd so user/group lists will be
     #visible on the web-ui.
     el = 'enumerate = True\n'
     fh, npath = mkstemp()
     sssd_config = '/etc/sssd/sssd.conf'
     with open(sssd_config) as sfo, open(npath, 'w') as tfo:
         domain_section = False
         for line in sfo.readlines():
             if (domain_section is True):
                 if (len(line.strip()) == 0 or line[0] == '['):
                     #empty line or new section without empty line before it.
                     tfo.write(el)
                     domain_section = False
             elif (re.match('\[domain/%s]' % domain, line) is not None):
                 domain_section = True
             tfo.write(line)
         if (domain_section is True):
             #reached end of file, also coinciding with end of domain section
             tfo.write(el)
     shutil.move(npath, sssd_config)
     systemctl('sssd', 'restart')
开发者ID:Mchakravartula,项目名称:rockstor-core,代码行数:22,代码来源:active_directory.py


注:本文中的system.services.systemctl函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。