소스 검색

Merge pull request #463 from dotcloud/improve_pid_file_feature

Check that the pid in pidfile exists before preventing docker to start
Guillaume J. Charmes 12 년 전
부모
커밋
0b0d958b88
1개의 변경된 파일9개의 추가작업 그리고 2개의 파일을 삭제
  1. 9 2
      docker/docker.go

+ 9 - 2
docker/docker.go

@@ -7,9 +7,11 @@ import (
 	"github.com/dotcloud/docker/rcli"
 	"github.com/dotcloud/docker/term"
 	"io"
+	"io/ioutil"
 	"log"
 	"os"
 	"os/signal"
+	"strconv"
 	"syscall"
 )
 
@@ -54,8 +56,13 @@ func main() {
 }
 
 func createPidFile(pidfile string) error {
-	if _, err := os.Stat(pidfile); err == nil {
-		return fmt.Errorf("pid file found, ensure docker is not running or delete %s", pidfile)
+	if pidString, err := ioutil.ReadFile(pidfile); err == nil {
+		pid, err := strconv.Atoi(string(pidString))
+		if err == nil {
+			if _, err := os.Stat(fmt.Sprintf("/proc/%d/", pid)); err == nil {
+				return fmt.Errorf("pid file found, ensure docker is not running or delete %s", pidfile)
+			}
+		}
 	}
 
 	file, err := os.Create(pidfile)