Merge pull request #463 from dotcloud/improve_pid_file_feature

Check that the pid in pidfile exists before preventing docker to start
This commit is contained in:
Guillaume J. Charmes 2013-04-22 18:24:03 -07:00
commit 0b0d958b88
1 changed files with 9 additions and 2 deletions

View File

@ -7,9 +7,11 @@ import (
"github.com/dotcloud/docker/rcli" "github.com/dotcloud/docker/rcli"
"github.com/dotcloud/docker/term" "github.com/dotcloud/docker/term"
"io" "io"
"io/ioutil"
"log" "log"
"os" "os"
"os/signal" "os/signal"
"strconv"
"syscall" "syscall"
) )
@ -54,9 +56,14 @@ func main() {
} }
func createPidFile(pidfile string) error { func createPidFile(pidfile string) error {
if _, err := os.Stat(pidfile); err == nil { 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) return fmt.Errorf("pid file found, ensure docker is not running or delete %s", pidfile)
} }
}
}
file, err := os.Create(pidfile) file, err := os.Create(pidfile)
if err != nil { if err != nil {