add cronjob for clear logs files

This commit is contained in:
Hamidreza Ghavami 2023-06-27 19:54:46 +04:30
parent 92d0ee8c01
commit 605895321c
No known key found for this signature in database
GPG key ID: 402C6797325182D9
3 changed files with 29 additions and 1 deletions

25
web/job/clear_logs_job.go Normal file
View file

@ -0,0 +1,25 @@
package job
import (
"os"
"x-ui/logger"
"x-ui/xray"
)
type ClearLogsJob struct{}
func NewClearLogsJob() *ClearLogsJob {
return new(ClearLogsJob)
}
// Here Run is an interface method of the Job interface
func (j *ClearLogsJob) Run() {
logFiles := []string{xray.GetIPLimitLogPath(), xray.GetIPLimitBannedLogPath(), xray.GetAccessPersistentLogPath()}
// clear log files
for i := 0; i < len(logFiles); i++ {
if err := os.Truncate(logFiles[i], 0); err != nil {
logger.Warning("clear logs job err:", err)
}
}
}

View file

@ -253,6 +253,9 @@ func (s *Server) startTask() {
// check client ips from log file every 20 sec
s.cron.AddJob("@every 20s", job.NewCheckClientIpJob())
// check client ips from log file every 3 day
s.cron.AddJob("@every 3d", job.NewClearLogsJob())
// Make a traffic condition every day, 8:30
var entry cron.EntryID
isTgbotenabled, err := s.settingService.GetTgbotenabled()

View file

@ -57,7 +57,7 @@ func GetIPLimitBannedLogPath() string {
}
func GetAccessPersistentLogPath() string {
return config.GetLogFolder() + "/3xui-access-persistent.log"
return config.GetLogFolder() + "/3xipl-access-persistent.log"
}
func GetAccessLogPath() string {