Skip to content

Commit 4700dd1

Browse files
committed
Improve socket bind verification and PID file retry handling in process supervisor
1 parent 098e956 commit 4700dd1

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

‎internal/supervisor/supervisor.go‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -526,16 +526,20 @@ func (s *Supervisor) startNginx() (ServiceStatus, error) {
526526
}
527527

528528
func readPIDFile(path string) int {
529-
data, err := os.ReadFile(path)
530-
if err != nil {
531-
return 0
529+
for i := 0; i < 10; i++ {
530+
data, err := os.ReadFile(path)
531+
if err == nil {
532+
if pid, _ := strconv.Atoi(strings.TrimSpace(string(data))); pid > 0 {
533+
return pid
534+
}
535+
}
536+
time.Sleep(100 * time.Millisecond)
532537
}
533-
pid, _ := strconv.Atoi(strings.TrimSpace(string(data)))
534-
return pid
538+
return 0
535539
}
536540

537541
func (s *Supervisor) startPHPCGI(port int) error {
538-
if existing := s.State.RunningPIDs["php-cgi"]; existing != 0 && IsProcessRunning(existing) {
542+
if existing := s.State.RunningPIDs["php-cgi"]; existing != 0 && IsProcessRunning(existing) && isPortBound(port) {
539543
return nil
540544
}
541545
logFile, err := os.OpenFile(filepath.Join(s.LogDir, "php-cgi.log"), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)

0 commit comments

Comments
 (0)