Example #1
0
// New creates and returns a new Server object with the provided Options as
// configuration.
func New(options *Options) *Server {
	s := &Server{
		log:     logray.New(),
		options: options,
	}
	return s
}
Example #2
0
// Run takes over the process and launches KurmaOS.
func Run() error {
	r := &runner{
		config: defaultConfiguration(),
		log:    logray.New(),
	}
	return r.Run()
}
Example #3
0
// New creates and returns a new Server object with the provided Options as
// configuration.
func New(options *Options) *Server {
	if options.BindAddress == "" {
		options.BindAddress = ":12312"
	}

	s := &Server{
		log:     logray.New(),
		options: options,
	}
	return s
}
Example #4
0
func main() {
	var configFile string
	var logLevel string

	flag.StringVar(&configFile, "f", "", "file to use to define processes")
	flag.StringVar(&logLevel, "log-levle", "info+", "log message levels to be logged")
	flag.Parse()

	// validate we have a config file
	if configFile == "" {
		fmt.Fprint(os.Stderr, "No config file specified with -f\n")
		os.Exit(1)
	}

	// validate the configured log level
	logclass, err := logray.ParseLogClass(logLevel)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to parse log class: %v\n", err)
		os.Exit(1)
	}
	logray.AddDefaultOutput("stdout://", logclass)
	log = logray.New()

	// load the config file
	config, err := loadConfig(configFile)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to load config file: %v\n", err)
		os.Exit(1)
	}

	// begin the signal handling
	handleSigterm()

	// begin managing processes
	wg := sync.WaitGroup{}
	for _, args := range config {
		wg.Add(1)
		go func(args []string) {
			defer wg.Done()
			manageProcess(args)
		}(args)
	}

	// wait for all to finish
	wg.Wait()
}
Example #5
0
func ExamplePass() {
	// Setup
	buffer := unittest.SetupBuffer()
	defer buffer.DumpToStdout()

	// Log a bunch of stuff.
	logger := logray.New()
	fmt.Println("Expected output.")
	logger.Info("log line 1")
	logger.Info("log line 2")
	logger.Info("log line 3")

	// Clear the buffer so nothing ends up on stdout.
	buffer.Clear()

	// Output: Expected output.
}
Example #6
0
// NewManager creates a new Manager with the provided options. It will ensure
// the manager is setup and ready to create containers with the provided
// configuration.
func NewManager(opts *Options) (*Manager, error) {
	// validate cgroups is properly setup on the host
	if err := cgroups.CheckCgroups(); err != nil {
		return nil, fmt.Errorf("failed to check cgroups: %v", err)
	}

	// create the parent cgroup for all child containers to be in
	cg, err := cgroups.New(opts.ParentCgroupName)
	if err != nil {
		return nil, err
	}

	m := &Manager{
		Log:                logray.New(),
		containers:         make(map[string]*Container),
		containerDirectory: opts.ContainerDirectory,
		volumeDirectory:    opts.VolumeDirectory,
		cgroup:             cg,
		requiredNamespaces: opts.RequiredNamespaces,
	}
	return m, nil
}