/
oci_start_linux.go
57 lines (45 loc) · 1.26 KB
/
oci_start_linux.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (c) 2018-2019, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
package singularity
import (
"encoding/json"
"fmt"
"io"
"github.com/sylabs/singularity/pkg/ociruntime"
"github.com/sylabs/singularity/pkg/util/unix"
)
// OciStart starts a previously create container
func OciStart(containerID string) error {
state, err := getState(containerID)
if err != nil {
return err
}
if state.Status != ociruntime.Created {
return fmt.Errorf("cannot start '%s', the state of the container must be %s", containerID, ociruntime.Created)
}
if state.ControlSocket == "" {
return fmt.Errorf("can't find control socket")
}
ctrl := &ociruntime.Control{}
ctrl.StartContainer = true
c, err := unix.Dial(state.ControlSocket)
if err != nil {
return fmt.Errorf("failed to connect to control socket")
}
defer c.Close()
enc := json.NewEncoder(c)
if err != nil {
return err
}
if err := enc.Encode(ctrl); err != nil {
return err
}
// wait runtime close socket connection for ACK
d := make([]byte, 1)
if _, err := c.Read(d); err != io.EOF {
return err
}
return nil
}