implement wait on freeze
Docker-DCO-1.1-Signed-off-by: Victor Vieux <vieux@docker.com> (github: vieux)
This commit is contained in:
parent
313ab78d1f
commit
ae0b8c7d9d
3 changed files with 33 additions and 1 deletions
|
@ -164,6 +164,11 @@ func writeFile(dir, file, data string) error {
|
||||||
return ioutil.WriteFile(filepath.Join(dir, file), []byte(data), 0700)
|
return ioutil.WriteFile(filepath.Join(dir, file), []byte(data), 0700)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func readFile(dir, file string) (string, error) {
|
||||||
|
data, err := ioutil.ReadFile(filepath.Join(dir, file))
|
||||||
|
return string(data), err
|
||||||
|
}
|
||||||
|
|
||||||
func removePath(p string, err error) error {
|
func removePath(p string, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/dotcloud/docker/pkg/libcontainer/cgroups"
|
"github.com/dotcloud/docker/pkg/libcontainer/cgroups"
|
||||||
)
|
)
|
||||||
|
@ -22,6 +23,17 @@ func (s *freezerGroup) Set(d *data) error {
|
||||||
if err := writeFile(dir, "freezer.state", string(d.c.Freezer)); err != nil {
|
if err := writeFile(dir, "freezer.state", string(d.c.Freezer)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
|
state, err := readFile(dir, "freezer.state")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if strings.TrimSpace(state) == string(d.c.Freezer) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(1 * time.Millisecond)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
if _, err := d.join("freezer"); err != nil && err != cgroups.ErrNotFound {
|
if _, err := d.join("freezer"); err != nil && err != cgroups.ErrNotFound {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
package systemd
|
package systemd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
@ -10,6 +11,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
systemd1 "github.com/coreos/go-systemd/dbus"
|
systemd1 "github.com/coreos/go-systemd/dbus"
|
||||||
"github.com/dotcloud/docker/pkg/libcontainer/cgroups"
|
"github.com/dotcloud/docker/pkg/libcontainer/cgroups"
|
||||||
|
@ -351,7 +353,20 @@ func Freeze(c *cgroups.Cgroup, state cgroups.FreezerState) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return ioutil.WriteFile(filepath.Join(path, "freezer.state"), []byte(state), 0)
|
if err := ioutil.WriteFile(filepath.Join(path, "freezer.state"), []byte(state), 0); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for {
|
||||||
|
state_, err := ioutil.ReadFile(filepath.Join(path, "freezer.state"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if string(state) == string(bytes.TrimSpace(state_)) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(1 * time.Millisecond)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPids(c *cgroups.Cgroup) ([]int, error) {
|
func GetPids(c *cgroups.Cgroup) ([]int, error) {
|
||||||
|
|
Loading…
Reference in a new issue