本文整理汇总了Golang中github.com/Masterminds/cookoo/log.Errf函数的典型用法代码示例。如果您正苦于以下问题:Golang Errf函数的具体用法?Golang Errf怎么用?Golang Errf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Errf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: RemoveMemberByName
// RemoveMemberByName removes a member whose name matches the given.
//
// Params:
// - client(client.Client): An etcd client
// - name (string): The name to remove
// Returns:
// true if the member was found, false otherwise.
func RemoveMemberByName(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
cli := p.Get("client", nil).(client.Client)
name := p.Get("name", "____").(string)
mem := client.NewMembersAPI(cli)
members, err := mem.List(dctx())
if err != nil {
log.Errf(c, "Could not get a list of members: %s", err)
return false, err
}
remIDs := []string{}
for _, member := range members {
if member.Name == name {
log.Infof(c, "Removing member %s (ID: %s)", name, member.ID)
// If this is synchronizable, we should do it in parallel.
if err := mem.Remove(dctx(), member.ID); err != nil {
log.Errf(c, "Failed to remove member: %s", err)
return len(remIDs) > 0, err
}
remIDs = append(remIDs, member.ID)
}
}
return len(remIDs) > 0, nil
}
开发者ID:bacongobbler,项目名称:pkg,代码行数:33,代码来源:members.go
示例2: ParseHostKeys
// ParseHostKeys parses the host key files.
//
// By default it looks in /etc/ssh for host keys of the patterh ssh_host_{{TYPE}}_key.
//
// Params:
// - keytypes ([]string): Key types to parse. Defaults to []string{rsa, dsa, ecdsa}
// - enableV1 (bool): Allow V1 keys. By default this is disabled.
// - path (string): Override the lookup pattern. If %s, it will be replaced with the keytype.
//
// Returns:
// []ssh.Signer
func ParseHostKeys(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
log.Debugf(c, "Parsing ssh host keys")
hostKeyTypes := p.Get("keytypes", []string{"rsa", "dsa", "ecdsa"}).([]string)
pathTpl := p.Get("path", "/etc/ssh/ssh_host_%s_key").(string)
hostKeys := make([]ssh.Signer, 0, len(hostKeyTypes))
for _, t := range hostKeyTypes {
path := fmt.Sprintf(pathTpl, t)
if key, err := ioutil.ReadFile(path); err == nil {
if hk, err := ssh.ParsePrivateKey(key); err == nil {
log.Infof(c, "Parsed host key %s.", path)
hostKeys = append(hostKeys, hk)
} else {
log.Errf(c, "Failed to parse host key %s (skipping): %s", path, err)
}
}
}
if c.Get("enableV1", false).(bool) {
path := "/etc/ssh/ssh_host_key"
if key, err := ioutil.ReadFile(path); err != nil {
log.Errf(c, "Failed to read ssh_host_key")
} else if hk, err := ssh.ParsePrivateKey(key); err == nil {
log.Infof(c, "Parsed host key %s.", path)
hostKeys = append(hostKeys, hk)
} else {
log.Errf(c, "Failed to parse host key %s: %s", path, err)
}
}
return hostKeys, nil
}
开发者ID:vdice,项目名称:builder,代码行数:41,代码来源:sshd.go
示例3: iam
// iam injects info into the environment about a host's self.
//
// Sets the following environment variables. (Values represent the data format.
// Instances will get its own values.)
//
// MY_NODEIP=10.245.1.3
// MY_SERVICE_IP=10.22.1.4
// MY_PORT_PEER=2380
// MY_PORT_CLIENT=2379
// MY_NAMESPACE=default
// MY_SELFLINK=/api/v1/namespaces/default/pods/deis-etcd-1-336jp
// MY_UID=62a3b54a-6956-11e5-b8ab-0800279dd272
// MY_APISERVER=https://10.247.0.1:443
// MY_NAME=deis-etcd-1-336jp
// MY_IP=10.246.44.7
// MY_LABEL_NAME=deis-etcd-1 # One entry per label in the JSON
// MY_ANNOTATION_NAME=deis-etcd-1 # One entry per annitation in the JSON
// MY_PORT_CLIENT=4100
// MY_PORT_PEER=2380
func iam(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
me, err := aboutme.FromEnv()
if err != nil {
log.Errf(c, "Failed aboutme.FromEnv: %s", err)
} else {
if strings.TrimSpace(me.IP) == "" {
log.Warn(c, "No IP found by API query.")
ip, err := aboutme.MyIP()
if err != nil || ip == "" {
// Force pod death.
log.Errf(c, "Failed to get an IP address: %s", err)
os.Exit(5)
}
}
me.ShuntEnv()
os.Setenv("ETCD_NAME", me.Name)
c.Put("ETCD_NAME", me.Name)
}
passEnv("MY_PORT_CLIENT", "$DEIS_ETCD_1_SERVICE_PORT_CLIENT")
passEnv("MY_PORT_PEER", "$DEIS_ETCD_1_SERVICE_PORT_PEER")
return nil, nil
}
开发者ID:bacongobbler,项目名称:etcd,代码行数:44,代码来源:boot.go
示例4: Watch
// Watch watches a given path, and executes a git check-repos for each event.
//
// It starts the watcher and then returns. The watcher runs on its own
// goroutine. To stop the watching, send the returned channel a bool.
//
// Params:
// - client (Watcher): An Etcd client.
// - path (string): The path to watch
func Watch(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
// etcdctl -C $ETCD watch --recursive /deis/services
path := p.Get("path", "/deis/services").(string)
cli := p.Get("client", nil).(client.Client)
k := client.NewKeysAPI(cli)
watcher := k.Watcher(path, &client.WatcherOptions{Recursive: true})
safely.GoDo(c, func() {
for {
// TODO: We should probably add cancellation support.
response, err := watcher.Next(dctx())
if err != nil {
log.Errf(c, "Etcd Watch failed: %s", err)
}
if response.Node == nil {
log.Infof(c, "Unexpected Etcd message: %v", response)
}
git := exec.Command("/home/git/check-repos")
if out, err := git.CombinedOutput(); err != nil {
log.Errf(c, "Failed git check-repos: %s", err)
log.Infof(c, "Output: %s", out)
}
}
})
return nil, nil
}
开发者ID:helgi,项目名称:pkg,代码行数:36,代码来源:etcd.go
示例5: keysToEtcd
// keysToEtcd copies local keys into etcd.
//
// It only fails if it cannot copy ssh_host_key to sshHostKey. All other
// abnormal conditions are logged, but not considered to be failures.
func keysToEtcd(c cookoo.Context, client Setter, ciphers []string, etcdPath string) error {
firstpath := ""
lpath := "/etc/ssh/ssh_host_%s_key"
privkey := "%s/sshHost%sKey"
for _, cipher := range ciphers {
path := fmt.Sprintf(lpath, cipher)
key := fmt.Sprintf(privkey, etcdPath, cipher)
content, err := ioutil.ReadFile(path)
if err != nil {
log.Infof(c, "No key named %s", path)
} else if _, err := client.Set(key, string(content), 0); err != nil {
log.Errf(c, "Could not store ssh key in etcd: %s", err)
}
// Remember the first key's path in case the generic key is missing
if firstpath == "" {
firstpath = path
}
}
// Now we set the generic key:
keypath := "/etc/ssh/ssh_host_key"
if _, err := os.Stat(keypath); os.IsNotExist(err) && firstpath != "" {
// Use ssh_host_dsa_key if newer ssh-keygen didn't create ssh_host_key
keypath = firstpath
}
if content, err := ioutil.ReadFile(keypath); err != nil {
log.Errf(c, "Could not read the %s file.", keypath)
return err
} else if _, err := client.Set("sshHostKey", string(content), 0); err != nil {
log.Errf(c, "Failed to set sshHostKey in etcd.")
return err
}
return nil
}
开发者ID:CodeJuan,项目名称:deis,代码行数:37,代码来源:etcd.go
示例6: Watch
// Watch watches a given path, and executes a git check-repos for each event.
//
// It starts the watcher and then returns. The watcher runs on its own
// goroutine. To stop the watching, send the returned channel a bool.
//
// Params:
// - client (Watcher): An Etcd client.
// - path (string): The path to watch
//
// Returns:
// - chan bool: Send this a message to stop the watcher.
func Watch(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
// etcdctl -C $ETCD watch --recursive /deis/services
path := p.Get("path", "/deis/services").(string)
cli, ok := p.Has("client")
if !ok {
return nil, errors.New("No etcd client found.")
}
client := cli.(Watcher)
// Stupid hack because etcd watch seems to be broken, constantly complaining
// that the JSON it received is malformed.
safely.GoDo(c, func() {
for {
response, err := client.Watch(path, 0, true, nil, nil)
if err != nil {
log.Errf(c, "Etcd Watch failed: %s", err)
time.Sleep(50 * time.Millisecond)
continue
}
if response.Node == nil {
log.Infof(c, "Unexpected Etcd message: %v", response)
}
git := exec.Command("/home/git/check-repos")
if out, err := git.CombinedOutput(); err != nil {
log.Errf(c, "Failed git check-repos: %s", err)
log.Infof(c, "Output: %s", out)
}
}
})
return nil, nil
}
开发者ID:smothiki,项目名称:builder,代码行数:46,代码来源:etcd.go
示例7: keysToLocal
// keysToLocal copies SSH host keys from etcd to the local file system.
//
// This only fails if the main key, sshHostKey cannot be stored or retrieved.
func keysToLocal(c cookoo.Context, client Getter, ciphers []string, etcdPath string) error {
lpath := "/etc/ssh/ssh_host_%s_key"
privkey := "%s/sshHost%sKey"
for _, cipher := range ciphers {
path := fmt.Sprintf(lpath, cipher)
key := fmt.Sprintf(privkey, etcdPath, cipher)
res, err := client.Get(key, false, false)
if err != nil || res.Node == nil {
continue
}
content := res.Node.Value
if err := ioutil.WriteFile(path, []byte(content), 0600); err != nil {
log.Errf(c, "Error writing ssh host key file: %s", err)
}
}
// Now get generic key.
res, err := client.Get("sshHostKey", false, false)
if err != nil || res.Node == nil {
return fmt.Errorf("Failed to get sshHostKey from etcd. %v", err)
}
content := res.Node.Value
if err := ioutil.WriteFile("/etc/ssh/ssh_host_key", []byte(content), 0600); err != nil {
log.Errf(c, "Error writing ssh host key file: %s", err)
return err
}
return nil
}
开发者ID:naveenholla,项目名称:deis,代码行数:33,代码来源:etcd.go
示例8: Run
// Run starts the Builder service.
//
// The Builder service is responsible for setting up the local container
// environment and then listening for new builds. The main listening service
// is SSH. Builder listens for new Git commands and then sends those on to
// Git.
//
// Run returns on of the Status* status code constants.
func Run(cmd string) int {
reg, router, ocxt := cookoo.Cookoo()
log.SetFlags(0) // Time is captured elsewhere.
// We layer the context to add better logging and also synchronize
// access so that goroutines don't get into race conditions.
cxt := cookoo.SyncContext(ocxt)
cxt.Put("cookoo.Router", router)
cxt.AddLogger("stdout", os.Stdout)
// Build the routes. See routes.go.
routes(reg)
// Bootstrap the background services. If this fails, we stop.
if err := router.HandleRequest("boot", cxt, false); err != nil {
clog.Errf(cxt, "Fatal errror on boot: %s", err)
return StatusLocalError
}
// Set up the SSH service.
ip := os.Getenv("SSH_HOST_IP")
if ip == "" {
ip = "0.0.0.0"
}
port := os.Getenv("SSH_HOST_PORT")
if port == "" {
port = "2223"
}
cxt.Put(sshd.Address, ip+":"+port)
// Supply route names for handling various internal routing. While this
// isn't necessary for Cookoo, it makes it easy for us to mock these
// routes in tests. c.f. sshd/server.go
cxt.Put("route.sshd.pubkeyAuth", "pubkeyAuth")
cxt.Put("route.sshd.sshPing", "sshPing")
cxt.Put("route.sshd.sshGitReceive", "sshGitReceive")
// Start the SSH service.
// TODO: We could refactor Serve to be a command, and then run this as
// a route.
if err := sshd.Serve(reg, router, cxt); err != nil {
clog.Errf(cxt, "SSH server failed: %s", err)
return StatusLocalError
}
return StatusOk
}
开发者ID:smothiki,项目名称:builder,代码行数:56,代码来源:builder.go
示例9: handleConn
// handleConn handles an individual client connection.
//
// It manages the connection, but passes channels on to `answer()`.
func (s *server) handleConn(conn net.Conn, conf *ssh.ServerConfig) {
defer conn.Close()
log.Info(s.c, "Accepted connection.")
_, chans, reqs, err := ssh.NewServerConn(conn, conf)
if err != nil {
// Handshake failure.
log.Errf(s.c, "Failed handshake: %s (%v)", err, conn)
return
}
// Discard global requests. We're only concerned with channels.
safely.GoDo(s.c, func() { ssh.DiscardRequests(reqs) })
condata := sshConnection(conn)
// Now we handle the channels.
for incoming := range chans {
log.Infof(s.c, "Channel type: %s\n", incoming.ChannelType())
if incoming.ChannelType() != "session" {
incoming.Reject(ssh.UnknownChannelType, "Unknown channel type")
}
channel, req, err := incoming.Accept()
if err != nil {
// Should close request and move on.
panic(err)
}
safely.GoDo(s.c, func() { s.answer(channel, req, condata) })
}
conn.Close()
}
开发者ID:yun-an,项目名称:deis,代码行数:34,代码来源:server.go
示例10: ParallelBuild
// ParallelBuild runs multiple docker builds at the same time.
//
// Params:
// -images ([]BuildImg): Images to build
// -alwaysFetch (bool): Default false. If set to true, this will always fetch
// the Docker image even if it already exists in the registry.
//
// Returns:
//
// - Waiter: A *sync.WaitGroup that is waiting for the docker downloads to finish.
//
// Context:
//
// This puts 'ParallelBuild.failN" (int) into the context to indicate how many failures
// occurred during fetches.
func ParallelBuild(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
images := p.Get("images", []BuildImg{}).([]BuildImg)
var wg sync.WaitGroup
var m sync.Mutex
var fails int
for _, img := range images {
img := img
wg.Add(1)
safely.GoDo(c, func() {
log.Infof(c, "Starting build for %s (tag: %s)", img.Path, img.Tag)
if _, err := buildImg(c, img.Path, img.Tag); err != nil {
log.Errf(c, "Failed to build docker image: %s", err)
m.Lock()
fails++
m.Unlock()
}
wg.Done()
})
}
// Number of failures.
c.Put("ParallelBuild.failN", fails)
return &wg, nil
}
开发者ID:naveenholla,项目名称:deis,代码行数:43,代码来源:docker.go
示例11: ParallelBuild
// ParallelBuild runs multiple docker builds at the same time.
//
// Params:
// -images ([]BuildImg): Images to build
// -alwaysFetch (bool): Default false. If set to true, this will always fetch
// the Docker image even if it already exists in the registry.
//
// Returns:
//
// - Waiter: A *sync.WaitGroup that is waiting for the docker downloads to finish.
//
// Context:
//
// This puts 'ParallelBuild.failN" (int) into the context to indicate how many failures
// occurred during fetches.
func ParallelBuild(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
images := p.Get("images", []BuildImg{}).([]BuildImg)
var wg sync.WaitGroup
var m sync.Mutex
var fails int
for _, img := range images {
img := img
// HACK: ensure "docker build" is serialized by allowing only one entry in
// the WaitGroup. This works around the "simultaneous docker pull" bug.
wg.Wait()
wg.Add(1)
safely.GoDo(c, func() {
log.Infof(c, "Starting build for %s (tag: %s)", img.Path, img.Tag)
if _, err := buildImg(c, img.Path, img.Tag); err != nil {
log.Errf(c, "Failed to build docker image: %s", err)
m.Lock()
fails++
m.Unlock()
}
wg.Done()
})
}
// Number of failures.
c.Put("ParallelBuild.failN", fails)
return &wg, nil
}
开发者ID:smt116,项目名称:deis,代码行数:47,代码来源:docker.go
示例12: Receive
// Receive receives a Git repo.
// This will only work for git-receive-pack.
//
// Params:
// - operation (string): e.g. git-receive-pack
// - repoName (string): The repository name, in the form '/REPO.git'.
// - channel (ssh.Channel): The channel.
// - request (*ssh.Request): The channel.
// - gitHome (string): Defaults to /home/git.
// - fingerprint (string): The fingerprint of the user's SSH key.
// - user (string): The name of the Deis user.
//
// Returns:
// - nothing
func Receive(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
if ok, z := p.Requires("channel", "request", "fingerprint", "permissions"); !ok {
return nil, fmt.Errorf("Missing requirements %q", z)
}
repoName := p.Get("repoName", "").(string)
operation := p.Get("operation", "").(string)
channel := p.Get("channel", nil).(ssh.Channel)
gitHome := p.Get("gitHome", "/home/git").(string)
fingerprint := p.Get("fingerprint", nil).(string)
user := p.Get("user", "").(string)
repo, err := cleanRepoName(repoName)
if err != nil {
log.Warnf(c, "Illegal repo name: %s.", err)
channel.Stderr().Write([]byte("No repo given"))
return nil, err
}
repo += ".git"
if _, err := createRepo(c, filepath.Join(gitHome, repo), gitHome); err != nil {
log.Infof(c, "Did not create new repo: %s", err)
}
cmd := exec.Command("git-shell", "-c", fmt.Sprintf("%s '%s'", operation, repo))
log.Infof(c, strings.Join(cmd.Args, " "))
var errbuff bytes.Buffer
cmd.Dir = gitHome
cmd.Env = []string{
fmt.Sprintf("RECEIVE_USER=%s", user),
fmt.Sprintf("RECEIVE_REPO=%s", repo),
fmt.Sprintf("RECEIVE_FINGERPRINT=%s", fingerprint),
fmt.Sprintf("SSH_ORIGINAL_COMMAND=%s '%s'", operation, repo),
fmt.Sprintf("SSH_CONNECTION=%s", c.Get("SSH_CONNECTION", "0 0 0 0").(string)),
}
cmd.Env = append(cmd.Env, os.Environ()...)
done := plumbCommand(cmd, channel, &errbuff)
if err := cmd.Start(); err != nil {
log.Warnf(c, "Failed git receive immediately: %s %s", err, errbuff.Bytes())
return nil, err
}
fmt.Printf("Waiting for git-receive to run.\n")
done.Wait()
fmt.Printf("Waiting for deploy.\n")
if err := cmd.Wait(); err != nil {
log.Errf(c, "Error on command: %s %s", err, errbuff.Bytes())
return nil, err
}
if errbuff.Len() > 0 {
log.Warnf(c, "Unreported error: %s", errbuff.Bytes())
}
log.Infof(c, "Deploy complete.\n")
return nil, nil
}
开发者ID:helgi,项目名称:builder,代码行数:71,代码来源:git.go
示例13: genSSHKeys
// genSshKeys generates the default set of SSH host keys.
func genSSHKeys(c cookoo.Context) error {
// Generate a new key
out, err := exec.Command("ssh-keygen", "-A").CombinedOutput()
if err != nil {
log.Infof(c, "ssh-keygen: %s", out)
log.Errf(c, "Failed to generate SSH keys: %s", err)
return err
}
return nil
}
开发者ID:naveenholla,项目名称:deis,代码行数:11,代码来源:etcd.go
示例14: Ping
// Ping handles a simple test SSH exec.
//
// Returns the string PONG and exit status 0.
//
// Params:
// - channel (ssh.Channel): The channel to respond on.
// - request (*ssh.Request): The request.
//
func Ping(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
channel := p.Get("channel", nil).(ssh.Channel)
req := p.Get("request", nil).(*ssh.Request)
log.Info(c, "PING\n")
if _, err := channel.Write([]byte("pong")); err != nil {
log.Errf(c, "Failed to write to channel: %s", err)
}
sendExitStatus(0, channel)
req.Reply(true, nil)
return nil, nil
}
开发者ID:yun-an,项目名称:deis,代码行数:19,代码来源:server.go
示例15: UpdateHostPort
// UpdateHostPort intermittently notifies etcd of the builder's address.
//
// If `port` is specified, this will notify etcd at 10 second intervals that
// the builder is listening at $HOST:$PORT, setting the TTL to 20 seconds.
//
// This will notify etcd as long as the local sshd is running.
//
// Params:
// - base (string): The base path to write the data: $base/host and $base/port.
// - host (string): The hostname
// - port (string): The port
// - client (Setter): The client to use to write the data to etcd.
// - sshPid (int): The PID for SSHD. If SSHD dies, this stops notifying.
func UpdateHostPort(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
base := p.Get("base", "").(string)
host := p.Get("host", "").(string)
port := p.Get("port", "").(string)
client := p.Get("client", nil).(Setter)
sshd := p.Get("sshdPid", 0).(int)
// If no port is specified, we don't do anything.
if len(port) == 0 {
log.Infof(c, "No external port provided. Not publishing details.")
return false, nil
}
var ttl uint64 = 20
if err := setHostPort(client, base, host, port, ttl); err != nil {
log.Errf(c, "Etcd error setting host/port: %s", err)
return false, err
}
// Update etcd every ten seconds with this builder's host/port.
safely.GoDo(c, func() {
ticker := time.NewTicker(10 * time.Second)
for range ticker.C {
//log.Infof(c, "Setting SSHD host/port")
if _, err := os.FindProcess(sshd); err != nil {
log.Errf(c, "Lost SSHd process: %s", err)
break
} else {
if err := setHostPort(client, base, host, port, ttl); err != nil {
log.Errf(c, "Etcd error setting host/port: %s", err)
break
}
}
}
ticker.Stop()
})
return true, nil
}
开发者ID:ngpestelos,项目名称:deis,代码行数:54,代码来源:etcd.go
示例16: iam
// iam injects info into the environment about a host's self.
//
// Sets the following environment variables. (Values represent the data format.
// Instances will get its own values.)
//
// MY_NODEIP=10.245.1.3
// MY_SERVICE_IP=10.22.1.4
// MY_PORT_PEER=2380
// MY_PORT_CLIENT=2379
// MY_NAMESPACE=default
// MY_SELFLINK=/api/v1/namespaces/default/pods/deis-etcd-1-336jp
// MY_UID=62a3b54a-6956-11e5-b8ab-0800279dd272
// MY_APISERVER=https://10.247.0.1:443
// MY_NAME=deis-etcd-1-336jp
// MY_IP=10.246.44.7
// MY_LABEL_NAME=deis-etcd-1 # One entry per label in the JSON
// MY_ANNOTATION_NAME=deis-etcd-1 # One entry per annitation in the JSON
// MY_PORT_CLIENT=4100
// MY_PORT_PEER=2380
func iam(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
me, err := aboutme.FromEnv()
if err != nil {
log.Errf(c, "Failed aboutme.FromEnv: %s", err)
log.Warn(c, "Attempting to recover.")
}
// This will try to recover whenever IP is not set. Only some fields
// can be recovered. But all we really need is IP and Name.
if strings.TrimSpace(me.IP) == "" {
log.Warn(c, "No IP found by API query.")
ip, err := aboutme.MyIP()
if err != nil || ip == "" {
// Force pod death.
log.Errf(c, "Failed to get an IP address: %s", err)
os.Exit(5)
}
me.IP = ip
}
if strings.TrimSpace(me.Name) == "" {
// Try to set name from DAPI.
me.Name = os.Getenv("POD_NAME")
log.Warnf(c, "Setting name to %q", me.Name)
}
if strings.TrimSpace(me.Namespace) == "" {
// Try to set namespace from DAPI.
me.Namespace = os.Getenv("POD_NAMESPACE")
log.Warnf(c, "Setting name to %q", me.Namespace)
}
me.ShuntEnv()
os.Setenv("ETCD_NAME", me.Name)
c.Put("ETCD_NAME", me.Name)
passEnv("MY_PORT_CLIENT", "$DEIS_ETCD_1_SERVICE_PORT_CLIENT")
passEnv("MY_PORT_PEER", "$DEIS_ETCD_1_SERVICE_PORT_PEER")
return nil, nil
}
开发者ID:smothiki,项目名称:etcd,代码行数:57,代码来源:boot.go
示例17: IsRunning
// IsRunning checks to see if etcd is running.
//
// It will test `count` times before giving up.
//
// Params:
// - client (EtcdGetter)
// - count (int): Number of times to try before giving up.
//
// Returns:
// boolean true if etcd is listening.
func IsRunning(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
client := p.Get("client", nil).(Getter)
count := p.Get("count", 20).(int)
for i := 0; i < count; i++ {
_, err := client.Get("/", false, false)
if err == nil {
return true, nil
}
log.Infof(c, "Waiting for etcd to come online.")
time.Sleep(250 * time.Millisecond)
}
log.Errf(c, "Etcd is not answering after %d attempts.", count)
return false, &cookoo.FatalError{"Could not connect to Etcd."}
}
开发者ID:naveenholla,项目名称:deis,代码行数:24,代码来源:etcd.go
示例18: keysToEtcd
// keysToEtcd copies local keys into etcd.
//
// It only fails if it cannot copy ssh_host_key to sshHostKey. All other
// abnormal conditions are logged, but not considered to be failures.
func keysToEtcd(c cookoo.Context, client Setter, ciphers []string, etcdPath string) error {
lpath := "/etc/ssh/ssh_host_%s_key"
privkey := "%s/sshHost%sKey"
for _, cipher := range ciphers {
path := fmt.Sprintf(lpath, cipher)
key := fmt.Sprintf(privkey, etcdPath, cipher)
content, err := ioutil.ReadFile(path)
if err != nil {
log.Infof(c, "No key named %s", path)
} else if _, err := client.Set(key, string(content), 0); err != nil {
log.Errf(c, "Could not store ssh key in etcd: %s", err)
}
}
// Now we set the generic key:
if content, err := ioutil.ReadFile("/etc/ssh/ssh_host_key"); err != nil {
log.Errf(c, "Could not read the ssh_host_key file.")
return err
} else if _, err := client.Set("sshHostKey", string(content), 0); err != nil {
log.Errf(c, "Failed to set sshHostKey in etcd.")
return err
}
return nil
}
开发者ID:naveenholla,项目名称:deis,代码行数:27,代码来源:etcd.go
示例19: iam
// iam injects info into the environment about a host's self.
//
// Sets the following environment variables. (Values represent the data format.
// Instances will get its own values.)
//
// MY_NODEIP=10.245.1.3
// MY_SERVICE_IP=10.22.1.4
// MY_PORT_PEER=2380
// MY_PORT_CLIENT=2379
// MY_NAMESPACE=default
// MY_SELFLINK=/api/v1/namespaces/default/pods/deis-etcd-1-336jp
// MY_UID=62a3b54a-6956-11e5-b8ab-0800279dd272
// MY_APISERVER=https://10.247.0.1:443
// MY_NAME=deis-etcd-1-336jp
// MY_IP=10.246.44.7
// MY_LABEL_NAME=deis-etcd-1 # One entry per label in the JSON
// MY_ANNOTATION_NAME=deis-etcd-1 # One entry per annitation in the JSON
// MY_PORT_CLIENT=4100
// MY_PORT_PEER=2380
func iam(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
me, err := aboutme.FromEnv()
if err != nil {
log.Errf(c, "Failed aboutme.FromEnv: %s", err)
} else {
me.ShuntEnv()
os.Setenv("ETCD_NAME", me.Name)
c.Put("ETCD_NAME", me.Name)
}
passEnv("MY_PORT_CLIENT", "$DEIS_ETCD_1_SERVICE_PORT_CLIENT")
passEnv("MY_PORT_PEER", "$DEIS_ETCD_1_SERVICE_PORT_PEER")
return nil, nil
}
开发者ID:arschles,项目名称:deis-etcd,代码行数:33,代码来源:boot.go
示例20: startEtcd
// startEtcd starts a cluster member of a static etcd cluster.
//
// Params:
// - discover (string): Value to pass to etcd --discovery.
// - client (client.Client): A client to the discovery server. This will
// periodically write data there to indicate liveness.
func startEtcd(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
cli := p.Get("client", nil).(client.Client)
// Use config from environment.
cmd := exec.Command("etcd")
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
println(strings.Join(os.Environ(), "\n"))
if err := cmd.Start(); err != nil {
log.Errf(c, "Failed to start etcd: %s", err)
return nil, err
}
// We need a way to tell starting members that there is an existing cluster,
// and that that cluster has met the initial consensus requirements. This
// basically stores a status record that indicates that it is an existing
// and running etcd server. It allows for basically a two hour window
// during which a cluster can be in an uncertain state before the entire
// thing gives up and a new cluster is created.
ticker := time.NewTicker(time.Minute)
expires := time.Hour * 2
go func() {
name := c.Get("ETCD_NAME", "").(string)
tok := c.Get("DEIS_ETCD_DISCOVERY_TOKEN", "").(string)
key := fmt.Sprintf(discovery.ClusterStatusKey, tok, name)
for t := range ticker.C {
etcd.SimpleSet(cli, key, t.String(), expires)
}
}()
if err := cmd.Wait(); err != nil {
ticker.Stop()
log.Errf(c, "Etcd quit unexpectedly: %s", err)
}
return nil, nil
}
开发者ID:bacongobbler,项目名称:etcd,代码行数:42,代码来源:boot.go
注:本文中的github.com/Masterminds/cookoo/log.Errf函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论