Enable build on unsupported platforms
Should compile now without errors but changes needed to be added for each system so it actually works. main_unsupported.go is a new file with all the unsupported commands Fixes #9 Signed-off-by: Marianna <mtesselh@gmail.com>
This commit is contained in:
parent
85e264d0b9
commit
5aa82c950d
|
@ -1,3 +1,5 @@
|
||||||
|
// +build linux
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -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
33
main.go
|
@ -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)
|
||||||
|
|
|
@ -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")
|
||||||
|
}
|
|
@ -1,3 +1,5 @@
|
||||||
|
// +build linux
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
33
run.go
33
run.go
|
@ -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 {
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// +build linux
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
3
spec.go
3
spec.go
|
@ -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)
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue