refactor:修改tsg-diagnose日志的删除方式由脚本变为tmpfile

This commit is contained in:
fumingwei
2021-09-07 11:15:43 +08:00
parent ae20a31190
commit c07659be19
4 changed files with 4 additions and 46 deletions

View File

@@ -24,6 +24,7 @@ set(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/cmake/PostunInstall
install(FILES compose/docker-compose.yml DESTINATION ./compose)
install(FILES images_build/client/dign_client/etc/client.conf DESTINATION ./etc)
install(FILES service/tsg-diagnose.service DESTINATION /usr/lib/systemd/system)
install(FILES service/tsg-diagnose.conf DESTINATION /usr/lib/tmpfiles.d)
install(FILES images_build/server_dns/config/dnsmasq.conf DESTINATION /opt/tsg/tsg-diagnose/etc/)
install(DIRECTORY images/ DESTINATION ./images)

View File

@@ -85,9 +85,6 @@ services:
cp -rf /opt/dign_client/etc/certs_import/certs/sets/current/gen/crt/ca-root.crt /usr/local/share/ca-certificates
update-ca-certificates
cat /opt/dign_client/etc/hosts >> /etc/hosts
echo '0 2 * * * /usr/local/bin/python /opt/dign_client/clear_file_timeout.py' > /etc/crontabs/root
echo '0 2 * * * /usr/local/bin/python /opt/dign_client/clear_file_timeout.py -d /opt/dign_client/log/conn_traffic_status' > /etc/crontabs/root
crond
tail -f /dev/null

View File

@@ -1,43 +0,0 @@
import os
import sys
import time
import argparse
def get_suite_option():
parser = argparse.ArgumentParser(description="Tsg diagnose Tools - clear tsg diagnose result file", epilog = "Example:help")
parser.add_argument('-t','--timeout', type = int, default = 604800,help='Specify the time to delete files that are not accessed in seconds ,the default is 604800 (7 days)')
parser.add_argument('-d','--dictpath', type = str, default = '/opt/dign_client/log/dign_client', help='Specify the folder to delete files, the default is /opt/dign_client/log/dign_client')
args = parser.parse_args()
return args
def clear_dict_file(dictpath, timeout):
try:
files = os.listdir(dictpath)
if not files:
print("The directory not exist, the process will exit")
sys.exit(0)
for file in files:
filePath = dictpath + "/" + file
if os.path.isfile(filePath):
last = int(os.stat(filePath).st_mtime)
now = int(time.time())
if (now - last >= timeout):
os.remove(filePath)
print(filePath + " was removed!")
elif os.path.isdir(filePath):
clear_dict_file(filePath,timeout)
if not os.listdir(filePath):
os.rmdir(filePath)
except Exception as ex:
print("Process get an exception, will exit, Exception info: ", ex)
sys.stdout.write(str(ex))
sys.exit(1)
if __name__ == '__main__':
args = get_suite_option()
timeout = args.timeout
dictpath = args.dictpath
clear_dict_file(dictpath, timeout)

View File

@@ -0,0 +1,3 @@
#Type Path Mode User Group Age Argument
d /var/log/tsg-diagnose/ 0755 - - 2d -
L /opt/tsg/tsg-diagnose/log - - - - /var/log/tsg-diagnose