mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-08-30 23:06:18 +00:00
add cronjob for clear logs files
This commit is contained in:
parent
92d0ee8c01
commit
605895321c
3 changed files with 29 additions and 1 deletions
25
web/job/clear_logs_job.go
Normal file
25
web/job/clear_logs_job.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -253,6 +253,9 @@ func (s *Server) startTask() {
|
||||||
// check client ips from log file every 20 sec
|
// check client ips from log file every 20 sec
|
||||||
s.cron.AddJob("@every 20s", job.NewCheckClientIpJob())
|
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
|
// Make a traffic condition every day, 8:30
|
||||||
var entry cron.EntryID
|
var entry cron.EntryID
|
||||||
isTgbotenabled, err := s.settingService.GetTgbotenabled()
|
isTgbotenabled, err := s.settingService.GetTgbotenabled()
|
||||||
|
|
|
@ -57,7 +57,7 @@ func GetIPLimitBannedLogPath() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAccessPersistentLogPath() string {
|
func GetAccessPersistentLogPath() string {
|
||||||
return config.GetLogFolder() + "/3xui-access-persistent.log"
|
return config.GetLogFolder() + "/3xipl-access-persistent.log"
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAccessLogPath() string {
|
func GetAccessLogPath() string {
|
||||||
|
|
Loading…
Reference in a new issue