def update_acl(self): acl_dir = _get_acl_dir() acl_files = self.kwargs.get('acl_files', []) filenames = {filename: os.path.join(acl_dir, filename) for filename in acl_files} for acl_file, acl_path in filenames.items(): # 生成新的配置文件 content = DnsdbApi.get_acl_content(acl_file)['data'] with open('{}.tmp'.format(acl_path), 'w') as f: f.write(content) # 重新加载配置 if can_reload(self.group_name): tmp_conf_dict = {} for acl_file in filenames.values(): # 备份原来配置文件 backup_file('acl', acl_file) back = acl_file + '.bak' shutil.copy(acl_file, back) # 拷贝新的配置文件 shutil.copy('{}.tmp'.format(acl_file), acl_file) tmp_conf_dict[acl_file] = back # 检查文件语法 try: check_named_conf(_get_named_path()) except UpdaterErr as e: # 配置文件还原 for conf_file, back in tmp_conf_dict.items(): shutil.copy(back, conf_file) raise reload_conf()
def update_acl(self): acl_dir = _get_acl_dir() acl_files = self.kwargs.get('acl_files', []) filenames = { filename: os.path.join(acl_dir, filename) for filename in acl_files } for acl_file, acl_path in filenames.items(): # 生成新的配置文件 content = DnsdbApi.get_acl_content(acl_file)['data'] with open('{}.tmp'.format(acl_path), 'w') as f: f.write(content) # 重新加载配置 if can_reload(self.group_name): tmp_conf_dict = {} for acl_file in filenames.values(): # 备份原来配置文件 backup_file('acl', acl_file) back = acl_file + '.bak' shutil.copy(acl_file, back) # 拷贝新的配置文件 shutil.copy('{}.tmp'.format(acl_file), acl_file) tmp_conf_dict[acl_file] = back # 检查文件语法 try: check_named_conf(_get_named_path()) except UpdaterErr as e: # 配置文件还原 for conf_file, back in tmp_conf_dict.items(): shutil.copy(back, conf_file) raise reload_conf()
def copy_named_conf(named_file): named_path = _get_named_path() # 备份 backup_file('named', named_path) status, output = commands.getstatusoutput( 'cp %s %s && chown named:named %s' % (named_file, named_path, named_path)) if status == 0: log.info('update name.conf ok') else: raise UpdaterErr('copy_named_conf failed: %s' % output)
def copy_named_conf(named_file): named_path = _get_named_path() # 备份 backup_file('named', named_path) status, output = commands.getstatusoutput( f'cp {named_file} {named_path} && chown {CONF.bind_default.user}:{CONF.bind_default.group} {named_path}' ) if status == 0: log.info('update name.conf ok') else: raise UpdaterErr('copy_named_conf failed: %s' % output)