| 1 | // Copyright © 2013, 2014, The Go-LXC Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a LGPLv2.1 |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | //go:build linux && cgo |
| 6 | // +build linux,cgo |
| 7 | |
| 8 | package main |
| 9 | |
| 10 | import ( |
| 11 | "flag" |
| 12 | "log" |
| 13 | "time" |
| 14 | |
| 15 | "github.com/lxc/go-lxc" |
| 16 | ) |
| 17 | |
| 18 | var ( |
| 19 | lxcpath string |
| 20 | name string |
| 21 | ) |
| 22 | |
| 23 | func init() { |
| 24 | flag.StringVar(&lxcpath, "lxcpath", lxc.DefaultConfigPath(), "Use specified container path") |
| 25 | flag.StringVar(&name, "name", "rubik", "Name of the container") |
| 26 | flag.Parse() |
| 27 | } |
| 28 | |
| 29 | func main() { |
| 30 | c, err := lxc.NewContainer(name, lxcpath) |
| 31 | if err != nil { |
| 32 | log.Fatalf("ERROR: %s\n", err.Error()) |
| 33 | } |
| 34 | defer c.Release() |
| 35 | |
| 36 | c.SetLogFile("/tmp/" + name + ".log") |
| 37 | c.SetLogLevel(lxc.TRACE) |
| 38 | |
| 39 | log.Printf("Starting the container...\n") |
| 40 | if err := c.Start(); err != nil { |
| 41 | log.Fatalf("ERROR: %s\n", err.Error()) |
| 42 | } |
| 43 | |
| 44 | log.Printf("Waiting container to startup networking...\n") |
| 45 | if _, err := c.WaitIPAddresses(5 * time.Second); err != nil { |
| 46 | log.Fatalf("ERROR: %s\n", err.Error()) |
| 47 | } |
| 48 | } |