feat(self-check): add Docker socket existence check

This commit is contained in:
Jacky 2025-04-22 14:14:23 +00:00
parent 3944be2369
commit 7dfb6e86e6
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
8 changed files with 48 additions and 2 deletions

View file

@ -9,3 +9,14 @@ import (
func InNginxUIOfficialDocker() bool {
return cast.ToBool(os.Getenv("NGINX_UI_OFFICIAL_DOCKER"))
}
func DockerSocketExists() bool {
if !InNginxUIOfficialDocker() {
return false
}
_, err := os.Stat("/var/run/docker.sock")
if os.IsNotExist(err) {
return false
}
return true
}

View file

@ -0,0 +1,17 @@
package self_check
import (
"github.com/0xJacky/Nginx-UI/internal/helper"
)
func CheckDockerSocket() error {
if !helper.InNginxUIOfficialDocker() {
return nil
}
if !helper.DockerSocketExists() {
return ErrDockerSocketNotExist
}
return nil
}

View file

@ -17,4 +17,5 @@ var (
ErrStreamAvailableNotExist = e.New(4048, "Streams-available directory not exist")
ErrStreamEnabledNotExist = e.New(4049, "Streams-enabled directory not exist")
ErrNginxConfNotIncludeConfD = e.New(4050, "Nginx conf not include conf.d directory")
ErrDockerSocketNotExist = e.New(4051, "Docker socket not exist")
)

View file

@ -3,6 +3,7 @@ package self_check
import (
"errors"
"github.com/0xJacky/Nginx-UI/internal/helper"
"github.com/uozi-tech/cosy"
)
@ -53,6 +54,12 @@ func init() {
for _, task := range selfCheckTasks {
selfCheckTaskMap[task.Name] = task
}
if helper.InNginxUIOfficialDocker() {
selfCheckTasks = append(selfCheckTasks, &Task{
Name: "Docker-Socket",
CheckFunc: CheckDockerSocket,
})
}
}
func Run() (reports Reports) {