2014-08-13 01:46:43 +08:00
|
|
|
package main
|
2014-02-20 08:40:36 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2014-03-04 13:47:03 +08:00
|
|
|
|
2015-02-17 05:09:00 +08:00
|
|
|
log "github.com/Sirupsen/logrus"
|
2014-06-05 07:46:30 +08:00
|
|
|
"github.com/codegangsta/cli"
|
2014-02-20 08:40:36 +08:00
|
|
|
)
|
|
|
|
|
2014-08-13 01:46:43 +08:00
|
|
|
func main() {
|
2014-06-05 07:46:30 +08:00
|
|
|
app := cli.NewApp()
|
|
|
|
app.Name = "nsinit"
|
2015-02-14 07:43:14 +08:00
|
|
|
app.Version = "2"
|
2014-06-05 07:46:30 +08:00
|
|
|
app.Author = "libcontainer maintainers"
|
2014-08-05 06:05:50 +08:00
|
|
|
app.Flags = []cli.Flag{
|
2014-10-23 04:45:23 +08:00
|
|
|
cli.StringFlag{Name: "root", Value: ".", Usage: "root directory for containers"},
|
2015-03-13 03:00:01 +08:00
|
|
|
cli.StringFlag{Name: "log-file", Value: "", Usage: "set the log file to output logs to"},
|
2015-02-17 05:09:00 +08:00
|
|
|
cli.BoolFlag{Name: "debug", Usage: "enable debug output in the logs"},
|
2014-08-07 09:44:41 +08:00
|
|
|
}
|
2014-06-05 07:46:30 +08:00
|
|
|
app.Commands = []cli.Command{
|
2015-02-12 09:42:58 +08:00
|
|
|
configCommand,
|
2014-06-05 07:46:30 +08:00
|
|
|
execCommand,
|
|
|
|
initCommand,
|
2015-01-27 20:54:19 +08:00
|
|
|
oomCommand,
|
2014-06-27 07:44:43 +08:00
|
|
|
pauseCommand,
|
2015-01-27 20:54:19 +08:00
|
|
|
statsCommand,
|
2014-06-27 07:44:43 +08:00
|
|
|
unpauseCommand,
|
2015-02-12 09:42:58 +08:00
|
|
|
stateCommand,
|
2014-05-30 08:23:18 +08:00
|
|
|
}
|
2015-02-17 05:09:00 +08:00
|
|
|
app.Before = func(context *cli.Context) error {
|
|
|
|
if context.GlobalBool("debug") {
|
|
|
|
log.SetLevel(log.DebugLevel)
|
|
|
|
}
|
|
|
|
if path := context.GlobalString("log-file"); path != "" {
|
|
|
|
f, err := os.Create(path)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
log.SetOutput(f)
|
|
|
|
}
|
|
|
|
return nil
|
2014-05-30 08:23:18 +08:00
|
|
|
}
|
2014-06-05 07:46:30 +08:00
|
|
|
if err := app.Run(os.Args); err != nil {
|
|
|
|
log.Fatal(err)
|
2014-05-30 08:23:18 +08:00
|
|
|
}
|
|
|
|
}
|