func (exec *sidecarExecutor) notifyDrain() {
	if !shouldCheckSidecar(exec.containerConfig) ||
		exec.config.SidecarDrainingDuration == 0 {
		return
	}
	sidecarUrl, err := url.Parse(exec.config.SidecarUrl)
	if err != nil {
		log.Errorf("Error parsing Sidercar URL: %s", err)
		return
	}
	if exec.containerID == "" {
		log.Error("Attempted to drain service with empty container ID")
		return
	}
	sidecarDrainServiceUrl := url.URL{
		Scheme: sidecarUrl.Scheme,
		Host:   sidecarUrl.Host,
		Path:   fmt.Sprintf("/api/services/%s/drain", exec.containerID[:12]),
	}
	drainer := func() (int, error) {
		resp, err := exec.fetcher.Post(sidecarDrainServiceUrl.String(), "", nil)
		if err != nil {
			return 0, err
		}
		defer resp.Body.Close()
		return resp.StatusCode, nil
	}
	log.Warnf("Setting service ID %q status to DRAINING in Sidecar", exec.containerID[:12])
	watcherDoneChan := make(chan struct{})
	go func() {
		exec.watcherWg.Wait()
		close(watcherDoneChan)
	}()
RETRIES:
	for i := 0; i <= exec.config.SidecarRetryCount; i++ {
		status, err := drainer()
		if err == nil && status == 202 {
			break
		}
		log.Warnf("Failed %d attempts to set service to DRAINING in Sidecar!", i+1)
		select {
		case <-watcherDoneChan:
			break RETRIES
		default:
		}
		time.Sleep(exec.config.SidecarRetryDelay)
	}
	ticker := time.NewTicker(exec.config.SidecarDrainingDuration)
	defer ticker.Stop()
	select {
	case <-ticker.C:
	case <-watcherDoneChan:
	}
}
notifyDrain instructs Sidecar to set the current service's status to DRAINING
package main
import (
	"encoding/json"
	"fmt"
	"io"
	"io/ioutil"
	"net/url"
	"os"
	"strconv"
	"strings"
	"time"
	"github.com/Nitro/sidecar-executor/container"
	"github.com/fsouza/go-dockerclient"
	log "github.com/sirupsen/logrus"
)
func (exec *sidecarExecutor) copyLogs(containerId string) {
	startTimeEpoch := time.Now().UTC().Add(0 - exec.config.LogsSince).Unix()
	container.GetLogs(
		exec.client, containerId, startTimeEpoch, os.Stdout, os.Stderr,
	)
}
func (exec *sidecarExecutor) handleContainerLogs(containerId string,
	labels map[string]string) {
	if exec.config.RelaySyslog || exec.config.RelaySyslogStartupOnly {
		var output io.Writer
		if exec.config.ContainerLogsStdout {
			output = os.Stdout
		} else {
			output = ioutil.Discard
		}
		exec.logsQuitChan = make(chan struct{})
		go exec.relayLogs(exec.logsQuitChan, containerId, labels, output)
	}
}
func (exec *sidecarExecutor) getMasterHostname() (string, error) {
	envEndpoint := os.Getenv("MESOS_AGENT_ENDPOINT")
	if len(envEndpoint) < 1 {  
		return "", fmt.Errorf("Can't get MESOS_AGENT_ENDPOINT from env! Won't provide Sidecar seeds.")
	}
	localEndpoint := "http://" + envEndpoint + "/state"
	localStruct := struct {
		MasterHostname string `json:"master_hostname"`
	}{}
	resp, err := exec.fetcher.Get(localEndpoint)
	if err != nil {
		return "", fmt.Errorf("Unable to fetch Mesos master info from worker endpoint: %s", err)
	}
	if resp.Body != nil {
		defer resp.Body.Close()
	}
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return "", fmt.Errorf("Error reading response body from Mesos worker! '%s'", err)
	}
	err = json.Unmarshal(body, &localStruct)
	if err != nil {
		return "", fmt.Errorf("Error parsing response body from Mesos worker! '%s'", err)
	}
	return localStruct.MasterHostname, nil
}
func (exec *sidecarExecutor) getWorkerHostnames(masterHostname string) ([]string, error) {
	masterAddr := masterHostname
	if exec.config.MesosMasterPort != "" {
		masterAddr += ":" + exec.config.MesosMasterPort
	}
	masterEndpoint := "http://" + masterAddr + "/slaves"
	type workersStruct struct {
		Hostname string `json:"hostname"`
	}
	masterStruct := struct {
		Slaves []workersStruct `json:"slaves"`
	}{}
	resp, err := exec.fetcher.Get(masterEndpoint)
	if err != nil {
		return nil, fmt.Errorf("Unable to fetch info from master endpoint: %s", err)
	}
	if resp.Body != nil {
		defer resp.Body.Close()
	}
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, fmt.Errorf("Error reading response body from Mesos master! '%s'", err)
	}
	err = json.Unmarshal(body, &masterStruct)
	if err != nil {
		return nil, fmt.Errorf("Error parsing response body from Mesos master! '%s'", err)
	}
	var workers []string
	for _, worker := range masterStruct.Slaves {
		workers = append(workers, worker.Hostname)
	}
	return workers, nil
}
func (exec *sidecarExecutor) addSidecarSeeds(envVars []string) []string {
	masterHostname, err := exec.getMasterHostname()
	if err != nil {
		log.Error(err.Error())
		return envVars
	}
	workerNames, err := exec.getWorkerHostnames(masterHostname)
	if err != nil {
		log.Error(err.Error())
		return envVars
	}
	return append(envVars, "SIDECAR_SEEDS="+strings.Join(workerNames, ","))
}