|
@@ -1,6 +1,7 @@
|
|
package docker
|
|
package docker
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "bytes"
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"errors"
|
|
"errors"
|
|
"io"
|
|
"io"
|
|
@@ -9,10 +10,9 @@ import (
|
|
"os"
|
|
"os"
|
|
"os/exec"
|
|
"os/exec"
|
|
"path"
|
|
"path"
|
|
|
|
+ "strings"
|
|
"syscall"
|
|
"syscall"
|
|
"time"
|
|
"time"
|
|
- "strings"
|
|
|
|
- "bytes"
|
|
|
|
)
|
|
)
|
|
|
|
|
|
type Container struct {
|
|
type Container struct {
|
|
@@ -33,8 +33,8 @@ type Container struct {
|
|
stdout *writeBroadcaster
|
|
stdout *writeBroadcaster
|
|
stderr *writeBroadcaster
|
|
stderr *writeBroadcaster
|
|
|
|
|
|
- stdoutLog *bytes.Buffer
|
|
|
|
- stderrLog *bytes.Buffer
|
|
|
|
|
|
+ stdoutLog *bytes.Buffer
|
|
|
|
+ stderrLog *bytes.Buffer
|
|
}
|
|
}
|
|
|
|
|
|
type Config struct {
|
|
type Config struct {
|
|
@@ -56,8 +56,8 @@ func createContainer(id string, root string, command string, args []string, laye
|
|
lxcConfigPath: path.Join(root, "config.lxc"),
|
|
lxcConfigPath: path.Join(root, "config.lxc"),
|
|
stdout: newWriteBroadcaster(),
|
|
stdout: newWriteBroadcaster(),
|
|
stderr: newWriteBroadcaster(),
|
|
stderr: newWriteBroadcaster(),
|
|
- stdoutLog: new(bytes.Buffer),
|
|
|
|
- stderrLog: new(bytes.Buffer),
|
|
|
|
|
|
+ stdoutLog: new(bytes.Buffer),
|
|
|
|
+ stderrLog: new(bytes.Buffer),
|
|
}
|
|
}
|
|
container.stdout.AddWriter(NopWriteCloser(container.stdoutLog))
|
|
container.stdout.AddWriter(NopWriteCloser(container.stdoutLog))
|
|
container.stderr.AddWriter(NopWriteCloser(container.stderrLog))
|
|
container.stderr.AddWriter(NopWriteCloser(container.stderrLog))
|
|
@@ -83,8 +83,8 @@ func loadContainer(containerPath string) (*Container, error) {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
container := &Container{
|
|
container := &Container{
|
|
- stdout: newWriteBroadcaster(),
|
|
|
|
- stderr: newWriteBroadcaster(),
|
|
|
|
|
|
+ stdout: newWriteBroadcaster(),
|
|
|
|
+ stderr: newWriteBroadcaster(),
|
|
stdoutLog: new(bytes.Buffer),
|
|
stdoutLog: new(bytes.Buffer),
|
|
stderrLog: new(bytes.Buffer),
|
|
stderrLog: new(bytes.Buffer),
|
|
}
|
|
}
|
|
@@ -98,7 +98,6 @@ func loadContainer(containerPath string) (*Container, error) {
|
|
return container, nil
|
|
return container, nil
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
func (container *Container) Cmd() *exec.Cmd {
|
|
func (container *Container) Cmd() *exec.Cmd {
|
|
return container.cmd
|
|
return container.cmd
|
|
}
|
|
}
|
|
@@ -135,7 +134,7 @@ func (container *Container) SetUserData(key, value string) error {
|
|
return container.saveUserData(data)
|
|
return container.saveUserData(data)
|
|
}
|
|
}
|
|
|
|
|
|
-func (container *Container) GetUserData(key string) (string) {
|
|
|
|
|
|
+func (container *Container) GetUserData(key string) string {
|
|
data, err := container.loadUserData()
|
|
data, err := container.loadUserData()
|
|
if err != nil {
|
|
if err != nil {
|
|
return ""
|
|
return ""
|
|
@@ -146,7 +145,6 @@ func (container *Container) GetUserData(key string) (string) {
|
|
return ""
|
|
return ""
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
func (container *Container) save() (err error) {
|
|
func (container *Container) save() (err error) {
|
|
data, err := json.Marshal(container)
|
|
data, err := json.Marshal(container)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -226,7 +224,6 @@ func (container *Container) StdoutLog() io.Reader {
|
|
return strings.NewReader(container.stdoutLog.String())
|
|
return strings.NewReader(container.stdoutLog.String())
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
func (container *Container) StderrPipe() (io.ReadCloser, error) {
|
|
func (container *Container) StderrPipe() (io.ReadCloser, error) {
|
|
reader, writer := io.Pipe()
|
|
reader, writer := io.Pipe()
|
|
container.stderr.AddWriter(writer)
|
|
container.stderr.AddWriter(writer)
|