Esempio n. 1
0
	leverapi "github.com/leveros/leveros/api"
	"github.com/leveros/leveros/config"
	"github.com/leveros/leveros/core"
	"github.com/leveros/leveros/host"
	"github.com/leveros/leveros/leverutil"
)

// PackageName is the name of this package.
const PackageName = "apiserver"

var (
	// ListenPortFlag is the port the API server should listen on.
	ListenPortFlag = config.DeclareString(PackageName, "listenPort", "3503")
	// DisableAPIServerFlag disables the creation of an HTTP API server.
	DisableAPIServerFlag = config.DeclareBool(PackageName, "disableAPIServer")
)

var logger = leverutil.GetLogger(PackageName, "Server")

const maxNonChanRequestSize = 512 * 1024 // 512 KiB

var bufferedReaderPool = &sync.Pool{
	New: func() interface{} {
		return bufio.NewReaderSize(nil, maxNonChanRequestSize)
	},
}

var bufferPool = &sync.Pool{
	New: func() interface{} {
		return make([]byte, maxNonChanRequestSize)
Esempio n. 2
0
	// DockerSwarmFlag is the docker swarm endpoint.
	DockerSwarmFlag = config.DeclareString(
		PackageName, "dockerSwarm", "unix:///var/run/docker.sock")
	// DockerLocalFlag is the local docker endpoint.
	DockerLocalFlag = config.DeclareString(
		PackageName, "dockerLocal", "unix:///var/run/docker.sock")

	// LeverCodeHostDirFlag is the location on the host (outside docker) of the
	// mounted customer code directory, containing all code from all
	// environments and services.
	LeverCodeHostDirFlag = config.DeclareString(
		PackageName, "leverCodeHostDir", "/tmp/leveros/custcodetree")

	// DisableRemoveContainerFlag causes Lever containers to not be
	// removed (on errors, on exit etc).
	DisableRemoveContainerFlag = config.DeclareBool(
		PackageName, "disableRemoveContainer")
)

var logger = leverutil.GetLogger(PackageName, "dockerutil")

var (
	ownContainerIDOnce sync.Once
	ownContainerID     = ""
)

// HostCodeDirPath returns the path on the docker host that the code for a given
// service version is found at.
func HostCodeDirPath(environment, service string, codeVersion int64) string {
	return filepath.Join(
		LeverCodeHostDirFlag.Get(), environment, service,
		strconv.Itoa(int(codeVersion)))
Esempio n. 3
0
import (
	"strconv"
	"strings"
	"time"

	aerospike "github.com/aerospike/aerospike-client-go"
	"github.com/leveros/leveros/config"
	"github.com/leveros/leveros/scale"
)

const leverOSNamespace = "leveros"

var (
	// AerospikeFromConsulFlag indicates whether Consul should be used to get
	// an Aerospike client.
	AerospikeFromConsulFlag = config.DeclareBool(
		PackageName, "aerospikeFromConsul")
	// AerospikeFixedAddrFlag indicates a fixed address which is used if
	// AerospikeFromConsulFlag is false.
	AerospikeFixedAddrFlag = config.DeclareString(
		PackageName, "aerospikeFixedAddr", "leverosaerospike:3000")
)

// NewAerospike returns a new Aerospike client.
func NewAerospike() (as *aerospike.Client, err error) {
	var target string
	if AerospikeFromConsulFlag.Get() {
		for retry := 0; retry < 15; retry++ {
			target, _, err = scale.DereferenceService("aerospike")
			if err == nil {
				break
			}
Esempio n. 4
0
	"github.com/leveros/leveros/scale"
)

var (
	// ConnectionExpiryFlag is the inactivity time after which client
	// connections are closed.
	ConnectionExpiryFlag = config.DeclareDuration(
		PackageName, "connectionExpiry", 5*time.Minute)
	// ConnectionConnectTimeoutFlag is the timeout for client connections to
	// establish.
	ConnectionConnectTimeoutFlag = config.DeclareDuration(
		PackageName, "connectionConnectTimeout", 20*time.Second)

	// DisableProxyExtFlag enables listening to the external interface
	// (regional LB).
	DisableProxyExtFlag = config.DeclareBool(
		PackageName, "disableProxyExt")
	// DisableProxyInOutFlag enables listening to requests going to or coming
	// from a local environment.
	DisableProxyInOutFlag = config.DeclareBool(
		PackageName, "disableProxyInOut")

	// EnvOutListenPortFlag is the environment listen port for outward
	// connections. This port is accessible only from within the env network.
	EnvOutListenPortFlag = config.DeclareString(
		PackageName, "envOutListenPort", "3838")
	// EnvInListenPortFlag is the listen port for inward connections.
	EnvInListenPortFlag = config.DeclareString(
		PackageName, "envInListenPort", "3500")
	// EnvExtListenPortFlag is the listen port for external connections.
	EnvExtListenPortFlag = config.DeclareString(
		PackageName, "envExtListenPort", "3502")
Esempio n. 5
0
)

// PackageName is the name of this package.
const PackageName = "devlogger"

var (
	// DevLoggerListenPortFlag is the port to listen to for syslog messages.
	DevLoggerListenPortFlag = config.DeclareString(
		PackageName, "devLoggerListenPort", "6514")
	// InstanceIDFlag is the instance ID of the devlogger. Note: This is a
	// different instance ID than leverutil.InstanceIDFlag because they serve
	// different things.
	InstanceIDFlag = config.DeclareString(
		PackageName, "instanceID", leverutil.RandomID())
	// DisableFlag disables the devlogger server.
	DisableFlag = config.DeclareBool(PackageName, "disable")
)

var logger = leverutil.GetLogger(PackageName, "DevLogger")

// DevLoggerService is the name of the devlogger internal service.
const DevLoggerService = "devlogger"

// DevLogger is a syslog server meant to be used only for dev instances of
// Lever. It doesn't have the necessary redundancy and safeguards in place for
// production use.
type DevLogger struct {
	server     *syslog.Server
	serviceSKA *scale.SelfKeepAlive
	channel    syslog.LogPartsChannel
}
Esempio n. 6
0
	"github.com/Sirupsen/logrus"
	"github.com/leveros/leveros/config"
	prefixed "github.com/x-cray/logrus-prefixed-formatter"
)

var (
	// LoggingFormatFlag is the format of log lines.
	LoggingFormatFlag = config.DeclareString(
		PackageName, "loggingFormat", "colortext")
	// LoggingLevelFlag is the minimum level to log.
	LoggingLevelFlag = config.DeclareString(
		PackageName, "loggingLevel", "info")
	// LogInstanceAndServiceFlag causes all loggers to also log the instance ID
	// and service name of the process. Useful if logs from multiple sources
	// are merged and need to be filtered afterwards.
	LogInstanceAndServiceFlag = config.DeclareBool(
		PackageName, "logInstanceAndService")
)

// UpdateLoggingSettings initializes logging based on config params.
func UpdateLoggingSettings() {
	format := LoggingFormatFlag.Get()
	switch format {
	case "colortext":
		logrus.SetFormatter(&prefixed.TextFormatter{
			ShortTimestamp: true,
			ForceColors:    true,
		})
	case "text":
		logrus.SetFormatter(&logrus.TextFormatter{})
	case "json":
		logrus.SetFormatter(&logrus.JSONFormatter{})