Merge pull request #68 from mtesselH/master

Enable build on unsupported platforms
This commit is contained in:
Michael Crosby 2015-06-30 10:00:23 -07:00
commit fd6564b8e4
10 changed files with 72 additions and 33 deletions

View File

@ -1,3 +1,5 @@
// +build linux
package main package main
import ( import (

View File

@ -1,3 +1,5 @@
// +build linux
package main package main
import ( import (
@ -56,7 +58,7 @@ var eventsCommand = cli.Command{
return return
} }
go func() { go func() {
for _ = range time.Tick(context.Duration("interval")) { for range time.Tick(context.Duration("interval")) {
s, err := container.Stats() s, err := container.Stats()
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)

33
main.go
View File

@ -2,11 +2,9 @@ package main
import ( import (
"os" "os"
"runtime"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"github.com/opencontainers/runc/libcontainer"
) )
const ( const (
@ -27,18 +25,6 @@ After creating a spec for your root filesystem with runc, you can execute a simp
` `
) )
func init() {
if len(os.Args) > 1 && os.Args[1] == "init" {
runtime.GOMAXPROCS(1)
runtime.LockOSThread()
factory, _ := libcontainer.New("")
if err := factory.StartInitialization(); err != nil {
fatal(err)
}
panic("--this line should never been executed, congratulations--")
}
}
func main() { func main() {
app := cli.NewApp() app := cli.NewApp()
app.Name = "runc" app.Name = "runc"
@ -77,23 +63,8 @@ func main() {
} }
return nil return nil
} }
// default action is to execute a container
app.Action = func(context *cli.Context) { app.Action = runAction
spec, err := loadSpec(context.Args().First())
if err != nil {
fatal(err)
}
if os.Geteuid() != 0 {
logrus.Fatal("runc should be run as root")
}
status, err := execContainer(context, spec)
if err != nil {
logrus.Fatalf("Container start failed: %v", err)
}
// exit with the container's exit status so any external supervisor is
// notified of the exit with the correct exit status.
os.Exit(status)
}
if err := app.Run(os.Args); err != nil { if err := app.Run(os.Args); err != nil {
logrus.Fatal(err) logrus.Fatal(err)

22
main_unsupported.go Normal file
View File

@ -0,0 +1,22 @@
// +build !linux
package main
import (
"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
)
func getDefaultID() string {
return ""
}
var (
checkpointCommand cli.Command
eventsCommand cli.Command
restoreCommand cli.Command
)
func runAction(*cli.Context) {
logrus.Fatal("Current OS is not supported yet")
}

View File

@ -1,3 +1,5 @@
// +build linux
package main package main
import ( import (

33
run.go
View File

@ -1,14 +1,29 @@
// +build linux
package main package main
import ( import (
"fmt" "fmt"
"os" "os"
"runtime"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"github.com/opencontainers/runc/libcontainer" "github.com/opencontainers/runc/libcontainer"
) )
func init() {
if len(os.Args) > 1 && os.Args[1] == "init" {
runtime.GOMAXPROCS(1)
runtime.LockOSThread()
factory, _ := libcontainer.New("")
if err := factory.StartInitialization(); err != nil {
fatal(err)
}
panic("--this line should never been executed, congratulations--")
}
}
func execContainer(context *cli.Context, spec *Spec) (int, error) { func execContainer(context *cli.Context, spec *Spec) (int, error) {
config, err := createLibcontainerConfig(spec) config, err := createLibcontainerConfig(spec)
if err != nil { if err != nil {
@ -48,6 +63,24 @@ func execContainer(context *cli.Context, spec *Spec) (int, error) {
return handler.forward(process) return handler.forward(process)
} }
// default action is to execute a container
func runAction(context *cli.Context) {
spec, err := loadSpec(context.Args().First())
if err != nil {
fatal(err)
}
if os.Geteuid() != 0 {
logrus.Fatal("runc should be run as root")
}
status, err := execContainer(context, spec)
if err != nil {
logrus.Fatalf("Container start failed: %v", err)
}
// exit with the container's exit status so any external supervisor is
// notified of the exit with the correct exit status.
os.Exit(status)
}
func destroy(container libcontainer.Container) { func destroy(container libcontainer.Container) {
status, err := container.Status() status, err := container.Status()
if err != nil { if err != nil {

View File

@ -1,3 +1,5 @@
// +build linux
package main package main
import ( import (

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"runtime" "runtime"
"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
) )
@ -111,7 +112,7 @@ var specCommand = cli.Command{
} }
data, err := json.MarshalIndent(&spec, "", "\t") data, err := json.MarshalIndent(&spec, "", "\t")
if err != nil { if err != nil {
fatal(err) logrus.Fatal(err)
} }
fmt.Printf("%s", data) fmt.Printf("%s", data)
}, },

2
tty.go
View File

@ -1,3 +1,5 @@
// +build linux
package main package main
import ( import (

View File

@ -1,3 +1,5 @@
// +build linux
package main package main
import ( import (