mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-12-20 06:18:56 +08:00
fix: 1pctl 数据库路径修改
This commit is contained in:
parent
9d0b731730
commit
deca1d01d3
3 changed files with 33 additions and 4 deletions
|
|
@ -45,6 +45,9 @@ func Init() {
|
||||||
if len(baseDir) == 0 {
|
if len(baseDir) == 0 {
|
||||||
panic("error `BASE_DIR` find in /usr/bin/1pctl")
|
panic("error `BASE_DIR` find in /usr/bin/1pctl")
|
||||||
}
|
}
|
||||||
|
if strings.HasSuffix(baseDir, "/") {
|
||||||
|
baseDir = baseDir[:strings.LastIndex(baseDir, "/")]
|
||||||
|
}
|
||||||
reader := bytes.NewReader(conf.AppYaml)
|
reader := bytes.NewReader(conf.AppYaml)
|
||||||
if err := v.ReadConfig(reader); err != nil {
|
if err := v.ReadConfig(reader); err != nil {
|
||||||
panic(fmt.Errorf("Fatal error config file: %s \n", err))
|
panic(fmt.Errorf("Fatal error config file: %s \n", err))
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,10 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/backend/global"
|
"github.com/1Panel-dev/1Panel/backend/global"
|
||||||
|
cmdUtils "github.com/1Panel-dev/1Panel/backend/utils/cmd"
|
||||||
"github.com/1Panel-dev/1Panel/backend/utils/encrypt"
|
"github.com/1Panel-dev/1Panel/backend/utils/encrypt"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"gorm.io/driver/sqlite"
|
"gorm.io/driver/sqlite"
|
||||||
|
|
@ -18,8 +20,19 @@ var userinfoCmd = &cobra.Command{
|
||||||
Use: "user-info",
|
Use: "user-info",
|
||||||
Short: "获取用户信息",
|
Short: "获取用户信息",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
fullPath := "/opt/1panel/db/1Panel.db"
|
stdout, err := cmdUtils.Exec("grep '^BASE_DIR=' /usr/bin/1pctl | cut -d'=' -f2")
|
||||||
db, err := gorm.Open(sqlite.Open(fullPath), &gorm.Config{})
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
baseDir := strings.ReplaceAll(stdout, "\n", "")
|
||||||
|
if len(baseDir) == 0 {
|
||||||
|
fmt.Printf("error `BASE_DIR` find in /usr/bin/1pctl \n")
|
||||||
|
}
|
||||||
|
if strings.HasSuffix(baseDir, "/") {
|
||||||
|
baseDir = baseDir[:strings.LastIndex(baseDir, "/")]
|
||||||
|
}
|
||||||
|
|
||||||
|
db, err := gorm.Open(sqlite.Open(baseDir+"/1panel/db/1Panel.db"), &gorm.Config{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("init my db conn failed, err: %v \n", err)
|
fmt.Printf("init my db conn failed, err: %v \n", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
cmdUtils "github.com/1Panel-dev/1Panel/backend/utils/cmd"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"gorm.io/driver/sqlite"
|
"gorm.io/driver/sqlite"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
|
@ -16,8 +18,19 @@ var versionCmd = &cobra.Command{
|
||||||
Use: "version",
|
Use: "version",
|
||||||
Short: "获取系统版本信息",
|
Short: "获取系统版本信息",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
fullPath := "/opt/1panel/db/1Panel.db"
|
stdout, err := cmdUtils.Exec("grep '^BASE_DIR=' /usr/bin/1pctl | cut -d'=' -f2")
|
||||||
db, err := gorm.Open(sqlite.Open(fullPath), &gorm.Config{})
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
baseDir := strings.ReplaceAll(stdout, "\n", "")
|
||||||
|
if len(baseDir) == 0 {
|
||||||
|
fmt.Printf("error `BASE_DIR` find in /usr/bin/1pctl \n")
|
||||||
|
}
|
||||||
|
if strings.HasSuffix(baseDir, "/") {
|
||||||
|
baseDir = baseDir[:strings.LastIndex(baseDir, "/")]
|
||||||
|
}
|
||||||
|
|
||||||
|
db, err := gorm.Open(sqlite.Open(baseDir+"/1panel/db/1Panel.db"), &gorm.Config{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("init my db conn failed, err: %v \n", err)
|
fmt.Printf("init my db conn failed, err: %v \n", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue