diff --git a/pkg/pidfile/pidfile.go b/pkg/pidfile/pidfile.go index db3535b01491c6e8b31d8f782e8b58a551073287..58cc4017032696357e1fb8d19098d370dd021a7b 100644 --- a/pkg/pidfile/pidfile.go +++ b/pkg/pidfile/pidfile.go @@ -9,6 +9,7 @@ import ( "os" "path/filepath" "strconv" + "strings" ) // PIDFile is a file used to store the process ID of a running process. @@ -17,9 +18,10 @@ type PIDFile struct { } func checkPIDFileAlreadyExists(path string) error { - if pidString, err := ioutil.ReadFile(path); err == nil { - if pid, err := strconv.Atoi(string(pidString)); err == nil { - if _, err := os.Stat(filepath.Join("/proc", string(pid))); err == nil { + if pidByte, err := ioutil.ReadFile(path); err == nil { + pidString := strings.TrimSpace(string(pidByte)) + if pid, err := strconv.Atoi(pidString); err == nil { + if _, err := os.Stat(filepath.Join("/proc", strconv.Itoa(pid))); err == nil { return fmt.Errorf("pid file found, ensure docker is not running or delete %s", path) } }