portainer

This commit is contained in:
qiaofeng1227 2024-07-29 11:02:59 +08:00
parent 4eac811022
commit 25e70a3b0d
2 changed files with 18 additions and 6 deletions

View file

@ -1,4 +1,4 @@
# modify time: 202404101102, you can modify here to trigger Docker Build action # modify time: 202407291102, you can modify here to trigger Docker Build action
# step1: Build entrypoint execute program init_portainer by golang # step1: Build entrypoint execute program init_portainer by golang
FROM golang:latest AS builder FROM golang:latest AS builder

View file

@ -34,12 +34,19 @@ func main() {
// 检查初始化标志文件是否存在 // 检查初始化标志文件是否存在
if _, err := os.Stat(initFlagFilePath); err == nil { if _, err := os.Stat(initFlagFilePath); err == nil {
log.Println("Initialization has already been completed by another instance.") log.Println("Initialization has already been completed by another instance.")
startPortainer(os.Args[1:]...) startPortainer()
return return
} }
// 启动 Portainer // 启动 Portainer
startPortainer(os.Args[1:]...) // cmd := exec.Command("/portainer")
cmd := exec.Command("/portainer", os.Args[1:]...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Start(); err != nil {
log.Fatalf("Failed to start Portainer: %v", err)
}
// 等待 Portainer 启动 // 等待 Portainer 启动
waitForPortainer() waitForPortainer()
@ -65,10 +72,15 @@ func main() {
} }
} }
} }
// 等待 Portainer 进程结束
if err := cmd.Wait(); err != nil {
log.Fatalf("Portainer process exited with error: %v", err)
}
} }
func startPortainer(args ...string) { func startPortainer() {
cmd := exec.Command("/portainer", args...) cmd := exec.Command("/portainer")
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr