mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
fix pidfile, pid is num use '/proc + string(pid)' can't found it
Signed-off-by: mingqing <limingqing@cyou-inc.com>
This commit is contained in:
parent
742a7d53f2
commit
6a033fa03e
1 changed files with 5 additions and 3 deletions
|
@ -9,6 +9,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PIDFile is a file used to store the process ID of a running process.
|
// 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 {
|
func checkPIDFileAlreadyExists(path string) error {
|
||||||
if pidString, err := ioutil.ReadFile(path); err == nil {
|
if pidByte, err := ioutil.ReadFile(path); err == nil {
|
||||||
if pid, err := strconv.Atoi(string(pidString)); err == nil {
|
pidString := strings.TrimSpace(string(pidByte))
|
||||||
if _, err := os.Stat(filepath.Join("/proc", string(pid))); err == nil {
|
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)
|
return fmt.Errorf("pid file found, ensure docker is not running or delete %s", path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue