forked from sylabs/singularity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oci_state_linux.go
37 lines (33 loc) · 952 Bytes
/
oci_state_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
// 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"
"github.com/sylabs/singularity/pkg/util/unix"
)
// OciState query container state
func OciState(containerID string, args *OciArgs) error {
// query instance files and returns state
state, err := getState(containerID)
if err != nil {
return err
}
if args.SyncSocketPath != "" {
data, err := json.Marshal(state)
if err != nil {
return fmt.Errorf("failed to marshal state data: %s", err)
} else if err := unix.WriteSocket(args.SyncSocketPath, data); err != nil {
return err
}
} else {
c, err := json.MarshalIndent(state, "", "\t")
if err != nil {
return err
}
fmt.Println(string(c))
}
return nil
}