1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Move process functions to pkg/system

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Vincent Demeester 2016-12-12 09:28:41 +01:00
parent 0ab9320ab2
commit 8c1ac81665
No known key found for this signature in database
GPG key ID: 083CC6FD6EB699A3
3 changed files with 11 additions and 12 deletions

View file

@ -21,8 +21,7 @@ import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
containerd "github.com/docker/containerd/api/grpc/types" containerd "github.com/docker/containerd/api/grpc/types"
"github.com/docker/docker/pkg/locker" "github.com/docker/docker/pkg/locker"
sysinfo "github.com/docker/docker/pkg/system" "github.com/docker/docker/pkg/system"
"github.com/docker/docker/utils"
"github.com/golang/protobuf/ptypes" "github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/timestamp" "github.com/golang/protobuf/ptypes/timestamp"
"golang.org/x/net/context" "golang.org/x/net/context"
@ -81,7 +80,7 @@ func New(stateDir string, options ...RemoteOption) (_ Remote, err error) {
} }
} }
if err := sysinfo.MkdirAll(stateDir, 0700); err != nil { if err := system.MkdirAll(stateDir, 0700); err != nil {
return nil, err return nil, err
} }
@ -164,8 +163,8 @@ func (r *remote) handleConnectionChange() {
transientFailureCount++ transientFailureCount++
if transientFailureCount >= maxConnectionRetryCount { if transientFailureCount >= maxConnectionRetryCount {
transientFailureCount = 0 transientFailureCount = 0
if utils.IsProcessAlive(r.daemonPid) { if system.IsProcessAlive(r.daemonPid) {
utils.KillProcess(r.daemonPid) system.KillProcess(r.daemonPid)
} }
<-r.daemonWaitCh <-r.daemonWaitCh
if err := r.runContainerdDaemon(); err != nil { //FIXME: Handle error if err := r.runContainerdDaemon(); err != nil { //FIXME: Handle error
@ -188,13 +187,13 @@ func (r *remote) Cleanup() {
// Wait up to 15secs for it to stop // Wait up to 15secs for it to stop
for i := time.Duration(0); i < containerdShutdownTimeout; i += time.Second { for i := time.Duration(0); i < containerdShutdownTimeout; i += time.Second {
if !utils.IsProcessAlive(r.daemonPid) { if !system.IsProcessAlive(r.daemonPid) {
break break
} }
time.Sleep(time.Second) time.Sleep(time.Second)
} }
if utils.IsProcessAlive(r.daemonPid) { if system.IsProcessAlive(r.daemonPid) {
logrus.Warnf("libcontainerd: containerd (%d) didn't stop within 15 secs, killing it\n", r.daemonPid) logrus.Warnf("libcontainerd: containerd (%d) didn't stop within 15 secs, killing it\n", r.daemonPid)
syscall.Kill(r.daemonPid, syscall.SIGKILL) syscall.Kill(r.daemonPid, syscall.SIGKILL)
} }
@ -354,7 +353,7 @@ func (r *remote) runContainerdDaemon() error {
if err != nil { if err != nil {
return err return err
} }
if utils.IsProcessAlive(int(pid)) { if system.IsProcessAlive(int(pid)) {
logrus.Infof("libcontainerd: previous instance of containerd still alive (%d)", pid) logrus.Infof("libcontainerd: previous instance of containerd still alive (%d)", pid)
r.daemonPid = int(pid) r.daemonPid = int(pid)
return nil return nil
@ -417,11 +416,11 @@ func (r *remote) runContainerdDaemon() error {
} }
logrus.Infof("libcontainerd: new containerd process, pid: %d", cmd.Process.Pid) logrus.Infof("libcontainerd: new containerd process, pid: %d", cmd.Process.Pid)
if err := setOOMScore(cmd.Process.Pid, r.oomScore); err != nil { if err := setOOMScore(cmd.Process.Pid, r.oomScore); err != nil {
utils.KillProcess(cmd.Process.Pid) system.KillProcess(cmd.Process.Pid)
return err return err
} }
if _, err := f.WriteString(fmt.Sprintf("%d", cmd.Process.Pid)); err != nil { if _, err := f.WriteString(fmt.Sprintf("%d", cmd.Process.Pid)); err != nil {
utils.KillProcess(cmd.Process.Pid) system.KillProcess(cmd.Process.Pid)
return err return err
} }

View file

@ -1,6 +1,6 @@
// +build linux freebsd solaris // +build linux freebsd solaris
package utils package system
import ( import (
"syscall" "syscall"

View file

@ -1,4 +1,4 @@
package utils package system
// IsProcessAlive returns true if process with a given pid is running. // IsProcessAlive returns true if process with a given pid is running.
func IsProcessAlive(pid int) bool { func IsProcessAlive(pid int) bool {