1
0
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:
Darren Shepherd
2015-02-16 22:09:26 -07:00
parent d656da6a26
commit 76e5cf8d50
5 changed files with 14 additions and 19 deletions

View File

@@ -55,9 +55,6 @@ var (
"/sbin/modprobe": "/busybox",
"/var/run": "/run",
DOCKER: "/docker",
"/sbin/poweroff": "/init",
"/sbin/halt": "/init",
"/sbin/reboot": "/init",
}
)

View File

@@ -5,15 +5,14 @@ import (
"errors"
"os"
"strconv"
"syscall"
"strings"
"syscall"
"github.com/fsouza/go-dockerclient"
)
const (
dockerPath = "unix:///var/run/system-docker.sock"
dockerPath = "unix:///var/run/system-docker.sock"
dockerCGroupsFile = "/proc/self/cgroup"
)
@@ -65,14 +64,14 @@ func shutDownContainers() error {
return nil
}
client, err := docker.NewClient(dockerPath)
if err != nil {
return err
}
opts := docker.ListContainersOptions{All: true, Filters: map[string][]string{"status": []string{"running"}}}
var containers []docker.APIContainers
containers, err = client.ListContainers(opts)
if err != nil {
@@ -93,7 +92,7 @@ func shutDownContainers() error {
}
stopErr := client.StopContainer(containers[i].ID, timeout)
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)
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 {
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
}
func getCurrentContainerId() (string, error) {
file, err := os.Open(dockerCGroupsFile)
@@ -131,7 +129,7 @@ func getCurrentContainerId() (string, error) {
line := fileReader.Text()
parts := strings.Split(line, "/")
while len(parts) != 3 {
for len(parts) != 3 {
if !fileReader.Scan() {
return "", errors.New("Found no docker cgroups")
}
@@ -148,4 +146,3 @@ func getCurrentContainerId() (string, error) {
return parts[len(parts)-1:][0], nil
}

View File

@@ -5,7 +5,7 @@ set -x
cd $(dirname $0)/..
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

View File

@@ -1,3 +1,4 @@
FROM base
RUN rm /sbin/poweroff /sbin/reboot /sbin/halt
COPY scripts/dockerimages/scripts/console.sh /
CMD ["/console.sh"]

View File

@@ -1,7 +1,7 @@
package util
/*
#cgo LDFLAGS: -lmount -lblkid -luuid
#cgo LDFLAGS: -lmount -lblkid -luuid -lselinux
#include<blkid/blkid.h>
#include<libmount/libmount.h>
#include<stdlib.h>
@@ -17,19 +17,19 @@ func ResolveDevice(spec string) string {
cSpec := C.CString(spec)
defer C.free(unsafe.Pointer(cSpec))
cString := C.blkid_evaluate_spec(cSpec, nil)
defer C.free(unsafe.Pointer(cString))
defer C.free(unsafe.Pointer(cString))
return C.GoString(cString)
}
func GetFsType(device string) (string, error) {
var ambi * C.int
var ambi *C.int
cDevice := C.CString(device)
defer C.free(unsafe.Pointer(cDevice))
cString := C.mnt_get_fstype(cDevice, ambi, nil)
defer C.free(unsafe.Pointer(cString))
if cString != nil {
return C.GoString(cString), nil
}
}
return "", errors.New("Error while getting fstype")
}