mirror of
				https://github.com/linuxkit/linuxkit.git
				synced 2025-10-31 23:51:23 +00:00 
			
		
		
		
	Currently it supports only `service start <SERVICE>`, but it could grow e.g. `stop`, `exec` etc in the future (although you can still use `ctr` for those). In order to be able to use go-compile.sh the containerd build needs to move from /root/go to /go as the GOPATH. The vendoring situation is not ideal, but since this tool wants to be an exact match for the containerd it seems tollerable to reuse its vendoring. Signed-off-by: Ian Campbell <ian.campbell@docker.com>
		
			
				
	
	
		
			76 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			76 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package main
 | |
| 
 | |
| import (
 | |
| 	"flag"
 | |
| 	"fmt"
 | |
| 	"os"
 | |
| 	"path/filepath"
 | |
| 
 | |
| 	log "github.com/Sirupsen/logrus"
 | |
| )
 | |
| 
 | |
| var (
 | |
| 	defaultLogFormatter = &log.TextFormatter{}
 | |
| )
 | |
| 
 | |
| // infoFormatter overrides the default format for Info() log events to
 | |
| // provide an easier to read output
 | |
| type infoFormatter struct {
 | |
| }
 | |
| 
 | |
| func (f *infoFormatter) Format(entry *log.Entry) ([]byte, error) {
 | |
| 	if entry.Level == log.InfoLevel {
 | |
| 		return append([]byte(entry.Message), '\n'), nil
 | |
| 	}
 | |
| 	return defaultLogFormatter.Format(entry)
 | |
| }
 | |
| 
 | |
| func main() {
 | |
| 	flag.Usage = func() {
 | |
| 		fmt.Printf("USAGE: %s [options] COMMAND\n\n", filepath.Base(os.Args[0]))
 | |
| 		fmt.Printf("Commands:\n")
 | |
| 		fmt.Printf("  start       Start a service\n")
 | |
| 		fmt.Printf("  help        Print this message\n")
 | |
| 		fmt.Printf("\n")
 | |
| 		fmt.Printf("Run '%s COMMAND --help' for more information on the command\n", filepath.Base(os.Args[0]))
 | |
| 		fmt.Printf("\n")
 | |
| 		fmt.Printf("Options:\n")
 | |
| 		flag.PrintDefaults()
 | |
| 	}
 | |
| 	flagQuiet := flag.Bool("q", false, "Quiet execution")
 | |
| 	flagVerbose := flag.Bool("v", false, "Verbose execution")
 | |
| 
 | |
| 	// Set up logging
 | |
| 	log.SetFormatter(new(infoFormatter))
 | |
| 	log.SetLevel(log.InfoLevel)
 | |
| 	flag.Parse()
 | |
| 	if *flagQuiet && *flagVerbose {
 | |
| 		fmt.Printf("Can't set quiet and verbose flag at the same time\n")
 | |
| 		os.Exit(1)
 | |
| 	}
 | |
| 	if *flagQuiet {
 | |
| 		log.SetLevel(log.ErrorLevel)
 | |
| 	}
 | |
| 	if *flagVerbose {
 | |
| 		// Switch back to the standard formatter
 | |
| 		log.SetFormatter(defaultLogFormatter)
 | |
| 		log.SetLevel(log.DebugLevel)
 | |
| 	}
 | |
| 
 | |
| 	args := flag.Args()
 | |
| 	if len(args) < 1 {
 | |
| 		fmt.Printf("Please specify a command.\n\n")
 | |
| 		flag.Usage()
 | |
| 		os.Exit(1)
 | |
| 	}
 | |
| 
 | |
| 	switch args[0] {
 | |
| 	case "start":
 | |
| 		start(args[1:])
 | |
| 	default:
 | |
| 		fmt.Printf("%q is not valid command.\n\n", args[0])
 | |
| 		flag.Usage()
 | |
| 		os.Exit(1)
 | |
| 	}
 | |
| }
 |