Esempio n. 1
0
func main() {
	host := oswrapper.Getopt("HOST", "127.0.0.1")
	etcdPort := oswrapper.Getopt("ETCD_PORT", "4001")
	etcdCtlPeers := oswrapper.Getopt("ETCD_PEERS", "127.0.0.1:"+etcdPort)
	etcdURL := etcd.GetHTTPEtcdUrls(host+":"+etcdPort, etcdCtlPeers)
	etcdClient := etcd.NewClient(etcdURL)

	etcd.Mkdir(etcdClient, etcdPath)

	log.Infof("boot version [%v]", version.Version)
	log.Info("zookeeper: starting...")

	zookeeper.CheckZkMappingInFleet(etcdPath, etcdClient, etcdURL)

	// we need to write the file /opt/zookeeper-data/data/myid with the id of this node
	os.MkdirAll("/opt/zookeeper-data/data", 0640)
	zkID := etcd.Get(etcdClient, etcdPath+"/"+host+"/id")
	ioutil.WriteFile("/opt/zookeeper-data/data/myid", []byte(zkID), 0640)

	zkServer := &zookeeper.ZkServer{
		Stdout: os.Stdout,
		Stderr: os.Stderr,
	}

	signal.Notify(signalChan,
		syscall.SIGHUP,
		syscall.SIGINT,
		syscall.SIGKILL,
		syscall.SIGTERM,
		syscall.SIGQUIT,
		os.Interrupt,
	)

	// Wait for a signal and exit
	exitChan := make(chan int)
	go func() {
		for {
			s := <-signalChan
			log.Debugf("Signal received: %v", s)
			switch s {
			case syscall.SIGTERM:
				exitChan <- 0
			case syscall.SIGQUIT:
				exitChan <- 0
			case syscall.SIGKILL:
				exitChan <- 1
			default:
				exitChan <- 1
			}
		}
	}()

	// wait for confd to run once and install initial templates
	confd.WaitForInitialConf(getConfdNodes(host, etcdCtlPeers, 4001), 10*time.Second)

	params := make(map[string]string)
	params["HOST"] = host
	if log.Level.String() == "debug" {
		params["DEBUG"] = "true"
	}

	err := oswrapper.RunScript("pkg/boot/zookeeper/bash/add-node.bash", params, bindata.Asset)
	if err != nil {
		log.Printf("command finished with error: %v", err)
	}

	if err := zkServer.Start(); err != nil {
		panic(err)
	}

	log.Info("zookeeper: running...")

	go func() {
		log.Debugf("starting pprof http server in port 6060")
		http.ListenAndServe("localhost:6060", nil)
	}()

	code := <-exitChan
	log.Debugf("execution terminated with exit code %v", code)

	log.Debugf("executing pre shutdown script")
	err = oswrapper.RunScript("pkg/boot/zookeeper/bash/remove-node.bash", params, bindata.Asset)
	if err != nil {
		log.Printf("command finished with error: %v", err)
	}

	log.Info("stopping zookeeper node")
	zkServer.Stop()
}
Esempio n. 2
0
	"strconv"
	"strings"
	"syscall"
	"time"

	"github.com/deis/deis/mesos/bindata/zookeeper"
	"github.com/deis/deis/mesos/pkg/boot/zookeeper"
	"github.com/deis/deis/mesos/pkg/confd"
	"github.com/deis/deis/mesos/pkg/etcd"
	logger "github.com/deis/deis/mesos/pkg/log"
	oswrapper "github.com/deis/deis/mesos/pkg/os"
	"github.com/deis/deis/version"
)

var (
	etcdPath   = oswrapper.Getopt("ETCD_PATH", "/zookeeper/nodes")
	log        = logger.New()
	signalChan = make(chan os.Signal, 1)
)

func main() {
	host := oswrapper.Getopt("HOST", "127.0.0.1")
	etcdPort := oswrapper.Getopt("ETCD_PORT", "4001")
	etcdCtlPeers := oswrapper.Getopt("ETCD_PEERS", "127.0.0.1:"+etcdPort)
	etcdURL := etcd.GetHTTPEtcdUrls(host+":"+etcdPort, etcdCtlPeers)
	etcdClient := etcd.NewClient(etcdURL)

	etcd.Mkdir(etcdClient, etcdPath)

	log.Infof("boot version [%v]", version.Version)
	log.Info("zookeeper: starting...")
Esempio n. 3
0
	"github.com/deis/deis/mesos/bindata/marathon"

	"github.com/deis/deis/mesos/pkg/boot"
	"github.com/deis/deis/mesos/pkg/etcd"
	logger "github.com/deis/deis/mesos/pkg/log"
	"github.com/deis/deis/mesos/pkg/os"
	"github.com/deis/deis/mesos/pkg/types"
)

const (
	mesosPort = 8180
)

var (
	etcdPath = os.Getopt("ETCD_PATH", "/mesos/marathon")
	log      = logger.New()
)

func init() {
	boot.RegisterComponent(new(MesosBoot), "boot")
}

func main() {
	boot.Start(etcdPath, mesosPort)
}

// MesosBoot struct for mesos boot.
type MesosBoot struct{}

// MkdirsEtcd creates a directory in  etcd.
Esempio n. 4
0
import (
	"strings"

	"github.com/deis/deis/mesos/pkg/boot"
	"github.com/deis/deis/mesos/pkg/etcd"
	logger "github.com/deis/deis/mesos/pkg/log"
	"github.com/deis/deis/mesos/pkg/os"
	"github.com/deis/deis/mesos/pkg/types"
)

const (
	mesosPort = 5050
)

var (
	etcdPath = os.Getopt("ETCD_PATH", "/mesos/master")
	log      = logger.New()
)

func init() {
	boot.RegisterComponent(new(MesosBoot), "boot")
}

func main() {
	boot.Start(etcdPath, mesosPort)
}

// MesosBoot struct to boot mesos.
type MesosBoot struct{}

// MkdirsEtcd creates a directory in  etcd.
Esempio n. 5
0
// Start initiate the boot process of the current component
// etcdPath is the base path used to publish the component in etcd
// externalPort is the base path used to publish the component in etcd
func Start(etcdPath string, externalPort int) {
	log.Infof("boot version [%v]", version.Version)

	go func() {
		log.Debugf("starting pprof http server in port 6060")
		http.ListenAndServe("localhost:6060", nil)
	}()

	signal.Notify(signalChan,
		syscall.SIGHUP,
		syscall.SIGINT,
		syscall.SIGKILL,
		syscall.SIGTERM,
		syscall.SIGQUIT,
		os.Interrupt,
	)

	// Wait for a signal and exit
	exitChan := make(chan int)
	go func() {
		for {
			s := <-signalChan
			log.Debugf("Signal received: %v", s)
			switch s {
			case syscall.SIGTERM:
				exitChan <- 0
			case syscall.SIGQUIT:
				exitChan <- 0
			case syscall.SIGKILL:
				exitChan <- 1
			default:
				exitChan <- 1
			}
		}
	}()

	component = bootProcess.Lookup("boot")
	if component == nil {
		log.Error("error loading boot extension...")
		signalChan <- syscall.SIGINT
	}

	host := oswrapper.Getopt("HOST", "127.0.0.1")
	etcdPort, _ := strconv.Atoi(oswrapper.Getopt("ETCD_PORT", "4001"))
	etcdPeers := oswrapper.Getopt("ETCD_PEERS", "127.0.0.1:"+strconv.Itoa(etcdPort))
	etcdClient := etcd.NewClient(etcd.GetHTTPEtcdUrls(host+":"+strconv.Itoa(etcdPort), etcdPeers))

	etcdURL := etcd.GetHTTPEtcdUrls(host+":"+strconv.Itoa(etcdPort), etcdPeers)

	currentBoot := &types.CurrentBoot{
		ConfdNodes: getConfdNodes(host+":"+strconv.Itoa(etcdPort), etcdPeers),
		EtcdClient: etcdClient,
		EtcdPath:   etcdPath,
		EtcdPort:   etcdPort,
		EtcdPeers:  etcdPeers,
		EtcdURL:    etcdURL,
		Host:       net.ParseIP(host),
		Timeout:    timeout,
		TTL:        timeout * 2,
		Port:       externalPort,
	}

	// do the real work in a goroutine to be able to exit if
	// a signal is received during the boot process
	go start(currentBoot)

	code := <-exitChan

	// pre shutdown tasks
	log.Debugf("executing pre shutdown scripts")
	preShutdownScripts := component.PreShutdownScripts(currentBoot)
	runAllScripts(signalChan, preShutdownScripts)

	log.Debugf("execution terminated with exit code %v", code)
	os.Exit(code)
}
Esempio n. 6
0
import (
	"strings"

	"github.com/deis/deis/mesos/pkg/boot"
	"github.com/deis/deis/mesos/pkg/etcd"
	logger "github.com/deis/deis/mesos/pkg/log"
	"github.com/deis/deis/mesos/pkg/os"
	"github.com/deis/deis/mesos/pkg/types"
)

const (
	mesosPort = 5051
)

var (
	etcdPath = os.Getopt("ETCD_PATH", "/mesos/slave")
	log      = logger.New()
)

func init() {
	boot.RegisterComponent(new(MesosBoot), "boot")
}

func main() {
	boot.Start(etcdPath, mesosPort)
}

// MesosBoot struct for mesos boot.
type MesosBoot struct{}

// MkdirsEtcd creates a directory in  etcd.