Skip to content

CasaOS - A simple, easy-to-use, elegant open-source Personal Cloud system.

wip

Tiger Wang182bc25343c9
diff --git a/build/sysroot/usr/lib/systemd/system/casaos.service b/build/sysroot/usr/lib/systemd/system/casaos.service
index 249d72c..aa7ad32 100644
--- a/build/sysroot/usr/lib/systemd/system/casaos.service
+++ b/build/sysroot/usr/lib/systemd/system/casaos.service
@@ -1,12 +1,13 @@
[Unit]
After=casaos-gateway.service
ConditionFileNotEmpty=/etc/casaos/casaos.conf
-Description=CasaOS Service
+Description=CasaOS Main Service
[Service]
ExecStart=/usr/bin/casaos -c /etc/casaos/casaos.conf
PIDFile=/var/run/casaos/casaos.pid
Restart=always
+Type=notify
[Install]
WantedBy=multi-user.target
diff --git a/go.mod b/go.mod
index cfcc59b..db9ca62 100644
--- a/go.mod
+++ b/go.mod
@@ -11,6 +11,7 @@ require (
github.com/ambelovsky/gosf v0.0.0-20201109201340-237aea4d6109
github.com/ambelovsky/gosf-socketio v0.0.0-20201109193639-add9d32f8b19 // indirect
github.com/containerd/containerd v1.5.7 // indirect
+ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e
github.com/disintegration/imaging v1.6.2
github.com/docker/distribution v2.8.0+incompatible // indirect
github.com/docker/docker v20.10.7+incompatible
diff --git a/main.go b/main.go
index 32b1c01..ede006d 100644
--- a/main.go
+++ b/main.go
@@ -18,6 +18,7 @@ import (
"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"
@@ -135,14 +136,6 @@ 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()
urlFilePath := filepath.Join(config.CommonInfo.RuntimePath, "casaos.url")
err = file.CreateFileAndWriteContent(urlFilePath, "http://"+listener.Addr().String())
if err != nil {
@@ -152,7 +145,20 @@ func main() {
)
}
- err = http.Serve(listener, r)
+ 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)
}
diff --git a/types/system.go b/types/system.go
index 24ef182..e77a7d6 100644
--- a/types/system.go
+++ b/types/system.go
@@ -1,15 +1,14 @@
-/*
- * @Author: LinkLeong [email protected]
- * @Date: 2022-02-17 18:53:22
- * @LastEditors: LinkLeong
- * @LastEditTime: 2022-09-06 14:27:42
- * @FilePath: /CasaOS/types/system.go
- * @Description:
- * @Website: https://www.casaos.io
- * Copyright (c) 2022 by icewhale, All Rights Reserved.
+/*@Author: LinkLeong [email protected]
+ *@Date: 2022-02-17 18:53:22
+ *@LastEditors: LinkLeong
+ *@LastEditTime: 2022-09-06 14:27:42
+ *@FilePath: /CasaOS/types/system.go
+ *@Description:
+ *@Website: https://www.casaos.io
+ *Copyright (c) 2022 by icewhale, All Rights Reserved.
*/
package types
-const CURRENTVERSION = "0.3.6"
+const CURRENTVERSION = "0.3.7"
const BODY = " "