Skip to content

Commit 32b5d4f

Browse files
feat: add website log cleanup option to cache cleaning
1 parent f27a429 commit 32b5d4f

File tree

12 files changed

+66
-21
lines changed

12 files changed

+66
-21
lines changed

agent/app/service/device_clean.go

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ func (u *DeviceService) Clean(req []dto.Clean) {
182182
} else {
183183
dropTaskLog(path.Join(global.Dir.TaskDir, item.Name))
184184
}
185+
case "website_log":
186+
dropWebsiteLog(item.Name)
185187
case "script":
186188
dropFileOrDir(path.Join(global.Dir.TmpDir, "script", item.Name))
187189
case "images":
@@ -621,7 +623,7 @@ func loadLogTree(fileOp fileUtils.FileOp) []dto.CleanTree {
621623
for _, file := range list1 {
622624
size += file.Size
623625
}
624-
treeData = append(treeData, dto.CleanTree{ID: uuid.NewString(), Label: "system_log", Size: uint64(size), Children: list1, Type: "system_log", IsRecommend: true})
626+
treeData = append(treeData, dto.CleanTree{ID: uuid.NewString(), Label: "system_log", Size: size, Children: list1, Type: "system_log", IsRecommend: true})
625627

626628
path2 := path.Join(global.Dir.TaskDir)
627629
list2 := loadTreeWithDir(false, "task_log", path2, fileOp)
@@ -632,9 +634,37 @@ func loadLogTree(fileOp fileUtils.FileOp) []dto.CleanTree {
632634
list3 := loadTreeWithAllFile(true, path3, "script", path3, fileOp)
633635
size3, _ := fileOp.GetDirSize(path3)
634636
treeData = append(treeData, dto.CleanTree{ID: uuid.NewString(), Label: "script", Size: uint64(size3), Children: list3, Type: "script", IsRecommend: true})
637+
638+
websiteLogList := loadWebsiteLogTree(fileOp)
639+
logTotalSize := uint64(0)
640+
for _, websiteLog := range websiteLogList {
641+
logTotalSize += websiteLog.Size
642+
}
643+
treeData = append(treeData, dto.CleanTree{ID: uuid.NewString(), Label: "website_log", Size: logTotalSize, Children: websiteLogList, Type: "website_log", IsRecommend: false})
644+
635645
return treeData
636646
}
637647

648+
func loadWebsiteLogTree(fileOp fileUtils.FileOp) []dto.CleanTree {
649+
websites, _ := websiteRepo.List()
650+
if len(websites) == 0 {
651+
return nil
652+
}
653+
var res []dto.CleanTree
654+
for _, website := range websites {
655+
size3, _ := fileOp.GetDirSize(path.Join(GteSiteDir(website.Alias), "log"))
656+
res = append(res, dto.CleanTree{
657+
ID: uuid.NewString(),
658+
Label: website.PrimaryDomain,
659+
Size: uint64(size3),
660+
IsCheck: size3 > 5*1024,
661+
Type: "website_log",
662+
Name: website.Alias,
663+
})
664+
}
665+
return res
666+
}
667+
638668
func loadContainerTree() []dto.CleanTree {
639669
var treeData []dto.CleanTree
640670
client, err := docker.NewDockerClient()
@@ -849,6 +879,18 @@ func dropVolumes() (int, int) {
849879
return len(res.VolumesDeleted), int(res.SpaceReclaimed)
850880
}
851881

882+
func dropWebsiteLog(alias string) {
883+
accessLogPath := path.Join(GteSiteDir(alias), "log", "access.log")
884+
errorLogPath := path.Join(GteSiteDir(alias), "log", "error.log")
885+
if err := os.Truncate(accessLogPath, 0); err != nil {
886+
global.LOG.Errorf("truncate access log %s failed, err %v", accessLogPath, err)
887+
}
888+
889+
if err := os.Truncate(errorLogPath, 0); err != nil {
890+
global.LOG.Errorf("truncate error log %s failed, err %v", errorLogPath, err)
891+
}
892+
}
893+
852894
func dropTaskLog(logDir string) {
853895
files, err := os.ReadDir(logDir)
854896
if err != nil {

frontend/src/lang/modules/en.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,8 +2221,8 @@ const message = {
22212221
downloadHelper: 'Temporary files downloaded from third-party backup accounts by the system',
22222222
directory: 'Directory',
22232223

2224-
systemLog: 'System Log Files',
2225-
systemLogHelper: 'System log and task log files',
2224+
systemLog: 'Log file',
2225+
systemLogHelper: 'System logs, task logs, website log files',
22262226
dockerLog: 'Container operation log files',
22272227
taskLog: 'Scheduled task execution log files',
22282228
shell: 'Shell script scheduled tasks',

frontend/src/lang/modules/es-es.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,8 +2233,9 @@ const message = {
22332233
download: 'Archivos temporales de descarga',
22342234
downloadHelper: 'Archivos temporales descargados desde respaldos externos',
22352235
directory: 'Directorio',
2236-
systemLog: 'Archivos de log del sistema',
2237-
systemLogHelper: 'Archivos de registro del sistema y de tareas',
2236+
2237+
systemLog: 'Archivo de registro',
2238+
systemLogHelper: 'Registros del sistema, registros de tareas, archivos de registro del sitio web',
22382239
dockerLog: 'Archivos de registro de operaciones de contenedores',
22392240
taskLog: 'Archivos de registro de ejecución de tareas programadas',
22402241
shell: 'Tareas programadas de script de shell',

frontend/src/lang/modules/ja.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,8 +2141,8 @@ const message = {
21412141
downloadHelper: 'システムによってサードパーティのバックアップアカウントからダウンロードされた一時ファイル',
21422142
directory: 'ディレクトリ',
21432143

2144-
systemLog: 'システムログファイル',
2145-
systemLogHelper: 'システムログ、タスクログファイル',
2144+
systemLog: 'ログファイル',
2145+
systemLogHelper: 'システムログ、タスクログ、ウェブサイトログファイル',
21462146
dockerLog: 'コンテナ操作ログファイル',
21472147
taskLog: 'スケジュールタスク実行ログファイル',
21482148
shell: 'シェルスクリプトスケジュールタスク',

frontend/src/lang/modules/ko.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,8 +2105,8 @@ const message = {
21052105
downloadHelper: '시스템에서 제3자 백업 계정으로 다운로드된 임시 파일',
21062106
directory: '디렉터리',
21072107

2108-
systemLog: '시스템 로그 파일',
2109-
systemLogHelper: '시스템 로그, 작업 로그 파일',
2108+
systemLog: '로그 파일',
2109+
systemLogHelper: '시스템 로그, 작업 로그, 웹사이트 로그 파일',
21102110
dockerLog: '컨테이너 작업 로그 파일',
21112111
taskLog: '예약 작업 실행 로그 파일',
21122112
shell: '셸 스크립트 예약 작업',

frontend/src/lang/modules/ms.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,8 +2200,8 @@ const message = {
22002200
downloadHelper: 'Fail sementara dimuat turun dari akaun sandaran pihak ketiga oleh sistem',
22012201
directory: 'Direktori',
22022202

2203-
systemLog: 'Fail Log Sistem',
2204-
systemLogHelper: 'Fail log sistem dan log tugas',
2203+
systemLog: 'Fail log',
2204+
systemLogHelper: 'Log sistem, log tugas, fail log laman web',
22052205
dockerLog: 'Fail log operasi bekas',
22062206
taskLog: 'Fail log pelaksanaan tugas berjadual',
22072207
shell: 'Tugas berjadual skrip Shell',

frontend/src/lang/modules/pt-br.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2194,8 +2194,8 @@ const message = {
21942194
downloadHelper: 'Arquivos temporários baixados de contas de backup de terceiros pelo sistema',
21952195
directory: 'Diretório',
21962196

2197-
systemLog: 'Arquivos de log do sistema',
2198-
systemLogHelper: 'Arquivos de log do sistema e de tarefas',
2197+
systemLog: 'Arquivo de log',
2198+
systemLogHelper: 'Logs do sistema, logs de tarefas, arquivos de log do site',
21992199
dockerLog: 'Arquivos de log de operação de contêineres',
22002200
taskLog: 'Arquivos de log de execução de tarefas agendadas',
22012201
shell: 'Tarefas agendadas de script de shell',

frontend/src/lang/modules/ru.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2189,8 +2189,8 @@ const message = {
21892189
downloadHelper: 'Временные файлы, скачанные из сторонних аккаунтов резервного копирования системой',
21902190
directory: 'Директория',
21912191

2192-
systemLog: 'Системные файлы логов',
2193-
systemLogHelper: 'Файлы системных журналов и журналов задач',
2192+
systemLog: 'Файл журнала',
2193+
systemLogHelper: 'Системные журналы, журналы задач, файлы журналов веб-сайта',
21942194
dockerLog: 'Файлы журналов операций с контейнерами',
21952195
taskLog: 'Файлы журналов выполнения запланированных задач',
21962196
shell: 'Запланированные задачи скриптов оболочки',

frontend/src/lang/modules/tr.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,8 +2246,8 @@ const message = {
22462246
downloadHelper: 'Sistem tarafından üçüncü taraf yedek hesaplarından indirilen geçici dosyalar',
22472247
directory: 'Dizin',
22482248

2249-
systemLog: 'Sistem Günlük Dosyaları',
2250-
systemLogHelper: 'Sistem günlüğü ve görev günlüğü dosyaları',
2249+
systemLog: 'Günlük dosyası',
2250+
systemLogHelper: 'Sistem günlükleri, görev günlükleri, web sitesi günlük dosyaları',
22512251
dockerLog: 'Konteyner işlem günlüğü dosyaları',
22522252
taskLog: 'Zamanlanmış görev yürütme günlüğü dosyaları',
22532253
shell: 'Shell script zamanlanmış görevler',

frontend/src/lang/modules/zh-Hant.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,8 +2070,8 @@ const message = {
20702070
downloadHelper: '系統從第三方備份帳號下載的暫存檔',
20712071
directory: '資料夾',
20722072

2073-
systemLog: '系統日誌檔案',
2074-
systemLogHelper: '系統日誌、任務日誌檔案',
2073+
systemLog: '日誌檔案',
2074+
systemLogHelper: '系統日誌、任務日誌、網站日誌檔案',
20752075
dockerLog: '容器操作日誌檔案',
20762076
taskLog: '計劃任務執行日誌檔案',
20772077
shell: 'Shell 腳本計劃任務',

0 commit comments

Comments
 (0)