fix: Initialize the script library when the service starts (#8626)

This commit is contained in:
ssongliu
2025-05-14 04:18:27 +00:00
committed by GitHub
parent 6ecfb1f239
commit 404e551f7b
3 changed files with 23 additions and 6 deletions
+2 -2
View File
@@ -195,7 +195,7 @@ func (u *ScriptService) Sync(req dto.OperateByTaskID) error {
syncTask.Log("start to download data.yaml")
dataUrl := fmt.Sprintf("%s/scripts/data.yaml", global.CONF.RemoteURL.ResourceURL)
_, dataRes, err := req_helper.HandleRequest(dataUrl, http.MethodGet, constant.TimeOut20s)
_, dataRes, err := req_helper.HandleRequestWithProxy(dataUrl, http.MethodGet, constant.TimeOut20s)
if err != nil {
return fmt.Errorf("load scripts data.yaml from remote failed, err: %v", err)
}
@@ -213,7 +213,7 @@ func (u *ScriptService) Sync(req dto.OperateByTaskID) error {
_ = os.MkdirAll(tmpDir, 0755)
}
scriptsUrl := fmt.Sprintf("%s/scripts/scripts.tar.gz", global.CONF.RemoteURL.ResourceURL)
if err := files.DownloadFile(scriptsUrl, tmpDir+"/scripts.tar.gz"); err != nil {
if err := files.DownloadFileWithProxy(scriptsUrl, tmpDir+"/scripts.tar.gz"); err != nil {
return fmt.Errorf("download scripts.tar.gz failed, err: %v", err)
}
syncTask.Log("download successful! now start to decompress...")
+13
View File
@@ -0,0 +1,13 @@
package run
import (
"github.com/1Panel-dev/1Panel/core/app/dto"
"github.com/1Panel-dev/1Panel/core/app/service"
"github.com/1Panel-dev/1Panel/core/global"
)
func Init() {
if err := service.NewIScriptService().Sync(dto.OperateByTaskID{}); err != nil {
global.LOG.Errorf("sync scripts from remote failed, err: %v", err)
}
}
+8 -4
View File
@@ -4,15 +4,17 @@ import (
"crypto/tls"
"encoding/gob"
"fmt"
"github.com/1Panel-dev/1Panel/core/init/db"
"github.com/1Panel-dev/1Panel/core/init/geo"
"github.com/1Panel-dev/1Panel/core/init/log"
"github.com/1Panel-dev/1Panel/core/init/migration"
"net"
"net/http"
"os"
"path"
"github.com/1Panel-dev/1Panel/core/init/db"
"github.com/1Panel-dev/1Panel/core/init/geo"
"github.com/1Panel-dev/1Panel/core/init/log"
"github.com/1Panel-dev/1Panel/core/init/migration"
"github.com/1Panel-dev/1Panel/core/init/run"
"github.com/1Panel-dev/1Panel/core/constant"
"github.com/1Panel-dev/1Panel/core/global"
"github.com/1Panel-dev/1Panel/core/i18n"
@@ -42,6 +44,8 @@ func Start() {
hook.Init()
InitOthers()
run.Init()
rootRouter := router.Routers()
tcpItem := "tcp4"