// initializeModules will initialize internal modules that do not require the container runtime to be up.
// Note that the modules here must not depend on modules that are not initialized here.
555475
func (kl *Kubelet) initializeModules() error {
	// Prometheus metrics.
	metrics.Register(
		kl.runtimeCache,
		collectors.NewVolumeStatsCollector(kl),
		collectors.NewLogMetricsCollector(kl.StatsProvider.ListPodStats),
	)
	metrics.SetNodeName(kl.nodeName)

	// Setup filesystem directories.
	if err := kl.setupDataDirs(); err != nil {
		return err
	}

	// If the container logs directory does not exist, create it.
	if _, err := os.Stat(ContainerLogsDir); err != nil {
		if err := kl.os.MkdirAll(ContainerLogsDir, 0755); err != nil {
			klog.Errorf("Failed to create directory %q: %v", ContainerLogsDir, err)
		}
	}

	// Start the image manager.
	kl.imageManager.Start()

	// Start the certificate manager if it was enabled.
	if kl.serverCertificateManager != nil {
		kl.serverCertificateManager.Start()
	}

	// Start out of memory watcher.
	if err := kl.oomWatcher.Start(kl.nodeRef); err != nil {
		return fmt.Errorf("Failed to start OOM watcher %v", err)
	}

	// Start resource analyzer
	kl.resourceAnalyzer.Start()

	return nil
}
75851
func (s *State) EnsureModule(addr addrs.ModuleInstance) *Module {
	ms := s.Module(addr)
	if ms == nil {
		ms = NewModule(addr)
		s.Modules[addr.String()] = ms
	}
	return ms
}
1022249
func (v *GenerateServiceRequest) GetModules() (o map[ModuleID]*Module) {
	if v != nil {
		o = v.Modules
	}
	return
}
1321493
func (ls *LState) RegisterModule(name string, funcs map[string]LGFunction) LValue {
	tb := ls.FindTable(ls.Get(RegistryIndex).(*LTable), "_LOADED", 1)
	mod := ls.GetField(tb, name)
	if mod.Type() != LTTable {
		newmod := ls.FindTable(ls.Get(GlobalsIndex).(*LTable), name, len(funcs))
		if newmodtb, ok := newmod.(*LTable); !ok {
			ls.RaiseError("name conflict for module(%v)", name)
		} else {
			for fname, fn := range funcs {
				newmodtb.RawSetString(fname, ls.NewFunction(fn))
			}
			ls.SetField(tb, name, newmodtb)
			return newmodtb
		}
	}
	return mod
}
734054
func loadKernelModules(context *model.NodeupModelContext) error {
	err := modprobe("br_netfilter")
	if err != nil {
		// TODO: Return error in 1.11 (too risky for 1.10)
		glog.Warningf("error loading br_netfilter module: %v", err)
	}
	// TODO: Add to /etc/modules-load.d/ ?
	return nil
}
714770
func (m *Module) Init(c *service.Config) {
	c.Setup = func() error {
		m.keyStore = &keystore.KeyStore{}
		m.keyFile = defaultKeyFile
		m.csrfValidityDuration = defaultCSRFValidity
		return nil
	}

	c.Start = func() {
		var err error
		privateKey, publicKey, err := loadKeys(m.keyFile, m.keyStore)
		if err != nil {
			panic(err)
		}
		m.decryptionKey = privateKey
		m.encrypter, err = jose.NewEncrypter(keyAlgorithm, contentEncryption, publicKey)
		if err != nil {
			panic(err)
		}
	}
}
1333079
func parseModulesFile(r io.Reader) ([]string, error) {
	var result []string

	scanner := bufio.NewScanner(r)
	scanner.Split(bufio.ScanLines)

	for scanner.Scan() {
		moduleInfoRaw := scanner.Text()
		moduleInfoSeparated := strings.Split(moduleInfoRaw, " ")
		if len(moduleInfoSeparated) < 6 {
			return nil, fmt.Errorf(
				"invalid module info - it has %d fields (less than 6): %s",
				len(moduleInfoSeparated), moduleInfoRaw)
		}

		result = append(result, moduleInfoSeparated[0])
	}

	return result, nil
}
1074999
func (m *Module) Init(c *service.Config) {
	c.Setup = func() error {
		m.BaseAuthenticator = m
		return nil
	}
}
924543
func (r *containerRouter) initRoutes() {
	r.routes = []router.Route{
		// GET
		local.NewGetRoute("/container/info", r.getContainerInfo),
		local.NewGetRoute("/container/logs", r.getContainerLogs),
		local.NewGetRoute("/exitcode", r.getExitCode),
		// POST
		local.NewPostRoute("/container/create", r.postContainerCreate),
		local.NewPostRoute("/container/start", r.postContainerStart),
		local.NewPostRoute("/container/rename", r.postContainerRename),
		local.NewPostRoute("/container/commit", r.postContainerCommit),
		local.NewPostRoute("/container/stop", r.postContainerStop),
		local.NewPostRoute("/container/remove", r.postContainerRemove),
		local.NewPostRoute("/container/kill", r.postContainerKill),
		local.NewPostRoute("/exec/create", r.postContainerExecCreate),
		local.NewPostRoute("/exec/start", r.postContainerExecStart),
		local.NewPostRoute("/attach", r.postContainerAttach),
		local.NewPostRoute("/tty/resize", r.postTtyResize),
		local.NewPostRoute("/execvm", r.postExecVM),
		// PUT
		// DELETE
	}
}
1012088
func buildCopyModules(c *model.CommandConfig, revel_paths *model.RevelContainer, packageFolders []string) (err error) {
	destPath := filepath.Join(c.Build.TargetPath, "src")
	// Find all the modules used and copy them over.
	config := revel_paths.Config.Raw()
	modulePaths := make(map[string]string) // import path => filesystem path

	// We should only copy over the section of options what the build is targeted for
	// We will default to prod
	for _, section := range config.Sections() {
		// If the runmode is defined we will only import modules defined for that run mode
		if c.Build.Mode != "" && c.Build.Mode != section {
			continue
		}
		options, _ := config.SectionOptions(section)
		for _, key := range options {
			if !strings.HasPrefix(key, "module.") {
				continue
			}
			moduleImportPath, _ := config.String(section, key)
			if moduleImportPath == "" {
				continue
			}

			modPkg, err := build.Import(moduleImportPath, revel_paths.RevelPath, build.FindOnly)
			if err != nil {
				utils.Logger.Fatalf("Failed to load module %s (%s): %s", key[len("module."):], c.ImportPath, err)
			}
			modulePaths[moduleImportPath] = modPkg.Dir
		}
	}

	// Copy the the paths for each of the modules
	for importPath, fsPath := range modulePaths {
		utils.Logger.Info("Copy files ", "to", filepath.Join(destPath, importPath), "from", fsPath)
		if c.Build.CopySource {
			err = utils.CopyDir(filepath.Join(destPath, importPath), fsPath, nil)
			if err != nil {
				return
			}
		} else {
			for _, folder := range packageFolders {
				err = utils.CopyDir(
					filepath.Join(destPath, importPath, folder),
					filepath.Join(fsPath, folder),
					nil)
				if err != nil {
					return
				}
			}
		}
	}

	return
}
112585
func addModule(name, importPath, modulePath string) {
	if _, found := ModuleByName(name); found {
		moduleLog.Panic("Attempt to import duplicate module %s path %s aborting startup", "name", name, "path", modulePath)
	}
	Modules = append(Modules, &Module{Name: name,
		ImportPath: filepath.ToSlash(importPath),
		Path:       filepath.ToSlash(modulePath),
		Log:        RootLog.New("module", name)})
	if codePath := filepath.Join(modulePath, "app"); DirExists(codePath) {
		CodePaths = append(CodePaths, codePath)
		if viewsPath := filepath.Join(modulePath, "app", "views"); DirExists(viewsPath) {
			TemplatePaths = append(TemplatePaths, viewsPath)
		}
	}

	moduleLog.Debug("Loaded module ", "module", filepath.Base(modulePath))

	// Hack: There is presently no way for the testrunner module to add the
	// "test" subdirectory to the CodePaths.  So this does it instead.
	if importPath == Config.StringDefault("module.testrunner", "github.com/revel/modules/testrunner") {
		joinedPath := filepath.Join(BasePath, "tests")
		moduleLog.Debug("Found testrunner module, adding `tests` path ", "path", joinedPath)
		CodePaths = append(CodePaths, joinedPath)
	}
	if testsPath := filepath.Join(modulePath, "tests"); DirExists(testsPath) {
		moduleLog.Debug("Found tests path ", "path", testsPath)
		CodePaths = append(CodePaths, testsPath)
	}
}
29515
func (loader *TemplateLoader) initializeEngines(runtimeLoader *templateRuntime, templateEngineNameList string) (err *Error) {
	// Walk through the template loader's paths and build up a template set.
	if templateEngineNameList == "" {
		templateEngineNameList = GO_TEMPLATE

	}
	runtimeLoader.templatesAndEngineList = []TemplateEngine{}
	for _, engine := range strings.Split(templateEngineNameList, ",") {
		engine := strings.TrimSpace(strings.ToLower(engine))

		if templateLoader, err := loader.CreateTemplateEngine(engine); err != nil {
			runtimeLoader.compileError = &Error{
				Title:       "Panic (Template Loader)",
				Description: err.Error(),
			}
			return runtimeLoader.compileError
		} else {
			// Always assign a default engine, switch it if it is specified in the config
			runtimeLoader.templatesAndEngineList = append(runtimeLoader.templatesAndEngineList, templateLoader)
		}
	}
	return
}
1087964
func NewModule(name string) *Module {
	return &Module{
		Name:   name,
		Flags:  []cli.Flag{},
		Depend: Modules{},
	}
}
227197
func init() {
	for k, v := range ChanModeToString {
		StringToChanMode[v] = k
	}
	for k, v := range ChanPrivToString {
		StringToChanPriv[v] = k
	}
	for k, v := range ChanPrivToModeChar {
		ModeCharToChanPriv[v] = k
	}
}
840460
func (m *Module) Init(c *service.Config) {
	c.Setup = func() error {
		m.HTTPRouter = httprouter.New()
		m.ErrorHandler = func(rw http.ResponseWriter, req *http.Request, err error) {
			_ = m.HandleError(rw, req, err)
		}
		m.ErrorPage = func(rw http.ResponseWriter, req *http.Request, status int) {
			http.Error(rw, fmt.Sprint(status), status)
		}

		// root handler
		m.Root = http.NewServeMux()
		m.Root.Handle("/", m.HTTPRouter)
		m.Middleware = middleware.NewServer(m.Root.ServeHTTP)
		m.Config.ReadConfig(&m.config)
		return nil
	}

	c.Start = func() {
		laddr := m.laddr()
		m.Logger.Infof("listening on %s", laddr)
		m.server = &http.Server{Addr: laddr, Handler: m.Middleware}
		go m.server.ListenAndServe()
	}

	c.Stop = func() {
		m.Shutdown(context.Background())
	}
}
938057
func NewModule(addr addrs.ModuleInstance) *Module {
	return &Module{
		Addr:         addr,
		Resources:    map[string]*Resource{},
		OutputValues: map[string]*OutputValue{},
		LocalValues:  map[string]cty.Value{},
	}
}
422367
func ParseModule(filename, input string) (*Module, error) {
	stmts, comments, err := ParseStatements(filename, input)
	if err != nil {
		return nil, err
	}
	return parseModule(stmts, comments)
}