/
oci_start_linux.go
61 lines (49 loc) · 1.55 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
58
59
60
61
// Copyright (c) Contributors to the Apptainer project, established as
// Apptainer a Series of LF Projects LLC.
// For website terms of use, trademark policy, privacy policy and other
// project policies see https://lfprojects.org/policies
// 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 apptainer
import (
"encoding/json"
"fmt"
"io"
"github.com/apptainer/apptainer/pkg/ociruntime"
"github.com/apptainer/apptainer/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 enc == nil {
return fmt.Errorf("cannot instantiate new JSON encoder")
}
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
}