Check that the pid in pidfile exists before preventing docker to start
| ... | ... |
@@ -7,9 +7,11 @@ import ( |
| 7 | 7 |
"github.com/dotcloud/docker/rcli" |
| 8 | 8 |
"github.com/dotcloud/docker/term" |
| 9 | 9 |
"io" |
| 10 |
+ "io/ioutil" |
|
| 10 | 11 |
"log" |
| 11 | 12 |
"os" |
| 12 | 13 |
"os/signal" |
| 14 |
+ "strconv" |
|
| 13 | 15 |
"syscall" |
| 14 | 16 |
) |
| 15 | 17 |
|
| ... | ... |
@@ -54,8 +56,13 @@ func main() {
|
| 54 | 54 |
} |
| 55 | 55 |
|
| 56 | 56 |
func createPidFile(pidfile string) error {
|
| 57 |
- if _, err := os.Stat(pidfile); err == nil {
|
|
| 58 |
- return fmt.Errorf("pid file found, ensure docker is not running or delete %s", pidfile)
|
|
| 57 |
+ if pidString, err := ioutil.ReadFile(pidfile); err == nil {
|
|
| 58 |
+ pid, err := strconv.Atoi(string(pidString)) |
|
| 59 |
+ if err == nil {
|
|
| 60 |
+ if _, err := os.Stat(fmt.Sprintf("/proc/%d/", pid)); err == nil {
|
|
| 61 |
+ return fmt.Errorf("pid file found, ensure docker is not running or delete %s", pidfile)
|
|
| 62 |
+ } |
|
| 63 |
+ } |
|
| 59 | 64 |
} |
| 60 | 65 |
|
| 61 | 66 |
file, err := os.Create(pidfile) |