• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python services.systemctl函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: post

 def post(self, request, command):
     """
     execute a command on the service
     """
     e_msg = ('Failed to %s S.M.A.R.T service due to system error.' %
              command)
     with self._handle_exception(request, e_msg):
         if (not os.path.exists(SMART)):
             install_pkg('smartmontools')
         if (command == 'config'):
             service = Service.objects.get(name=self.service_name)
             config = request.DATA.get('config', {})
             logger.debug('config = %s' % config)
             self._save_config(service, config)
             if ('smartd_config' in config):
                 config = config['smartd_config']
             else:
                 config = ''
             smart.update_config(config)
             systemctl(self.service_name, 'enable')
             systemctl(self.service_name, 'restart')
         else:
             self._switch(command)
     return Response()
开发者ID:Type-of-iframe,项目名称:rockstor-core,代码行数:24,代码来源:smartd_service.py


示例17: post

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

        if (command == 'config'):
            config = request.data.get('config')
            self._save_config(service, config)
            shelltype = config.get('shelltype')
            css = config.get('css')
            update_shell_config(shelltype, css)
            restart_shell()

        elif (command == 'start'):
            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,代码行数:20,代码来源:shellinaboxd_service.py


示例18: 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:
                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 = ('%s%s' % (settings.MNT_PT, share.name))
            if (not is_share_mounted(share.name)):
                pool_device = Disk.objects.filter(pool=share.pool)[0].name
                mount_share(share, pool_device, mnt_pt)

            inf = ('%s/docker.service' % (settings.CONFROOT))
            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('%s %s\n' % (l.strip(), mnt_pt))
                    else:
                        outo.write(l)
            socket_file = ('%s/docker.socket' % (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:Type-of-iframe,项目名称:rockstor-core,代码行数:39,代码来源:docker_service.py


示例19: 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:
                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 = "%s%s" % (settings.MNT_PT, share.name)
            if not is_share_mounted(share.name):
                mount_share(share, mnt_pt)

            inf = "%s/docker.service" % (settings.CONFROOT)
            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("%s %s\n" % (l.strip(), mnt_pt))
                    else:
                        outo.write(l)
            socket_file = "%s/docker.socket" % (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:Stoney49th,项目名称:rockstor-core,代码行数:37,代码来源:docker_service.py


示例20: update_global_config

 if (command == 'config'):
     #nothing to really configure atm. just save the model
     try:
         config = request.data.get('config', {'workgroup': 'MYGROUP',})
         workgroup = config['workgroup']
         self._save_config(service, config)
         update_global_config(workgroup)
         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' % 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('smb', command)
         systemctl('nmb', command)
     except Exception, e:
         e_msg = ('Failed to %s samba due to a system error: %s' % (command, e.__str__()))
开发者ID:Stoney49th,项目名称:rockstor-core,代码行数:31,代码来源:samba_service.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python manager.StorageManager类代码示例发布时间:2022-05-27
下一篇:
Python process_context.ProcessContext类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap