2015-06-22 10:31:12 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2016-02-02 07:00:09 +08:00
|
|
|
"github.com/Sirupsen/logrus"
|
2016-05-26 02:24:26 +08:00
|
|
|
"github.com/opencontainers/runtime-spec/specs-go"
|
2016-06-07 02:45:46 +08:00
|
|
|
"github.com/urfave/cli"
|
2015-06-22 10:31:12 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// fatal prints the error's details if it is a libcontainer specific error type
|
2015-07-11 07:19:18 +08:00
|
|
|
// then exits the program with an exit status of 1.
|
2015-06-22 10:31:12 +08:00
|
|
|
func fatal(err error) {
|
2016-03-09 10:05:50 +08:00
|
|
|
// make sure the error is written to the logger
|
|
|
|
logrus.Error(err)
|
2015-06-22 10:31:12 +08:00
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2016-05-26 02:24:26 +08:00
|
|
|
|
|
|
|
// setupSpec performs inital setup based on the cli.Context for the container
|
|
|
|
func setupSpec(context *cli.Context) (*specs.Spec, error) {
|
|
|
|
bundle := context.String("bundle")
|
|
|
|
if bundle != "" {
|
|
|
|
if err := os.Chdir(bundle); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spec, err := loadSpec(specConfig)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
notifySocket := os.Getenv("NOTIFY_SOCKET")
|
|
|
|
if notifySocket != "" {
|
|
|
|
setupSdNotify(spec, notifySocket)
|
|
|
|
}
|
|
|
|
if os.Geteuid() != 0 {
|
|
|
|
return nil, fmt.Errorf("runc should be run as root")
|
|
|
|
}
|
|
|
|
return spec, nil
|
|
|
|
}
|