1Panel/backend/init/app/app.go

46 lines
1.5 KiB
Go
Raw Normal View History

2022-11-21 11:27:56 +08:00
package app
import (
"github.com/1Panel-dev/1Panel/backend/utils/docker"
2024-06-15 22:28:03 +08:00
"github.com/1Panel-dev/1Panel/backend/utils/firewall"
"path"
2022-11-21 11:27:56 +08:00
"github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/backend/global"
2022-11-21 11:27:56 +08:00
"github.com/1Panel-dev/1Panel/backend/utils/files"
)
func Init() {
constant.DataDir = global.CONF.System.DataDir
constant.ResourceDir = path.Join(constant.DataDir, "resource")
2022-11-21 11:27:56 +08:00
constant.AppResourceDir = path.Join(constant.ResourceDir, "apps")
constant.AppInstallDir = path.Join(constant.DataDir, "apps")
constant.RuntimeDir = path.Join(constant.DataDir, "runtime")
2022-11-21 11:27:56 +08:00
2023-05-16 17:31:47 +08:00
constant.LocalAppResourceDir = path.Join(constant.AppResourceDir, "local")
constant.LocalAppInstallDir = path.Join(constant.AppInstallDir, "local")
constant.RemoteAppResourceDir = path.Join(constant.AppResourceDir, "remote")
2023-11-20 16:16:20 +08:00
constant.SSLLogDir = path.Join(global.CONF.System.DataDir, "log", "ssl")
2023-05-16 17:31:47 +08:00
dirs := []string{constant.DataDir, constant.ResourceDir, constant.AppResourceDir, constant.AppInstallDir,
2023-11-20 16:16:20 +08:00
global.CONF.System.Backup, constant.RuntimeDir, constant.LocalAppResourceDir, constant.RemoteAppResourceDir, constant.SSLLogDir}
2022-11-21 11:27:56 +08:00
fileOp := files.NewFileOp()
for _, dir := range dirs {
createDir(fileOp, dir)
}
_ = docker.CreateDefaultDockerNetwork()
2024-06-15 22:28:03 +08:00
if f, err := firewall.NewFirewallClient(); err == nil {
_ = f.EnableForward()
}
2022-11-21 11:27:56 +08:00
}
func createDir(fileOp files.FileOp, dirPath string) {
if !fileOp.Stat(dirPath) {
_ = fileOp.CreateDir(dirPath, 0755)
}
}