mirror of
https://github.com/rancher/os.git
synced 2025-09-01 06:40:31 +00:00
Merge power funcs and fix build issues
This commit is contained in:
@@ -55,9 +55,6 @@ var (
|
|||||||
"/sbin/modprobe": "/busybox",
|
"/sbin/modprobe": "/busybox",
|
||||||
"/var/run": "/run",
|
"/var/run": "/run",
|
||||||
DOCKER: "/docker",
|
DOCKER: "/docker",
|
||||||
"/sbin/poweroff": "/init",
|
|
||||||
"/sbin/halt": "/init",
|
|
||||||
"/sbin/reboot": "/init",
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -5,15 +5,14 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"syscall"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"github.com/fsouza/go-dockerclient"
|
"github.com/fsouza/go-dockerclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
dockerPath = "unix:///var/run/system-docker.sock"
|
dockerPath = "unix:///var/run/system-docker.sock"
|
||||||
dockerCGroupsFile = "/proc/self/cgroup"
|
dockerCGroupsFile = "/proc/self/cgroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -65,14 +64,14 @@ func shutDownContainers() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
client, err := docker.NewClient(dockerPath)
|
client, err := docker.NewClient(dockerPath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
opts := docker.ListContainersOptions{All: true, Filters: map[string][]string{"status": []string{"running"}}}
|
opts := docker.ListContainersOptions{All: true, Filters: map[string][]string{"status": []string{"running"}}}
|
||||||
var containers []docker.APIContainers
|
var containers []docker.APIContainers
|
||||||
|
|
||||||
containers, err = client.ListContainers(opts)
|
containers, err = client.ListContainers(opts)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -93,7 +92,7 @@ func shutDownContainers() error {
|
|||||||
}
|
}
|
||||||
stopErr := client.StopContainer(containers[i].ID, timeout)
|
stopErr := client.StopContainer(containers[i].ID, timeout)
|
||||||
if stopErr != nil {
|
if stopErr != nil {
|
||||||
stopErrorStrings = append(stopErrorStrings, " [" + containers[i].ID + "] " +stopErr.Error())
|
stopErrorStrings = append(stopErrorStrings, " ["+containers[i].ID+"] "+stopErr.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,10 +104,10 @@ func shutDownContainers() error {
|
|||||||
}
|
}
|
||||||
_, waitErr := client.WaitContainer(containers[i].ID)
|
_, waitErr := client.WaitContainer(containers[i].ID)
|
||||||
if waitErr != nil {
|
if waitErr != nil {
|
||||||
waitErrorStrings = append(waitErrorStrings, " [" + containers[i].ID + "] " + waitErr.Error())
|
waitErrorStrings = append(waitErrorStrings, " ["+containers[i].ID+"] "+waitErr.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(waitErrorStrings) != 0 || len(stopErrorStrings) != 0 {
|
if len(waitErrorStrings) != 0 || len(stopErrorStrings) != 0 {
|
||||||
return errors.New("error while stopping \n1. STOP Errors [" + strings.Join(stopErrorStrings, ",") + "] \n2. WAIT Errors [" + strings.Join(waitErrorStrings, ",") + "]")
|
return errors.New("error while stopping \n1. STOP Errors [" + strings.Join(stopErrorStrings, ",") + "] \n2. WAIT Errors [" + strings.Join(waitErrorStrings, ",") + "]")
|
||||||
}
|
}
|
||||||
@@ -116,7 +115,6 @@ func shutDownContainers() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func getCurrentContainerId() (string, error) {
|
func getCurrentContainerId() (string, error) {
|
||||||
file, err := os.Open(dockerCGroupsFile)
|
file, err := os.Open(dockerCGroupsFile)
|
||||||
|
|
||||||
@@ -131,7 +129,7 @@ func getCurrentContainerId() (string, error) {
|
|||||||
line := fileReader.Text()
|
line := fileReader.Text()
|
||||||
parts := strings.Split(line, "/")
|
parts := strings.Split(line, "/")
|
||||||
|
|
||||||
while len(parts) != 3 {
|
for len(parts) != 3 {
|
||||||
if !fileReader.Scan() {
|
if !fileReader.Scan() {
|
||||||
return "", errors.New("Found no docker cgroups")
|
return "", errors.New("Found no docker cgroups")
|
||||||
}
|
}
|
||||||
@@ -148,4 +146,3 @@ func getCurrentContainerId() (string, error) {
|
|||||||
|
|
||||||
return parts[len(parts)-1:][0], nil
|
return parts[len(parts)-1:][0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5,7 +5,7 @@ set -x
|
|||||||
cd $(dirname $0)/..
|
cd $(dirname $0)/..
|
||||||
|
|
||||||
apt-get update
|
apt-get update
|
||||||
apt-get install -y curl rsync build-essential syslinux xorriso libblkid-dev
|
apt-get install -y curl rsync build-essential syslinux xorriso libblkid-dev libmount-dev libselinux1-dev
|
||||||
|
|
||||||
|
|
||||||
curl -sL https://github.com/ibuildthecloud/docker/releases/download/v1.5.0-rancher-2/docker-1.5.0 > /usr/bin/docker
|
curl -sL https://github.com/ibuildthecloud/docker/releases/download/v1.5.0-rancher-2/docker-1.5.0 > /usr/bin/docker
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
FROM base
|
FROM base
|
||||||
|
RUN rm /sbin/poweroff /sbin/reboot /sbin/halt
|
||||||
COPY scripts/dockerimages/scripts/console.sh /
|
COPY scripts/dockerimages/scripts/console.sh /
|
||||||
CMD ["/console.sh"]
|
CMD ["/console.sh"]
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#cgo LDFLAGS: -lmount -lblkid -luuid
|
#cgo LDFLAGS: -lmount -lblkid -luuid -lselinux
|
||||||
#include<blkid/blkid.h>
|
#include<blkid/blkid.h>
|
||||||
#include<libmount/libmount.h>
|
#include<libmount/libmount.h>
|
||||||
#include<stdlib.h>
|
#include<stdlib.h>
|
||||||
@@ -17,19 +17,19 @@ func ResolveDevice(spec string) string {
|
|||||||
cSpec := C.CString(spec)
|
cSpec := C.CString(spec)
|
||||||
defer C.free(unsafe.Pointer(cSpec))
|
defer C.free(unsafe.Pointer(cSpec))
|
||||||
cString := C.blkid_evaluate_spec(cSpec, nil)
|
cString := C.blkid_evaluate_spec(cSpec, nil)
|
||||||
defer C.free(unsafe.Pointer(cString))
|
defer C.free(unsafe.Pointer(cString))
|
||||||
return C.GoString(cString)
|
return C.GoString(cString)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetFsType(device string) (string, error) {
|
func GetFsType(device string) (string, error) {
|
||||||
var ambi * C.int
|
var ambi *C.int
|
||||||
cDevice := C.CString(device)
|
cDevice := C.CString(device)
|
||||||
defer C.free(unsafe.Pointer(cDevice))
|
defer C.free(unsafe.Pointer(cDevice))
|
||||||
cString := C.mnt_get_fstype(cDevice, ambi, nil)
|
cString := C.mnt_get_fstype(cDevice, ambi, nil)
|
||||||
defer C.free(unsafe.Pointer(cString))
|
defer C.free(unsafe.Pointer(cString))
|
||||||
if cString != nil {
|
if cString != nil {
|
||||||
return C.GoString(cString), nil
|
return C.GoString(cString), nil
|
||||||
}
|
}
|
||||||
return "", errors.New("Error while getting fstype")
|
return "", errors.New("Error while getting fstype")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user