Remount if the configuration file already exists (#877)
This commit is contained in:
parent
b331c484f5
commit
fbfcc2c43a
9 changed files with 25 additions and 26 deletions
|
@ -1,5 +1,6 @@
|
||||||
[Unit]
|
[Unit]
|
||||||
After=casaos-message-bus.service
|
After=casaos-message-bus.service
|
||||||
|
After=rclone.service
|
||||||
ConditionFileNotEmpty=/etc/casaos/casaos.conf
|
ConditionFileNotEmpty=/etc/casaos/casaos.conf
|
||||||
Description=CasaOS Main Service
|
Description=CasaOS Main Service
|
||||||
|
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -42,6 +42,7 @@ require (
|
||||||
go.uber.org/zap v1.24.0
|
go.uber.org/zap v1.24.0
|
||||||
golang.org/x/crypto v0.5.0
|
golang.org/x/crypto v0.5.0
|
||||||
golang.org/x/oauth2 v0.3.0
|
golang.org/x/oauth2 v0.3.0
|
||||||
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
|
||||||
gorm.io/gorm v1.24.3
|
gorm.io/gorm v1.24.3
|
||||||
gotest.tools v2.2.0+incompatible
|
gotest.tools v2.2.0+incompatible
|
||||||
)
|
)
|
||||||
|
|
1
go.sum
1
go.sum
|
@ -323,6 +323,7 @@ golang.org/x/oauth2 v0.3.0 h1:6l90koy8/LaBLmLu8jpHeHexzMwEita0zFfYlggy2F8=
|
||||||
golang.org/x/oauth2 v0.3.0/go.mod h1:rQrIauxkUhJ6CuwEXwymO2/eh4xz2ZWF1nBkcxS+tGk=
|
golang.org/x/oauth2 v0.3.0/go.mod h1:rQrIauxkUhJ6CuwEXwymO2/eh4xz2ZWF1nBkcxS+tGk=
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
|
1
main.go
1
main.go
|
@ -147,7 +147,6 @@ func main() {
|
||||||
route.V2APIPath,
|
route.V2APIPath,
|
||||||
route.V2DocPath,
|
route.V2DocPath,
|
||||||
route.V3FilePath,
|
route.V3FilePath,
|
||||||
route.V4DirPath,
|
|
||||||
}
|
}
|
||||||
for _, apiPath := range routers {
|
for _, apiPath := range routers {
|
||||||
err = service.MyService.Gateway().CreateRoute(&model.Route{
|
err = service.MyService.Gateway().CreateRoute(&model.Route{
|
||||||
|
|
|
@ -66,9 +66,10 @@ func SendAllHardwareStatusBySocket() {
|
||||||
|
|
||||||
body["sys_net"] = newNet
|
body["sys_net"] = newNet
|
||||||
systemTempMap := service.MyService.Notify().GetSystemTempMap()
|
systemTempMap := service.MyService.Notify().GetSystemTempMap()
|
||||||
for k, v := range systemTempMap {
|
systemTempMap.Range(func(key, value interface{}) bool {
|
||||||
body[k] = v
|
body[key.(string)] = value
|
||||||
}
|
return true
|
||||||
|
})
|
||||||
service.MyService.Notify().SendNotify("casaos:system:utilization", body)
|
service.MyService.Notify().SendNotify("casaos:system:utilization", body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,12 +58,8 @@ func GetRecoverStorage(c *gin.Context) {
|
||||||
username = fileutil.NameAccumulation(username, "/mnt")
|
username = fileutil.NameAccumulation(username, "/mnt")
|
||||||
dataMap, _ := service.MyService.Storage().GetConfigByName(username)
|
dataMap, _ := service.MyService.Storage().GetConfigByName(username)
|
||||||
if len(dataMap) > 0 {
|
if len(dataMap) > 0 {
|
||||||
c.String(200, `<p>The same configuration has been added</p><script>window.close()</script>`)
|
service.MyService.Storage().UnmountStorage("/mnt/" + username)
|
||||||
service.MyService.Storage().CheckAndMountByName(username)
|
service.MyService.Storage().DeleteConfigByName(username)
|
||||||
notify["status"] = "warn"
|
|
||||||
notify["message"] = "The same configuration has been added"
|
|
||||||
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
dmap := make(map[string]string)
|
dmap := make(map[string]string)
|
||||||
dmap["client_id"] = add.ClientID
|
dmap["client_id"] = add.ClientID
|
||||||
|
@ -115,12 +111,8 @@ func GetRecoverStorage(c *gin.Context) {
|
||||||
username = fileutil.NameAccumulation(username, "/mnt")
|
username = fileutil.NameAccumulation(username, "/mnt")
|
||||||
dataMap, _ := service.MyService.Storage().GetConfigByName(username)
|
dataMap, _ := service.MyService.Storage().GetConfigByName(username)
|
||||||
if len(dataMap) > 0 {
|
if len(dataMap) > 0 {
|
||||||
c.String(200, `<p>The same configuration has been added</p><script>window.close()</script>`)
|
service.MyService.Storage().UnmountStorage("/mnt/" + username)
|
||||||
service.MyService.Storage().CheckAndMountByName(username)
|
service.MyService.Storage().DeleteConfigByName(username)
|
||||||
notify["status"] = "warn"
|
|
||||||
notify["message"] = "The same configuration has been added"
|
|
||||||
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
dmap := make(map[string]string)
|
dmap := make(map[string]string)
|
||||||
dmap["client_id"] = add.AppKey
|
dmap["client_id"] = add.AppKey
|
||||||
|
|
|
@ -232,9 +232,11 @@ func GetSystemUtilization(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
data["net"] = newNet
|
data["net"] = newNet
|
||||||
for k, v := range service.MyService.Notify().GetSystemTempMap() {
|
systemMap := service.MyService.Notify().GetSystemTempMap()
|
||||||
data[k] = v
|
systemMap.Range(func(key, value interface{}) bool {
|
||||||
}
|
data[key.(string)] = value
|
||||||
|
return true
|
||||||
|
})
|
||||||
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: data})
|
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: data})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,8 +69,8 @@ func InitV2Router() http.Handler {
|
||||||
|
|
||||||
e.Use(echo_middleware.JWTWithConfig(echo_middleware.JWTConfig{
|
e.Use(echo_middleware.JWTWithConfig(echo_middleware.JWTConfig{
|
||||||
Skipper: func(c echo.Context) bool {
|
Skipper: func(c echo.Context) bool {
|
||||||
// return c.RealIP() == "::1" || c.RealIP() == "127.0.0.1"
|
return c.RealIP() == "::1" || c.RealIP() == "127.0.0.1"
|
||||||
return true
|
//return true
|
||||||
},
|
},
|
||||||
ParseTokenFunc: func(token string, c echo.Context) (interface{}, error) {
|
ParseTokenFunc: func(token string, c echo.Context) (interface{}, error) {
|
||||||
claims, code := jwt.Validate(token)
|
claims, code := jwt.Validate(token)
|
||||||
|
|
|
@ -15,6 +15,7 @@ import (
|
||||||
"github.com/IceWhaleTech/CasaOS/service/model"
|
"github.com/IceWhaleTech/CasaOS/service/model"
|
||||||
"github.com/IceWhaleTech/CasaOS/types"
|
"github.com/IceWhaleTech/CasaOS/types"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
"golang.org/x/sync/syncmap"
|
||||||
|
|
||||||
socketio "github.com/googollee/go-socket.io"
|
socketio "github.com/googollee/go-socket.io"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
|
@ -36,17 +37,18 @@ type NotifyServer interface {
|
||||||
//SendInstallAppBySocket(app notifyCommon.Application)
|
//SendInstallAppBySocket(app notifyCommon.Application)
|
||||||
SendNotify(name string, message map[string]interface{})
|
SendNotify(name string, message map[string]interface{})
|
||||||
SettingSystemTempData(message map[string]interface{})
|
SettingSystemTempData(message map[string]interface{})
|
||||||
GetSystemTempMap() map[string]interface{}
|
GetSystemTempMap() syncmap.Map
|
||||||
}
|
}
|
||||||
|
|
||||||
type notifyServer struct {
|
type notifyServer struct {
|
||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
SystemTempMap map[string]interface{}
|
SystemTempMap syncmap.Map //[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *notifyServer) SettingSystemTempData(message map[string]interface{}) {
|
func (i *notifyServer) SettingSystemTempData(message map[string]interface{}) {
|
||||||
for k, v := range message {
|
for k, v := range message {
|
||||||
i.SystemTempMap[k] = v
|
i.SystemTempMap.Store(k, v)
|
||||||
|
//i.SystemTempMap[k] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,10 +342,10 @@ func SendMeg() {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// }
|
// }
|
||||||
func (i *notifyServer) GetSystemTempMap() map[string]interface{} {
|
func (i *notifyServer) GetSystemTempMap() syncmap.Map {
|
||||||
return i.SystemTempMap
|
return i.SystemTempMap
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNotifyService(db *gorm.DB) NotifyServer {
|
func NewNotifyService(db *gorm.DB) NotifyServer {
|
||||||
return ¬ifyServer{db: db, SystemTempMap: make(map[string]interface{})}
|
return ¬ifyServer{db: db, SystemTempMap: syncmap.Map{}}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue