diff --git a/backend/app/dto/setting.go b/backend/app/dto/setting.go
index 1de8d8129..423e84c57 100644
--- a/backend/app/dto/setting.go
+++ b/backend/app/dto/setting.go
@@ -30,6 +30,7 @@ type SettingInfo struct {
ServerPort string `json:"serverPort"`
SSL string `json:"ssl"`
SSLType string `json:"sslType"`
+ AutoRestart string `json:"autoRestart"`
BindDomain string `json:"bindDomain"`
AllowIPs string `json:"allowIPs"`
SecurityEntrance string `json:"securityEntrance"`
@@ -73,12 +74,13 @@ type SettingUpdate struct {
}
type SSLUpdate struct {
- SSLType string `json:"sslType" validate:"required,oneof=self select import import-paste import-local"`
- Domain string `json:"domain"`
- SSL string `json:"ssl" validate:"required,oneof=enable disable"`
- Cert string `json:"cert"`
- Key string `json:"key"`
- SSLID uint `json:"sslID"`
+ SSLType string `json:"sslType" validate:"required,oneof=self select import import-paste import-local"`
+ Domain string `json:"domain"`
+ SSL string `json:"ssl" validate:"required,oneof=enable disable"`
+ Cert string `json:"cert"`
+ Key string `json:"key"`
+ SSLID uint `json:"sslID"`
+ AutoRestart string `json:"autoRestart"`
}
type SSLInfo struct {
Domain string `json:"domain"`
diff --git a/backend/app/service/setting.go b/backend/app/service/setting.go
index 0bbf3b68b..80296049a 100644
--- a/backend/app/service/setting.go
+++ b/backend/app/service/setting.go
@@ -322,6 +322,9 @@ func (u *SettingService) UpdateSSL(c *gin.Context, req dto.SSLUpdate) error {
if err := settingRepo.Update("SSL", req.SSL); err != nil {
return err
}
+ if err := settingRepo.Update("AutoRestart", req.AutoRestart); err != nil {
+ return err
+ }
sID, _ := c.Cookie(constant.SessionName)
c.SetCookie(constant.SessionName, sID, 0, "", "", true, true)
diff --git a/backend/app/service/website_utils.go b/backend/app/service/website_utils.go
index 5bdf02413..e6380678a 100644
--- a/backend/app/service/website_utils.go
+++ b/backend/app/service/website_utils.go
@@ -3,7 +3,6 @@ package service
import (
"encoding/json"
"fmt"
- "github.com/1Panel-dev/1Panel/backend/utils/xpack"
"log"
"os"
"path"
@@ -13,6 +12,8 @@ import (
"strings"
"time"
+ "github.com/1Panel-dev/1Panel/backend/utils/xpack"
+
"github.com/1Panel-dev/1Panel/backend/buserr"
"github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/backend/i18n"
@@ -1001,20 +1002,23 @@ func saveCertificateFile(websiteSSL *model.WebsiteSSL, logger *log.Logger) {
}
}
-func GetSystemSSL() (bool, uint) {
+func GetSystemSSL() (bool, bool, uint) {
sslSetting, err := settingRepo.Get(settingRepo.WithByKey("SSL"))
if err != nil {
global.LOG.Errorf("load service ssl from setting failed, err: %v", err)
- return false, 0
+ return false, false, 0
}
if sslSetting.Value == "enable" {
sslID, _ := settingRepo.Get(settingRepo.WithByKey("SSLID"))
idValue, _ := strconv.Atoi(sslID.Value)
- if idValue > 0 {
- return true, uint(idValue)
+ if idValue <= 0 {
+ return false, false, 0
}
+
+ auto, _ := settingRepo.Get(settingRepo.WithByKey("AutoRestart"))
+ return true, auto.Value == "enable", uint(idValue)
}
- return false, 0
+ return false, false, 0
}
func UpdateSSLConfig(websiteSSL model.WebsiteSSL) error {
@@ -1033,7 +1037,7 @@ func UpdateSSLConfig(websiteSSL model.WebsiteSSL) error {
return buserr.WithErr(constant.ErrSSLApply, err)
}
}
- enable, sslID := GetSystemSSL()
+ enable, auto, sslID := GetSystemSSL()
if enable && sslID == websiteSSL.ID {
fileOp := files.NewFileOp()
secretDir := path.Join(global.CONF.System.BaseDir, "1panel/secret")
@@ -1045,6 +1049,9 @@ func UpdateSSLConfig(websiteSSL model.WebsiteSSL) error {
global.LOG.Errorf("Failed to update the SSL certificate for 1Panel System domain [%s] , err:%s", websiteSSL.PrimaryDomain, err.Error())
return err
}
+ if auto {
+ _, _ = cmd.Exec("systemctl restart 1panel.service")
+ }
}
return nil
}
diff --git a/backend/cron/job/ssl.go b/backend/cron/job/ssl.go
index 5349deb67..f6f906516 100644
--- a/backend/cron/job/ssl.go
+++ b/backend/cron/job/ssl.go
@@ -10,6 +10,7 @@ import (
"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/utils/cmd"
"github.com/1Panel-dev/1Panel/backend/utils/common"
"github.com/1Panel-dev/1Panel/backend/utils/files"
)
@@ -22,7 +23,7 @@ func NewSSLJob() *ssl {
}
func (ssl *ssl) Run() {
- systemSSLEnable, sslID := service.GetSystemSSL()
+ systemSSLEnable, auto, sslID := service.GetSystemSSL()
sslRepo := repo.NewISSLRepo()
sslService := service.NewIWebsiteSSLService()
sslList, _ := sslRepo.List()
@@ -70,6 +71,9 @@ func (ssl *ssl) Run() {
global.LOG.Errorf("Failed to update the SSL certificate for 1Panel System domain [%s] , err:%s", s.PrimaryDomain, err.Error())
continue
}
+ if auto {
+ _, _ = cmd.Exec("systemctl restart 1panel.service")
+ }
}
global.LOG.Infof("The SSL certificate for the [%s] domain has been successfully updated", s.PrimaryDomain)
}
diff --git a/backend/init/migration/migrate.go b/backend/init/migration/migrate.go
index faa3ce419..b2c472009 100644
--- a/backend/init/migration/migrate.go
+++ b/backend/init/migration/migrate.go
@@ -95,6 +95,8 @@ func Init() {
migrations.AddClamStatus,
migrations.AddAlertMenu,
migrations.AddComposeColumn,
+
+ migrations.AddAutoRestart,
})
if err := m.Migrate(); err != nil {
global.LOG.Error(err)
diff --git a/backend/init/migration/migrations/v_1_10.go b/backend/init/migration/migrations/v_1_10.go
index 2915606b1..4a10469ff 100644
--- a/backend/init/migration/migrations/v_1_10.go
+++ b/backend/init/migration/migrations/v_1_10.go
@@ -324,3 +324,13 @@ var AddComposeColumn = &gormigrate.Migration{
return nil
},
}
+
+var AddAutoRestart = &gormigrate.Migration{
+ ID: "20241021-add-auto-restart",
+ Migrate: func(tx *gorm.DB) error {
+ if err := tx.Create(&model.Setting{Key: "AutoRestart", Value: "enable"}).Error; err != nil {
+ return err
+ }
+ return nil
+ },
+}
diff --git a/frontend/src/api/interface/setting.ts b/frontend/src/api/interface/setting.ts
index 2e60ce791..1dc0da83c 100644
--- a/frontend/src/api/interface/setting.ts
+++ b/frontend/src/api/interface/setting.ts
@@ -29,6 +29,7 @@ export namespace Setting {
bindAddress: string;
ssl: string;
sslType: string;
+ autoRestart: string;
allowIPs: string;
bindDomain: string;
securityEntrance: string;
diff --git a/frontend/src/components/log-dialog/index.vue b/frontend/src/components/log-dialog/index.vue
index ba01b1ce1..0e70c5301 100644
--- a/frontend/src/components/log-dialog/index.vue
+++ b/frontend/src/components/log-dialog/index.vue
@@ -4,6 +4,7 @@
:destroy-on-close="true"
:close-on-click-modal="false"
:close-on-press-escape="false"
+ :before-close="handleClose"
:size="globalStore.isFullScreen ? '100%' : '50%'"
>
@@ -21,10 +22,10 @@