代码拉取完成,页面将自动刷新
同步操作将从 src-openEuler/A-Tune-Collector 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
From 1c513970f8f5e81268e998cc33ab8a93802bb722 Mon Sep 17 00:00:00 2001
From: gaoruoshu <gaoruoshu@huawei.com>
Date: Fri, 14 Jul 2023 18:47:25 +0800
Subject: [PATCH 10/11] bugfix: create file only if setting params
---
atune_collector/plugin/configurator/mysql/mysql.py | 9 ++++++---
atune_collector/plugin/configurator/nginx/nginx.py | 7 ++++---
atune_collector/plugin/configurator/redis/redis.py | 7 +++++--
3 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/atune_collector/plugin/configurator/mysql/mysql.py b/atune_collector/plugin/configurator/mysql/mysql.py
index cfc533d..e472a1c 100644
--- a/atune_collector/plugin/configurator/mysql/mysql.py
+++ b/atune_collector/plugin/configurator/mysql/mysql.py
@@ -31,8 +31,10 @@ class Mysql(Configurator):
self.__cmd = ""
self.__file_path = "/etc/my.cnf"
self.__mysqld_ind = -1
+
+ def _init_file(self):
if not os.path.isfile(self.__file_path):
- with open(self.__file_path, 'w'):
+ with open(self.__file_path, 'w', 0o644):
pass
os.chmod(self.__file_path, 0o644)
self.__check_mysqld()
@@ -61,7 +63,8 @@ class Mysql(Configurator):
return False, ind
def _set(self, key, value):
- with open(self.__file_path, 'r') as f:
+ self._init_file()
+ with open(self.__file_path, 'r', 0o400) as f:
lines = f.readlines()
key_exist, ind = self.__check_file_exists(lines, key)
@@ -71,7 +74,7 @@ class Mysql(Configurator):
else:
lines[ind] = new_line
- with open(self.__file_path, 'w') as f:
+ with open(self.__file_path, 'w', 0o644) as f:
f.writelines(lines)
return 0
diff --git a/atune_collector/plugin/configurator/nginx/nginx.py b/atune_collector/plugin/configurator/nginx/nginx.py
index 7ab619d..9d38dd0 100644
--- a/atune_collector/plugin/configurator/nginx/nginx.py
+++ b/atune_collector/plugin/configurator/nginx/nginx.py
@@ -42,18 +42,18 @@ class Nginx(Configurator):
os.mkdir(self.__file_dir)
os.chmod(self.__file_dir, 0o755)
if not os.path.isfile(self.__file_path):
- with open(self.__file_path, 'w'):
+ with open(self.__file_path, 'w', 0o644):
pass
os.chmod(self.__file_path, 0o644)
self._set_index()
def _get_lines(self):
- with open(self.__file_path, 'r') as f:
+ with open(self.__file_path, 'r', 0o444) as f:
lines = f.readlines()
return lines
def _set_lines(self, lines):
- with open(self.__file_path, 'w') as f:
+ with open(self.__file_path, 'w', 0o644) as f:
f.writelines(lines)
def _set_index(self):
@@ -209,3 +209,4 @@ def rewrite_value(value):
raise SetConfigError("Failed to get cpu number")
return output.stdout.decode().count("\n")
+
diff --git a/atune_collector/plugin/configurator/redis/redis.py b/atune_collector/plugin/configurator/redis/redis.py
index c56f38e..aa14bcd 100644
--- a/atune_collector/plugin/configurator/redis/redis.py
+++ b/atune_collector/plugin/configurator/redis/redis.py
@@ -34,15 +34,18 @@ class Redis(Configurator):
self.__re = r"^#\?\s*{key}\s* "
self.__file_dir = "/etc/redis/"
self.__file_path = self.__file_dir + "redis.conf"
+
+ def _init_file(self):
if not os.path.isdir(self.__file_dir):
os.mkdir(self.__file_dir)
os.chmod(self.__file_dir, 0o755)
if not os.path.isfile(self.__file_path):
- with open(self.__file_path, 'w', 0o200):
+ with open(self.__file_path, 'w', 0o600):
pass
os.chmod(self.__file_path, 0o644)
def _set(self, key, value):
+ self._init_file()
re_cmd = self.__re.format(key=key)
grep_cmd = [r"grep", re_cmd, self.__file_path]
out, err = self.execute_cmd(grep_cmd)
@@ -51,7 +54,7 @@ class Redis(Configurator):
num_lines = out.count("\n")
new_line = self.__lines.format(key=key, value=value)
if num_lines == 0:
- with open(self.__file_path, 'a', 0o600) as f:
+ with open(self.__file_path, 'a', 0o644) as f:
f.write(new_line + '\n')
elif num_lines == 1:
sed_cmd = [r"sed", "-i", r"s/{}.*$/{}/g".format(re_cmd, new_line), self.__file_path]
--
2.27.0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。