Beispiel #1
0
						&models.RunAction{
							User: "******",
							Path: "sh",
							Args: []string{
								"-c",
								`while true; do echo "sup dawg" | nc -l 127.0.0.1 -p 9999; done`,
							},
						},
					},
				}

				// busybox nc doesn't support -z
				lrp.Monitor = &models.RunAction{
					User: "******",
					Path: "sh",
					Args: []string{
						"-c",
						"echo -n '' | telnet localhost 3456 >/dev/null 2>&1 && true",
					},
				}
			})

			It("can ssh to appropriate app instance container", func() {
				verifySSH(address, processGuid, 0)
				verifySSH(address, processGuid, 1)
			})

			It("supports local port fowarding", func() {
				clientConfig := &ssh.ClientConfig{
					User: fmt.Sprintf("diego:%s/%d", processGuid, 0),
					Auth: []ssh.AuthMethod{ssh.Password("")},
				}
Beispiel #2
0
func (appRunner *appRunner) desireLrp(params CreateAppParams) error {
	primaryPort := uint16(0)
	if params.Monitor.Port != 0 {
		primaryPort = params.Monitor.Port
	} else if len(params.ExposedPorts) > 0 {
		primaryPort = params.ExposedPorts[0]
	}

	routes := appRunner.buildRoutes(params, primaryPort)

	vcapAppURIs := []string{}
	for _, route := range routes.AppRoutes {
		vcapAppURIs = append(vcapAppURIs, route.Hostnames...)
	}

	vcapApplication := struct {
		ApplicationName string   `json:"application_name"`
		ApplicationURIs []string `json:"application_uris"`
		Name            string   `json:"name"`
		URIs            []string `json:"uris"`
		Limits          struct {
			Disk   int `json:"disk,omitempty"`
			Memory int `json:"mem,omitempty"`
		} `json:"limits,omitempty"`
	}{}

	vcapApplication.ApplicationName = params.Name
	vcapApplication.Name = params.Name
	vcapApplication.ApplicationURIs = vcapAppURIs
	vcapApplication.URIs = vcapAppURIs
	vcapApplication.Limits.Disk = params.DiskMB
	vcapApplication.Limits.Memory = params.MemoryMB

	vcapAppBytes, err := json.Marshal(vcapApplication)
	if err != nil {
		return err
	}

	envVars := buildEnvironmentVariables(params.EnvironmentVariables)
	envVars = append(envVars, receptor.EnvironmentVariable{Name: "VCAP_APPLICATION", Value: string(vcapAppBytes)})
	envVars = append(envVars, receptor.EnvironmentVariable{Name: "PORT", Value: fmt.Sprintf("%d", primaryPort)})

	req := receptor.DesiredLRPCreateRequest{
		ProcessGuid:          params.Name,
		Domain:               lrpDomain,
		RootFS:               params.RootFS,
		Instances:            params.Instances,
		Routes:               routes.RoutingInfo(),
		CPUWeight:            params.CPUWeight,
		MemoryMB:             params.MemoryMB,
		DiskMB:               params.DiskMB,
		Privileged:           params.Privileged,
		Ports:                params.ExposedPorts,
		LogGuid:              params.Name,
		LogSource:            "APP",
		MetricsGuid:          params.Name,
		EnvironmentVariables: envVars,
		Annotation:           params.Annotation,
		Setup:                params.Setup,
		Action: &models.RunAction{
			Path: params.StartCommand,
			Args: params.AppArgs,
			Dir:  params.WorkingDir,
			User: params.User,
		},
	}

	var healthCheckArgs []string
	if params.Monitor.Timeout != 0 {
		healthCheckArgs = append(healthCheckArgs, "-timeout", fmt.Sprint(params.Monitor.Timeout))
	}
	switch params.Monitor.Method {
	case PortMonitor:
		req.Monitor = &models.RunAction{
			Path:      "/tmp/healthcheck",
			Args:      append(healthCheckArgs, "-port", fmt.Sprint(params.Monitor.Port)),
			LogSource: "HEALTH",
			User:      params.User,
		}
	case URLMonitor:
		req.Monitor = &models.RunAction{
			Path:      "/tmp/healthcheck",
			Args:      append(healthCheckArgs, "-port", fmt.Sprint(params.Monitor.Port), "-uri", params.Monitor.URI),
			LogSource: "HEALTH",
			User:      params.User,
		}
	}

	return appRunner.receptorClient.CreateDesiredLRP(req)
}
Beispiel #3
0
func (appRunner *appRunner) desireLrp(params CreateAppParams) error {
	primaryPort := uint16(0)
	if params.Monitor.Port != 0 {
		primaryPort = params.Monitor.Port
	} else if len(params.ExposedPorts) > 0 {
		primaryPort = params.ExposedPorts[0]
	}

	envVars := buildEnvironmentVariables(params.EnvironmentVariables)
	envVars = append(envVars, receptor.EnvironmentVariable{Name: "PORT", Value: fmt.Sprintf("%d", primaryPort)})

	var appRoutes route_helpers.AppRoutes
	if params.NoRoutes {
		appRoutes = route_helpers.AppRoutes{}
	} else if len(params.RouteOverrides) > 0 {
		routeMap := make(map[uint16][]string)
		for _, override := range params.RouteOverrides {
			routeMap[override.Port] = append(routeMap[override.Port], fmt.Sprintf("%s.%s", override.HostnamePrefix, appRunner.systemDomain))
		}
		for port, hostnames := range routeMap {
			appRoutes = append(appRoutes, route_helpers.AppRoute{
				Hostnames: hostnames,
				Port:      port,
			})
		}
	} else {
		appRoutes = appRunner.buildDefaultRoutingInfo(params.Name, params.ExposedPorts, primaryPort)
	}

	req := receptor.DesiredLRPCreateRequest{
		ProcessGuid:          params.Name,
		Domain:               lrpDomain,
		RootFS:               params.RootFS,
		Instances:            params.Instances,
		Routes:               appRoutes.RoutingInfo(),
		CPUWeight:            params.CPUWeight,
		MemoryMB:             params.MemoryMB,
		DiskMB:               params.DiskMB,
		Privileged:           params.Privileged,
		Ports:                params.ExposedPorts,
		LogGuid:              params.Name,
		LogSource:            "APP",
		MetricsGuid:          params.Name,
		EnvironmentVariables: envVars,
		Setup:                params.Setup,
		Action: &models.RunAction{
			Path: params.StartCommand,
			Args: params.AppArgs,
			Dir:  params.WorkingDir,
		},
	}

	var healthCheckArgs []string
	if params.Monitor.Timeout != 0 {
		healthCheckArgs = append(healthCheckArgs, "-timeout", fmt.Sprint(params.Monitor.Timeout))
	}
	switch params.Monitor.Method {
	case PortMonitor:
		req.Monitor = &models.RunAction{
			Path:      "/tmp/healthcheck",
			Args:      append(healthCheckArgs, "-port", fmt.Sprint(params.Monitor.Port)),
			LogSource: "HEALTH",
		}
	case URLMonitor:
		req.Monitor = &models.RunAction{
			Path:      "/tmp/healthcheck",
			Args:      append(healthCheckArgs, "-port", fmt.Sprint(params.Monitor.Port), "-uri", params.Monitor.URI),
			LogSource: "HEALTH",
		}
	}

	return appRunner.receptorClient.CreateDesiredLRP(req)
}
Beispiel #4
0
func (appRunner *appRunner) desireLrp(params CreateAppParams) error {
	primaryPort := route_helpers.GetPrimaryPort(params.Monitor.Port, params.ExposedPorts)

	private, public, err := appRunner.keygen.GenerateRSAKeyPair(2048)
	if err != nil {
		return err
	}

	routes := appRunner.buildRoutesWithDefaults(params, primaryPort)
	routes.DiegoSSHRoute = &route_helpers.DiegoSSHRoute{
		Port:       2222,
		PrivateKey: private,
	}

	vcapAppURIs := []string{}
	for _, route := range routes.AppRoutes {
		vcapAppURIs = append(vcapAppURIs, route.Hostnames...)
	}

	vcapApplication := struct {
		ApplicationName string   `json:"application_name"`
		ApplicationURIs []string `json:"application_uris"`
		Name            string   `json:"name"`
		URIs            []string `json:"uris"`
		Limits          struct {
			Disk   int `json:"disk,omitempty"`
			Memory int `json:"mem,omitempty"`
		} `json:"limits,omitempty"`
	}{}

	vcapApplication.ApplicationName = params.Name
	vcapApplication.Name = params.Name
	vcapApplication.ApplicationURIs = vcapAppURIs
	vcapApplication.URIs = vcapAppURIs
	vcapApplication.Limits.Disk = params.DiskMB
	vcapApplication.Limits.Memory = params.MemoryMB

	vcapAppBytes, err := json.Marshal(vcapApplication)
	if err != nil {
		return err
	}

	envVars := buildEnvironmentVariables(params.EnvironmentVariables)
	envVars = append(envVars, receptor.EnvironmentVariable{Name: "VCAP_APPLICATION", Value: string(vcapAppBytes)})
	envVars = append(envVars, receptor.EnvironmentVariable{Name: "PORT", Value: fmt.Sprintf("%d", primaryPort)})

	if _, exists := params.EnvironmentVariables["VCAP_SERVICES"]; !exists {
		envVars = append(envVars, receptor.EnvironmentVariable{Name: "VCAP_SERVICES", Value: "{}"})
	}

	setupAction := &models.SerialAction{
		Actions: []models.Action{
			params.Setup,
			&models.DownloadAction{
				From: "http://file_server.service.dc1.consul:8080/v1/static/diego-sshd.tgz",
				To:   "/tmp",
				User: "******",
			},
		},
	}

	hostKey, err := appRunner.keygen.GenerateRSAPrivateKey(2048)
	if err != nil {
		return err
	}

	req := receptor.DesiredLRPCreateRequest{
		ProcessGuid:          params.Name,
		Domain:               lrpDomain,
		RootFS:               params.RootFS,
		Instances:            params.Instances,
		Routes:               routes.RoutingInfo(),
		CPUWeight:            params.CPUWeight,
		MemoryMB:             params.MemoryMB,
		DiskMB:               params.DiskMB,
		Privileged:           params.Privileged,
		Ports:                append(params.ExposedPorts, 2222),
		LogGuid:              params.Name,
		LogSource:            "APP",
		MetricsGuid:          params.Name,
		EnvironmentVariables: envVars,
		Annotation:           params.Annotation,
		Setup:                setupAction,
		Action: &models.ParallelAction{
			Actions: []models.Action{
				&models.RunAction{
					Path: "/tmp/diego-sshd",
					Args: []string{
						"-address=0.0.0.0:2222",
						fmt.Sprintf("-authorizedKey=%s", public),
						fmt.Sprintf("-hostKey=%s", hostKey),
					},
					Dir:  "/tmp",
					User: params.User,
				},
				&models.RunAction{
					Path: params.StartCommand,
					Args: params.AppArgs,
					Dir:  params.WorkingDir,
					User: params.User,
				},
			},
		},
	}

	var healthCheckArgs []string
	if params.Monitor.Timeout != 0 {
		healthCheckArgs = append(healthCheckArgs, "-timeout", fmt.Sprint(params.Monitor.Timeout))
	}
	switch params.Monitor.Method {
	case PortMonitor:
		req.Monitor = &models.RunAction{
			Path:      "/tmp/healthcheck",
			Args:      append(healthCheckArgs, "-port", fmt.Sprint(params.Monitor.Port)),
			LogSource: "HEALTH",
			User:      params.User,
		}
	case URLMonitor:
		req.Monitor = &models.RunAction{
			Path:      "/tmp/healthcheck",
			Args:      append(healthCheckArgs, "-port", fmt.Sprint(params.Monitor.Port), "-uri", params.Monitor.URI),
			LogSource: "HEALTH",
			User:      params.User,
		}
	case CustomMonitor:
		req.Monitor = &models.RunAction{
			Path:      "/bin/sh",
			Args:      []string{"-c", params.Monitor.CustomCommand},
			LogSource: "HEALTH",
			User:      params.User,
		}
	}

	return appRunner.receptorClient.CreateDesiredLRP(req)
}
Beispiel #5
0
			Eventually(func() []receptor.ActualLRPResponse {
				lrps, err := receptorClient.ActualLRPsByProcessGuid(processGuid)
				Expect(err).NotTo(HaveOccurred())

				return lrps
			}).Should(HaveLen(1))

			Eventually(helpers.HelloWorldInstancePoller(componentMaker.Addresses.Router, helpers.DefaultHost)).Should(ConsistOf([]string{"0"}))
		})

		Context("when it's unhealthy for longer than its start timeout", func() {
			BeforeEach(func() {
				lrp.StartTimeout = 5

				lrp.Monitor = &models.RunAction{
					User: "******",
					Path: "false",
				}
			})

			It("eventually marks the LRP as crashed", func() {
				Eventually(func() []receptor.ActualLRPResponse {
					lrps, err := receptorClient.ActualLRPsByProcessGuid(processGuid)
					Expect(err).NotTo(HaveOccurred())

					return lrps
				}).Should(HaveLen(1))

				var actualLRP receptor.ActualLRPResponse
				Eventually(
					helpers.LRPStatePoller(receptorClient, processGuid, &actualLRP),
				).Should(Equal(receptor.ActualLRPStateCrashed))
Beispiel #6
0
func (appRunner *appRunner) desireLrp(params CreateAppParams) error {
	primaryPort := uint16(0)
	if params.Monitor.Port != 0 {
		primaryPort = params.Monitor.Port
	} else if len(params.ExposedPorts) > 0 {
		primaryPort = params.ExposedPorts[0]
	}

	envVars := buildEnvironmentVariables(params.EnvironmentVariables)
	envVars = append(envVars, receptor.EnvironmentVariable{Name: "PORT", Value: fmt.Sprintf("%d", primaryPort)})

	routes := appRunner.buildRoutes(params, primaryPort)

	req := receptor.DesiredLRPCreateRequest{
		ProcessGuid:          params.Name,
		Domain:               lrpDomain,
		RootFS:               params.RootFS,
		Instances:            params.Instances,
		Routes:               routes.RoutingInfo(),
		CPUWeight:            params.CPUWeight,
		MemoryMB:             params.MemoryMB,
		DiskMB:               params.DiskMB,
		Privileged:           params.Privileged,
		Ports:                params.ExposedPorts,
		LogGuid:              params.Name,
		LogSource:            "APP",
		MetricsGuid:          params.Name,
		EnvironmentVariables: envVars,
		Annotation:           params.Annotation,
		Setup:                params.Setup,
		Action: &models.RunAction{
			Path: params.StartCommand,
			Args: params.AppArgs,
			Dir:  params.WorkingDir,
			User: userForPrivilege(params.Privileged),
		},
	}

	var healthCheckArgs []string
	if params.Monitor.Timeout != 0 {
		healthCheckArgs = append(healthCheckArgs, "-timeout", fmt.Sprint(params.Monitor.Timeout))
	}
	switch params.Monitor.Method {
	case PortMonitor:
		req.Monitor = &models.RunAction{
			Path:      "/tmp/healthcheck",
			Args:      append(healthCheckArgs, "-port", fmt.Sprint(params.Monitor.Port)),
			LogSource: "HEALTH",
			User:      userForPrivilege(params.Privileged),
		}
	case URLMonitor:
		req.Monitor = &models.RunAction{
			Path:      "/tmp/healthcheck",
			Args:      append(healthCheckArgs, "-port", fmt.Sprint(params.Monitor.Port), "-uri", params.Monitor.URI),
			LogSource: "HEALTH",
			User:      userForPrivilege(params.Privileged),
		}
	}

	return appRunner.receptorClient.CreateDesiredLRP(req)
}