2024-07-23 14:48:37 +08:00
|
|
|
package global
|
|
|
|
|
|
|
|
|
|
import (
|
2025-09-28 18:18:17 +08:00
|
|
|
"context"
|
2026-07-15 15:53:44 +08:00
|
|
|
"sync"
|
2025-09-28 18:18:17 +08:00
|
|
|
|
2024-11-26 22:04:31 +08:00
|
|
|
badger_db "github.com/1Panel-dev/1Panel/agent/init/cache/db"
|
2024-07-23 14:48:37 +08:00
|
|
|
"github.com/go-playground/validator/v10"
|
|
|
|
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
|
|
|
|
"github.com/robfig/cron/v3"
|
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
2026-11-09 14:17:47 +08:00
|
|
|
DB *gorm.DB
|
|
|
|
|
MonitorDB *gorm.DB
|
|
|
|
|
GPUMonitorDB *gorm.DB
|
|
|
|
|
TaskDB *gorm.DB
|
|
|
|
|
CoreDB *gorm.DB
|
|
|
|
|
AlertDB *gorm.DB
|
2025-01-24 11:00:07 +08:00
|
|
|
|
|
|
|
|
LOG *logrus.Logger
|
|
|
|
|
CONF ServerConfig
|
|
|
|
|
VALID *validator.Validate
|
|
|
|
|
CACHE *badger_db.Cache
|
|
|
|
|
Viper *viper.Viper
|
|
|
|
|
|
|
|
|
|
Dir SystemDir
|
2024-07-23 14:48:37 +08:00
|
|
|
|
2026-11-09 14:17:47 +08:00
|
|
|
Cron *cron.Cron
|
|
|
|
|
MonitorCronID cron.EntryID
|
|
|
|
|
GPUMonitorCronID cron.EntryID
|
2024-07-23 14:48:37 +08:00
|
|
|
|
2026-11-10 20:56:28 +08:00
|
|
|
CleanupVLLMMonitor func(uint) error
|
|
|
|
|
|
2024-08-14 10:15:55 +08:00
|
|
|
IsMaster bool
|
2024-07-29 14:13:47 +08:00
|
|
|
|
2024-07-23 14:48:37 +08:00
|
|
|
I18n *i18n.Localizer
|
2025-07-18 11:44:20 +08:00
|
|
|
|
|
|
|
|
AlertBaseJobID cron.EntryID
|
|
|
|
|
AlertResourceJobID cron.EntryID
|
2025-09-28 18:18:17 +08:00
|
|
|
|
|
|
|
|
TaskCtxMap = make(map[string]context.CancelFunc)
|
2026-07-15 15:53:44 +08:00
|
|
|
taskCtxMu sync.RWMutex
|
2024-07-23 14:48:37 +08:00
|
|
|
)
|
2026-02-25 10:56:06 +08:00
|
|
|
|
2026-07-15 15:53:44 +08:00
|
|
|
func RegisterTaskCancel(taskID string, cancel context.CancelFunc) {
|
|
|
|
|
taskCtxMu.Lock()
|
|
|
|
|
defer taskCtxMu.Unlock()
|
|
|
|
|
TaskCtxMap[taskID] = cancel
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func LoadTaskCancel(taskID string) (context.CancelFunc, bool) {
|
|
|
|
|
taskCtxMu.RLock()
|
|
|
|
|
defer taskCtxMu.RUnlock()
|
|
|
|
|
cancel, ok := TaskCtxMap[taskID]
|
|
|
|
|
return cancel, ok
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func RemoveTaskCancel(taskID string) {
|
|
|
|
|
taskCtxMu.Lock()
|
|
|
|
|
defer taskCtxMu.Unlock()
|
|
|
|
|
delete(TaskCtxMap, taskID)
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-25 10:56:06 +08:00
|
|
|
func RepoURL() string {
|
2026-05-07 09:53:28 +08:00
|
|
|
if CONF.Base.IsEnterprise {
|
|
|
|
|
return "https://resource.fit2cloud.com/1panel/package/enterprise"
|
|
|
|
|
}
|
2026-02-27 15:17:51 +08:00
|
|
|
if CONF.Base.Edition != "intl" {
|
2026-02-25 10:56:06 +08:00
|
|
|
return "https://resource.fit2cloud.com/1panel/package/v2"
|
|
|
|
|
}
|
2026-03-02 12:05:59 +08:00
|
|
|
return "https://resource.1panel.pro/v2"
|
2026-02-25 10:56:06 +08:00
|
|
|
}
|
|
|
|
|
func ResourceURL() string {
|
2026-05-07 09:53:28 +08:00
|
|
|
if CONF.Base.IsEnterprise {
|
2026-05-18 16:49:31 +08:00
|
|
|
return "https://resource.fit2cloud.com/1panel/resource/v2"
|
2026-05-07 09:53:28 +08:00
|
|
|
}
|
2026-02-27 15:17:51 +08:00
|
|
|
if CONF.Base.Edition != "intl" {
|
2026-02-25 10:56:06 +08:00
|
|
|
return "https://resource.fit2cloud.com/1panel/resource/v2"
|
|
|
|
|
}
|
2026-03-02 12:05:59 +08:00
|
|
|
return "https://resource.1panel.pro/v2/resource"
|
2026-02-25 10:56:06 +08:00
|
|
|
}
|
|
|
|
|
func AppRepoURL() string {
|
2026-05-07 09:53:28 +08:00
|
|
|
if CONF.Base.IsEnterprise {
|
|
|
|
|
return "https://apps-assets.fit2cloud.com"
|
|
|
|
|
}
|
2026-02-27 15:17:51 +08:00
|
|
|
if CONF.Base.Edition != "intl" {
|
2026-02-25 10:56:06 +08:00
|
|
|
return "https://apps-assets.fit2cloud.com"
|
|
|
|
|
}
|
2026-03-03 15:20:02 +08:00
|
|
|
return "https://apps.1panel.pro"
|
2026-02-25 10:56:06 +08:00
|
|
|
}
|