mirror of
https://github.com/IceWhaleTech/CasaOS.git
synced 2025-12-22 12:38:45 +00:00
v0.3.7 (#600)
* add send notify function * add shell script * add system notiry * remove disk and test common package * update http status * add share function to common * remove temp path * remove /DATA directory initialization - moved to local-storage (#578) * update goreleaser configuration * wip * change service type to notify for systemd so its status is OK only when service is initialized successfully * update CasaOS-Common to fix runtime error * wip * add send notify function * add shell script * add system notiry * remove disk and test common package * update http status * add share function to common * remove temp path * remove /DATA directory initialization - moved to local-storage (#578) * update goreleaser configuration * wip * change service type to notify for systemd so its status is OK only when service is initialized successfully * update CasaOS-Common to fix runtime error * wip * wip * wip * wip * wip * Utilization interface to supplement disk information * fix upload file * wip * wip * add update url * wip * wip * add change log * update changelog Co-authored-by: LinkLeong <a624669980@163.com>
This commit is contained in:
69
main.go
69
main.go
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/IceWhaleTech/CasaOS-Gateway/common"
|
||||
@@ -12,10 +13,13 @@ import (
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/cache"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/sqlite"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/file"
|
||||
"github.com/IceWhaleTech/CasaOS/pkg/utils/loger"
|
||||
"github.com/IceWhaleTech/CasaOS/route"
|
||||
"github.com/IceWhaleTech/CasaOS/service"
|
||||
"github.com/IceWhaleTech/CasaOS/types"
|
||||
"github.com/coreos/go-systemd/daemon"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/robfig/cron"
|
||||
"gorm.io/gorm"
|
||||
@@ -25,9 +29,11 @@ const LOCALHOST = "127.0.0.1"
|
||||
|
||||
var sqliteDB *gorm.DB
|
||||
|
||||
var configFlag = flag.String("c", "", "config address")
|
||||
var dbFlag = flag.String("db", "", "db path")
|
||||
var versionFlag = flag.Bool("v", false, "version")
|
||||
var (
|
||||
configFlag = flag.String("c", "", "config address")
|
||||
dbFlag = flag.String("db", "", "db path")
|
||||
versionFlag = flag.Bool("v", false, "version")
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.Parse()
|
||||
@@ -36,7 +42,6 @@ func init() {
|
||||
return
|
||||
}
|
||||
config.InitSetup(*configFlag)
|
||||
config.UpdateSetup()
|
||||
|
||||
loger.LogInit()
|
||||
if len(*dbFlag) == 0 {
|
||||
@@ -44,7 +49,7 @@ func init() {
|
||||
}
|
||||
|
||||
sqliteDB = sqlite.GetDb(*dbFlag)
|
||||
//gredis.GetRedisConn(config.RedisInfo),
|
||||
// gredis.GetRedisConn(config.RedisInfo),
|
||||
|
||||
service.MyService = service.NewService(sqliteDB, config.CommonInfo.RuntimePath)
|
||||
|
||||
@@ -57,7 +62,6 @@ func init() {
|
||||
|
||||
// go service.LoopFriend()
|
||||
// go service.MyService.App().CheckNewImage()
|
||||
|
||||
}
|
||||
|
||||
// @title casaOS API
|
||||
@@ -77,22 +81,21 @@ func main() {
|
||||
return
|
||||
}
|
||||
go route.SocketInit(service.NotifyMsg)
|
||||
go route.MonitoryUSB()
|
||||
//model.Setup()
|
||||
//gredis.Setup()
|
||||
// model.Setup()
|
||||
// gredis.Setup()
|
||||
|
||||
r := route.InitRouter()
|
||||
//service.SyncTask(sqliteDB)
|
||||
// service.SyncTask(sqliteDB)
|
||||
cron2 := cron.New()
|
||||
//every day execution
|
||||
// every day execution
|
||||
|
||||
err := cron2.AddFunc("0/5 * * * * *", func() {
|
||||
if service.ClientCount > 0 {
|
||||
//route.SendNetINfoBySocket()
|
||||
//route.SendCPUBySocket()
|
||||
//route.SendMemBySocket()
|
||||
// route.SendNetINfoBySocket()
|
||||
// route.SendCPUBySocket()
|
||||
// route.SendMemBySocket()
|
||||
// route.SendDiskBySocket()
|
||||
//route.SendUSBBySocket()
|
||||
// route.SendUSBBySocket()
|
||||
route.SendAllHardwareStatusBySocket()
|
||||
}
|
||||
})
|
||||
@@ -107,7 +110,7 @@ func main() {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
routers := []string{"sys", "apps", "container", "app-categories", "port", "file", "folder", "batch", "image", "disks", "storage", "samba"}
|
||||
routers := []string{"sys", "apps", "container", "app-categories", "port", "file", "folder", "batch", "image", "samba", "notify"}
|
||||
for _, v := range routers {
|
||||
err = service.MyService.Gateway().CreateRoute(&common.Route{
|
||||
Path: "/v1/" + v,
|
||||
@@ -121,7 +124,7 @@ func main() {
|
||||
}
|
||||
go func() {
|
||||
time.Sleep(time.Second * 2)
|
||||
//v0.3.6
|
||||
// v0.3.6
|
||||
if config.ServerInfo.HttpPort != "" {
|
||||
changePort := common.ChangePortRequest{}
|
||||
changePort.Port = config.ServerInfo.HttpPort
|
||||
@@ -133,15 +136,29 @@ func main() {
|
||||
}
|
||||
}()
|
||||
|
||||
// s := &http.Server{
|
||||
// Addr: listener.Addr().String(), //fmt.Sprintf(":%v", config.ServerInfo.HttpPort),
|
||||
// Handler: r,
|
||||
// ReadTimeout: 60 * time.Second,
|
||||
// WriteTimeout: 60 * time.Second,
|
||||
// MaxHeaderBytes: 1 << 20,
|
||||
// }
|
||||
// s.ListenAndServe()
|
||||
err = http.Serve(listener, r)
|
||||
urlFilePath := filepath.Join(config.CommonInfo.RuntimePath, "casaos.url")
|
||||
err = file.CreateFileAndWriteContent(urlFilePath, "http://"+listener.Addr().String())
|
||||
if err != nil {
|
||||
loger.Error("Management service is listening...",
|
||||
zap.Any("address", listener.Addr().String()),
|
||||
zap.Any("filepath", urlFilePath),
|
||||
)
|
||||
}
|
||||
|
||||
if supported, err := daemon.SdNotify(false, daemon.SdNotifyReady); err != nil {
|
||||
loger.Error("Failed to notify systemd that casaos main service is ready", zap.Any("error", err))
|
||||
} else if supported {
|
||||
loger.Info("Notified systemd that casaos main service is ready")
|
||||
} else {
|
||||
loger.Info("This process is not running as a systemd service.")
|
||||
}
|
||||
|
||||
s := &http.Server{
|
||||
Handler: r,
|
||||
ReadHeaderTimeout: 5 * time.Second, // fix G112: Potential slowloris attack (see https://github.com/securego/gosec)
|
||||
}
|
||||
|
||||
err = s.Serve(listener) // not using http.serve() to fix G114: Use of net/http serve function that has no support for setting timeouts (see https://github.com/securego/gosec)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user