forked from sylabs/singularity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oci_linux.go
92 lines (76 loc) · 2.05 KB
/
oci_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// 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"
"os"
"github.com/sylabs/singularity/internal/pkg/instance"
"github.com/sylabs/singularity/internal/pkg/runtime/engines/config"
"github.com/sylabs/singularity/internal/pkg/runtime/engines/oci"
"github.com/sylabs/singularity/internal/pkg/sylog"
"github.com/sylabs/singularity/pkg/ociruntime"
)
// OciArgs contains CLI arguments
type OciArgs struct {
BundlePath string
LogPath string
LogFormat string
SyncSocketPath string
EmptyProcess bool
PidFile string
FromFile string
KillSignal string
}
func getCommonConfig(containerID string) (*config.Common, error) {
commonConfig := config.Common{
EngineConfig: &oci.EngineConfig{},
}
file, err := instance.Get(containerID)
if err != nil {
return nil, err
}
if err := json.Unmarshal(file.Config, &commonConfig); err != nil {
return nil, err
}
return &commonConfig, nil
}
func getEngineConfig(containerID string) (*oci.EngineConfig, error) {
commonConfig := config.Common{
EngineConfig: &oci.EngineConfig{},
}
file, err := instance.Get(containerID)
if err != nil {
return nil, err
}
if err := json.Unmarshal(file.Config, &commonConfig); err != nil {
return nil, err
}
return commonConfig.EngineConfig.(*oci.EngineConfig), nil
}
func getState(containerID string) (*ociruntime.State, error) {
engineConfig, err := getEngineConfig(containerID)
if err != nil {
return nil, err
}
return &engineConfig.State, nil
}
func exitContainer(containerID string, delete bool) {
state, err := getState(containerID)
if err != nil {
if !delete {
sylog.Errorf("%s", err)
os.Exit(1)
}
return
}
if state.ExitCode != nil {
defer os.Exit(*state.ExitCode)
}
if delete {
if err := OciDelete(containerID); err != nil {
sylog.Errorf("%s", err)
}
}
}