// Bootstrap prepares our application.
//
// Returns itself.
542408
func (b *Bootstrapper) Bootstrap() *Bootstrapper {
	b.SetupViews("./views")
	b.SetupSessions(24*time.Hour,
		[]byte("the-big-and-secret-fash-key-here"),
		[]byte("lot-secret-of-characters-big-too"),
	)
	b.SetupErrorHandlers()

	// static files
	b.Favicon(StaticAssets + Favicon)
	b.StaticWeb(StaticAssets[1:len(StaticAssets)-1], StaticAssets)

	// middleware, after static files
	b.Use(recover.New())
	b.Use(logger.New())

	return b
}
1025441
func LoadState(stor storage.StorageReader) (*BootstrapState, error) {
	r, err := storage.Get(stor, StateFile)
	if err != nil {
		if errors.IsNotFound(err) {
			return nil, environs.ErrNotBootstrapped
		}
		return nil, err
	}
	return loadState(r)
}
1222139
func (p *plugin) bootstrap() error {
	// create a new instance of the plugin via the
	// factory
	p.instance = reflect.New(reflect.TypeOf(p.iFace.Factory))
	instanceVal := reflect.ValueOf(p.instance.Interface()).Elem()

	// get list of methods
	for _, method := range p.iFace.methods {
		methodExported := getExportedFnName(p.name, method)
		factoryMethodName := getFactoryFnFieldName(method)
		factoryMethod := instanceVal.FieldByName(factoryMethodName)
		if !factoryMethod.IsValid() {
			return errors.New("Plugin factory missing method")
		}
		factoryMethodPtr := factoryMethod.Addr()

		// attach factory method to exported method
		p.lib.Sym(methodExported, factoryMethodPtr.Interface())
		if factoryMethodPtr.IsNil() {
			return errors.New("Could not get exported plugin method symbol")
		}
	}

	return nil
}
545788
func Bootstrap(config Config) error {
	if config.FSM != nil {
		return errors.NotValidf("non-nil FSM during Bootstrap")
	}
	if config.Transport != nil {
		return errors.NotValidf("non-nil Transport during Bootstrap")
	}

	// During bootstrap we use an in-memory transport. We just need
	// to make sure we use the same local address as we'll use later.
	_, transport := raft.NewInmemTransport(bootstrapAddress)
	defer transport.Close()
	config.Transport = transport

	// During bootstrap, we do not require an FSM.
	config.FSM = BootstrapFSM{}

	w, err := newWorker(config)
	if err != nil {
		return errors.Trace(err)
	}
	defer worker.Stop(w)

	r, err := w.Raft()
	if err != nil {
		return errors.Trace(err)
	}

	if err := r.BootstrapCluster(raft.Configuration{
		Servers: []raft.Server{{
			ID:      config.LocalID,
			Address: bootstrapAddress,
		}},
	}).Error(); err != nil {
		return errors.Annotate(err, "bootstrapping raft cluster")
	}
	return errors.Annotate(worker.Stop(w), "stopping bootstrap raft worker")
}
297366
func (m *MockZonedEnviron) PrepareForBootstrap(arg0 environs.BootstrapContext, arg1 string) error {
	ret := m.ctrl.Call(m, "PrepareForBootstrap", arg0, arg1)
	ret0, _ := ret[0].(error)
	return ret0
}
769133
func (l *listenerManager) bootstrap(lastSnap string) {
	if l.isOfflineMode && lastSnap == "" {
		log.Panic("Diagnostic mode requires existent snapshot info in default DB.")
	}

	if lastSnap != "" {
		if err := l.snapMan.startOnDataSnapshot(lastSnap); err == nil {
			log.Infof("Started on local snapshot: %s", lastSnap)
			l.changeMan.pollChangeWithBackoff()
			return
		} else {
			log.Errorf("Failed to bootstrap on local snapshot: %v", err)
			log.Warn("Will get new snapshots.")
		}
	}

	l.snapMan.downloadBootSnapshot()
	if err := l.snapMan.downloadDataSnapshot(); err != nil {
		log.Panicf("Error downloading data snapshot: %v", err)
	}
	l.changeMan.pollChangeWithBackoff()
}
1089079
func (b *Bootstrap) Register(m app.Module) error {
	if b.inited {
		return fmt.Errorf("Can not add module after inited")
	}
	b.modules = append(b.modules, m)
	return nil
}
372395
func (toolkit GoToolkit) Bootstrap() error {
	if toolkit.IsToolAvailableInPATH() {
		return nil
	}

	pthWithGoBins := configs.GeneratePATHEnvString(os.Getenv("PATH"), goToolkitBinsPath())
	if err := os.Setenv("PATH", pthWithGoBins); err != nil {
		return fmt.Errorf("Failed to set PATH to include the Go toolkit bins, error: %s", err)
	}

	if err := os.Setenv("GOROOT", goToolkitInstallRootPath()); err != nil {
		return fmt.Errorf("Failed to set GOROOT to Go toolkit root, error: %s", err)
	}

	return nil
}
1167486
func (e *Environ) PrepareForBootstrap(ctx environs.BootstrapContext, controllerName string) error {
	// Verify credentials.
	if err := authenticateClient(e.client()); err != nil {
		return err
	}
	if !e.supportsNeutron() {
		logger.Warningf(`Using deprecated OpenStack APIs.

  Neutron networking is not supported by this OpenStack cloud.
  Falling back to deprecated Nova networking.

  Support for deprecated Nova networking APIs will be removed
  in a future Juju release. Please upgrade to OpenStack Icehouse
  or newer to maintain compatibility.

`,
		)
	}
	return nil
}
131200
func bootstrapData(data *bootstrappolicy.PolicyData) *rbacrest.PolicyData {
	return &rbacrest.PolicyData{
		ClusterRoles:            data.ClusterRoles,
		ClusterRoleBindings:     data.ClusterRoleBindings,
		Roles:                   data.Roles,
		RoleBindings:            data.RoleBindings,
		ClusterRolesToAggregate: data.ClusterRolesToAggregate,
	}
}
83635
func bootstrapCmd(ctx *cli.Context) error {
	cloud := ctx.String("auth")

	resp, err := bootstrap.Do(
		bootstrap.Provider(cloud),
		ctx.String("url"),
		ctx.String("machine"),
		ctx.String("org"),
		ctx.String("role"),
		ctx.String("ca"),
	)
	if err != nil {
		return fmt.Errorf("bootstrap provision failed: %s", err)
	}

	envFile := filepath.Join(GlobalRoot, EnvironmentFile)
	err = writeEnvironmentFile(resp.Token, resp.Secret)
	if err != nil {
		return fmt.Errorf("failed to write environment file[%s]: %s", envFile, err)
	}

	fmt.Printf("Machine bootstrapped. Environment configuration saved in %s\n", envFile)
	return nil
}
1096654
func (dp DefaultProvider) BootstrapEnv(ctx environs.BootstrapContext, callCtx context.ProviderCallContext, args environs.BootstrapParams) (*environs.BootstrapResult, error) {
	result, err := Bootstrap(ctx, dp.Env, callCtx, args)
	if err != nil {
		return nil, errors.Trace(err)
	}
	return result, nil
}
892698
func ReadBootstrapConfigFile(file string) (map[string]BootstrapConfig, error) {
	data, err := ioutil.ReadFile(file)
	if err != nil {
		if os.IsNotExist(err) {
			return nil, nil
		}
		return nil, err
	}
	configs, err := ParseBootstrapConfig(data)
	if err != nil {
		return nil, err
	}
	return configs, nil
}
457016
func (env *azureEnviron) Bootstrap(
	ctx environs.BootstrapContext,
	callCtx context.ProviderCallContext,
	args environs.BootstrapParams,
) (*environs.BootstrapResult, error) {
	if err := env.initResourceGroup(callCtx, args.ControllerConfig.ControllerUUID(), true); err != nil {
		return nil, errors.Annotate(err, "creating controller resource group")
	}
	result, err := common.Bootstrap(ctx, env, callCtx, args)
	if err != nil {
		logger.Errorf("bootstrap failed, destroying model: %v", err)
		if err := env.Destroy(callCtx); err != nil {
			logger.Errorf("failed to destroy model: %v", err)
		}
		return nil, errors.Trace(err)
	}
	return result, nil
}
1310402
func (env *environ) Bootstrap(
	ctx environs.BootstrapContext,
	callCtx callcontext.ProviderCallContext,
	args environs.BootstrapParams,
) (result *environs.BootstrapResult, err error) {
	// NOTE(axw) we must not pass a sessionEnviron to common.Bootstrap,
	// as the Environ will be used during instance finalization after
	// the Bootstrap method returns, and the session will be invalid.
	if err := env.withSession(callCtx, func(env *sessionEnviron) error {
		return env.ensureVMFolder(args.ControllerConfig.ControllerUUID(), callCtx)
	}); err != nil {
		return nil, errors.Trace(err)
	}
	return Bootstrap(ctx, env, callCtx, args)
}
796714
func (s *Server) Boot() error {
	if s.format == nil {
		return errors.New("please set a valid format")
	}

	if s.handler == nil {
		return errors.New("please set a valid handler")
	}

	for _, listener := range s.listeners {
		s.goAcceptConnection(listener)
	}

	if len(s.connections) > 0 {
		s.goParseDatagrams()
	}

	for _, connection := range s.connections {
		s.goReceiveDatagrams(connection)
	}

	return nil
}
927341
func NewBootstrap(gapp app.App) app.Bootstrap {
	return &Bootstrap{
		gapp:    gapp,
		modules: []app.Module{},
		inited:  false,
		runed:   false,
	}
}