1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-02-28 02:54:13 +08:00

fix: 解决证书定时任务错误执行的问题 ()

This commit is contained in:
zhengkunwang223 2023-04-13 08:24:32 +08:00 committed by GitHub
parent 0356bdbf54
commit a5be9ca226
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,7 +3,6 @@ package job
import ( import (
"github.com/1Panel-dev/1Panel/backend/app/repo" "github.com/1Panel-dev/1Panel/backend/app/repo"
"github.com/1Panel-dev/1Panel/backend/app/service" "github.com/1Panel-dev/1Panel/backend/app/service"
"github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/global"
"time" "time"
) )
@ -19,19 +18,22 @@ func (ssl *ssl) Run() {
sslRepo := repo.NewISSLRepo() sslRepo := repo.NewISSLRepo()
sslService := service.NewIWebsiteSSLService() sslService := service.NewIWebsiteSSLService()
sslList, _ := sslRepo.List() sslList, _ := sslRepo.List()
global.LOG.Info("ssl renew cron job start...") global.LOG.Info("The scheduled certificate update task is currently in progress ...")
now := time.Now().Add(10 * time.Second) now := time.Now().Add(10 * time.Second)
for _, s := range sslList { for _, s := range sslList {
if !s.AutoRenew || s.Provider == "manual" || s.Provider == "dnsManual" { if !s.AutoRenew || s.Provider == "manual" || s.Provider == "dnsManual" {
continue continue
} }
expireDate, _ := time.ParseInLocation(constant.DateTimeLayout, s.ExpireDate.String(), time.Now().Location()) expireDate := s.ExpireDate.In(time.Now().Location())
sum := expireDate.Sub(now) sub := expireDate.Sub(now)
if sum.Hours() < 720 { if sub.Hours() < 720 {
global.LOG.Errorf("Update the SSL certificate for the [%s] domain", s.PrimaryDomain)
if err := sslService.Renew(s.ID); err != nil { if err := sslService.Renew(s.ID); err != nil {
global.LOG.Errorf("renew doamin [%s] ssl failed err:%s", s.PrimaryDomain, err.Error()) global.LOG.Errorf("Failed to update the SSL certificate for the [%s] domain , err:%s", s.PrimaryDomain, err.Error())
continue
} }
global.LOG.Errorf("The SSL certificate for the [%s] domain has been successfully updated", s.PrimaryDomain)
} }
} }
global.LOG.Info("ssl renew cron job end...") global.LOG.Info("The scheduled certificate update task has completed")
} }