本文整理汇总了Golang中github.com/zenoss/glog.Fatalf函数的典型用法代码示例。如果您正苦于以下问题:Golang Fatalf函数的具体用法?Golang Fatalf怎么用?Golang Fatalf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Fatalf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Init
func Init() {
var volumesDir string
if user, err := user.Current(); err == nil {
volumesDir = fmt.Sprintf("/tmp/serviced-%s/var/isvcs", user.Username)
} else {
volumesDir = "/tmp/serviced/var/isvcs"
}
Mgr = NewManager("unix:///var/run/docker.sock", imagesDir(), volumesDir)
if err := Mgr.Register(elasticsearch); err != nil {
glog.Fatalf("%s", err)
}
if err := Mgr.Register(zookeeper); err != nil {
glog.Fatalf("%s", err)
}
if err := Mgr.Register(logstash); err != nil {
glog.Fatalf("%s", err)
}
if err := Mgr.Register(opentsdb); err != nil {
glog.Fatalf("%s", err)
}
if err := Mgr.Register(celery); err != nil {
glog.Fatalf("%s", err)
}
}
示例2: startRPC
func (d *daemon) startRPC() {
if options.DebugPort > 0 {
go func() {
if err := http.ListenAndServe(fmt.Sprintf(":%d", options.DebugPort), nil); err != nil {
glog.Errorf("Unable to bind to debug port %s. Is another instance running?", err)
return
}
}()
}
listener, err := net.Listen("tcp", options.Listen)
if err != nil {
glog.Fatalf("Unable to bind to port %s. Is another instance running?")
}
rpcutils.SetDialTimeout(options.RPCDialTimeout)
d.rpcServer.HandleHTTP(rpc.DefaultRPCPath, rpc.DefaultDebugPath)
glog.V(0).Infof("Listening on %s", listener.Addr().String())
go func() {
for {
conn, err := listener.Accept()
if err != nil {
glog.Fatalf("Error accepting connections: %s", err)
}
go d.rpcServer.ServeCodec(jsonrpc.NewServerCodec(conn))
}
}()
}
示例3: editService
func editService(service *dao.Service, editor string) error {
serviceJson, err := json.MarshalIndent(service, " ", " ")
if err != nil {
glog.Fatalf("Problem marshaling service object: %s", err)
}
var reader io.Reader
if terminal.IsTerminal(syscall.Stdin) {
editorPath, err := findEditor(editor)
if err != nil {
fmt.Printf("%s\n", err)
return err
}
f, err := ioutil.TempFile("", fmt.Sprintf("serviced_edit_%s_", service.Id))
if err != nil {
glog.Fatalf("Could not write tempfile: %s", err)
}
defer f.Close()
defer os.Remove(f.Name())
_, err = f.Write(serviceJson)
if err != nil {
glog.Fatalf("Problem writing service json to file: %s", err)
}
editorCmd := exec.Command(editorPath, f.Name())
editorCmd.Stdout = os.Stdout
editorCmd.Stdin = os.Stdin
editorCmd.Stderr = os.Stderr
err = editorCmd.Run()
if err != nil {
glog.Fatal("Editor command returned error: %s", err)
}
_, err = f.Seek(0, 0)
if err != nil {
glog.Fatal("Could not seek to begining of tempfile: %s", err)
}
reader = f
} else {
_, err = os.Stdout.Write(serviceJson)
if err != nil {
glog.Fatal("Could not write service to terminal's stdout: %s", err)
}
reader = os.Stdin
}
serviceJson, err = ioutil.ReadAll(reader)
if err != nil {
glog.Fatal("Could not read tempfile back in: %s", err)
}
err = json.Unmarshal(serviceJson, &service)
if err != nil {
glog.Fatal("Could not parse json: %s", err)
}
return nil
}
示例4: startISVCS
func (d *daemon) startISVCS() {
isvcs.Init()
isvcs.Mgr.SetVolumesDir(path.Join(options.VarPath, "isvcs"))
if err := isvcs.Mgr.SetConfigurationOption("elasticsearch-serviced", "cluster", d.getEsClusterName("elasticsearch-serviced")); err != nil {
glog.Fatalf("Could not set es-serviced option: %s", err)
}
if err := isvcs.Mgr.SetConfigurationOption("elasticsearch-logstash", "cluster", d.getEsClusterName("elasticsearch-logstash")); err != nil {
glog.Fatalf("Could not set es-logstash option: %s", err)
}
if err := d.initISVCS(); err != nil {
glog.Fatalf("Could not start isvcs: %s", err)
}
}
示例5: SetUpSuite
//SetUpSuite is run before the tests to ensure elastic, zookeeper etc. are running.
func (dt *DaoTest) SetUpSuite(c *C) {
docker.SetUseRegistry(true)
dt.Port = 9202
isvcs.Init()
isvcs.Mgr.SetVolumesDir("/tmp/serviced-test")
esServicedClusterName, _ := utils.NewUUID36()
if err := isvcs.Mgr.SetConfigurationOption("elasticsearch-serviced", "cluster", esServicedClusterName); err != nil {
c.Fatalf("Could not set elasticsearch-serviced clustername: %s", err)
}
esLogstashClusterName, _ := utils.NewUUID36()
if err := isvcs.Mgr.SetConfigurationOption("elasticsearch-logstash", "cluster", esLogstashClusterName); err != nil {
c.Fatalf("Could not set elasticsearch-logstash clustername: %s", err)
}
isvcs.Mgr.Wipe()
if err := isvcs.Mgr.Start(); err != nil {
c.Fatalf("Could not start es container: %s", err)
}
dt.MappingsFile = "controlplane.json"
dt.FacadeTest.SetUpSuite(c)
dsn := coordzk.NewDSN([]string{"127.0.0.1:2181"}, time.Second*15).String()
glog.Infof("zookeeper dsn: %s", dsn)
zClient, err := coordclient.New("zookeeper", dsn, "", nil)
if err != nil {
glog.Fatalf("Could not start es container: %s", err)
}
zzk.InitializeLocalClient(zClient)
dt.zkConn, err = zzk.GetLocalConnection("/")
if err != nil {
c.Fatalf("could not get zk connection %v", err)
}
dt.Dao, err = NewControlSvc("localhost", int(dt.Port), dt.Facade, "/tmp", "rsync", 4979, time.Minute*5, "localhost:5000", MockStorageDriver{})
if err != nil {
glog.Fatalf("Could not start es container: %s", err)
} else {
for i := 0; i < 10; i += 1 {
id := strconv.Itoa(i)
dt.Dao.RemoveService(id, &unused)
}
for i := 100; i < 110; i += 1 {
id := strconv.Itoa(i)
dt.Dao.RemoveService(id, &unused)
}
}
}
示例6: resourcesDir
func resourcesDir() string {
path, err := filepath.EvalSymlinks(localDir("resources"))
if err != nil {
glog.Fatalf("Could not evaluate %s, not following symlinks: %s", localDir("resources"), err)
}
return path
}
示例7: GetLocalConnection
// GetLocalConnection acquires a connection from the local zookeeper client
func GetLocalConnection(path string) (client.Connection, error) {
localclient, ok := manager[local]
if !ok || localclient.Client == nil {
glog.Fatalf("zClient has not been initialized!")
}
return localclient.GetConnection(path)
}
示例8: init
func init() {
var err error
dockerPortBinding := portBinding{
HostIp: "0.0.0.0",
HostIpOverride: "", // docker registry should always be open
HostPort: registryPort,
}
defaultHealthCheck := healthCheckDefinition{
healthCheck: registryHealthCheck,
Interval: DEFAULT_HEALTHCHECK_INTERVAL,
Timeout: DEFAULT_HEALTHCHECK_TIMEOUT,
}
healthChecks := map[string]healthCheckDefinition{
DEFAULT_HEALTHCHECK_NAME: defaultHealthCheck,
}
command := `DOCKER_REGISTRY_CONFIG=/docker-registry/config/config_sample.yml SETTINGS_FLAVOR=serviced exec docker-registry`
dockerRegistry, err = NewIService(
IServiceDefinition{
Name: "docker-registry",
Repo: IMAGE_REPO,
Tag: IMAGE_TAG,
Command: func() string { return command },
PortBindings: []portBinding{dockerPortBinding},
Volumes: map[string]string{"registry": "/tmp/registry"},
HealthChecks: healthChecks,
},
)
if err != nil {
glog.Fatalf("Error initializing docker-registry container: %s", err)
}
}
示例9: cmdRegistrySync
// serviced docker sync
func (c *ServicedCli) cmdRegistrySync(ctx *cli.Context) {
err := c.driver.RegistrySync()
if err != nil {
glog.Fatalf("error syncing docker images to local registry: %s", err)
}
}
示例10: elasticsearchHealthCheck
// elasticsearchHealthCheck() determines if elasticsearch is healthy
func elasticsearchHealthCheck() error {
start := time.Now()
lastError := time.Now()
minUptime := time.Second * 2
timeout := time.Second * 30
schemaFile := localDir("resources/controlplane.json")
for {
if healthResponse, err := cluster.Health(true); err == nil && (healthResponse.Status == "green" || healthResponse.Status == "yellow") {
if buffer, err := os.Open(schemaFile); err != nil {
glog.Fatalf("problem reading %s", err)
return err
} else {
http.Post("http://localhost:9200/controlplane", "application/json", buffer)
buffer.Close()
}
} else {
lastError = time.Now()
glog.V(2).Infof("Still trying to connect to elastic: %v: %s", err, healthResponse)
}
if time.Since(lastError) > minUptime {
break
}
if time.Since(start) > timeout {
return fmt.Errorf("Could not startup elastic search container.")
}
time.Sleep(time.Millisecond * 1000)
}
glog.Info("elasticsearch container started, browser at http://localhost:9200/_plugin/head/")
return nil
}
示例11: cmdSquash
func (c *ServicedCli) cmdSquash(ctx *cli.Context) {
imageName := ""
baseLayer := ""
newName := ""
args := ctx.Args()
switch len(ctx.Args()) {
case 3:
newName = args[2]
fallthrough
case 2:
baseLayer = args[1]
fallthrough
case 1:
imageName = args[0]
break
default:
cli.ShowCommandHelp(ctx, "squash")
return
}
imageID, err := c.driver.Squash(imageName, baseLayer, newName, ctx.String("tempdir"))
if err != nil {
glog.Fatalf("error squashing: %s", err)
}
fmt.Println(imageID)
}
示例12: CmdEditService
func (cli *ServicedCli) CmdEditService(args ...string) error {
cmd := Subcmd("edit-service", "[SERVICE_ID]", "edit a service")
var editor string
cmd.StringVar(&editor, "editor", os.Getenv("EDITOR"), "editor to use to edit service definition, also controlled by $EDITOR var")
if err := cmd.Parse(args); err != nil {
cmd.Usage()
return nil
}
if len(cmd.Args()) != 1 {
cmd.Usage()
return nil
}
client := getClient()
var service dao.Service
err := client.GetService(cmd.Arg(0), &service)
if err != nil {
glog.Fatalf("Could not get service %s: %v", cmd.Arg(0), err)
}
err = editService(&service, editor)
var unused int
err = client.UpdateService(service, &unused)
return err
}
示例13: reloadLogstashContainerImpl
// Anytime the available service definitions are modified
// we need to restart the logstash container so it can write out
// its new filter set.
// This method depends on the elasticsearch container being up and running.
func reloadLogstashContainerImpl(ctx datastore.Context, f *Facade) error {
templates, err := f.GetServiceTemplates(ctx)
if err != nil {
glog.Fatalf("Could not write logstash configuration: %s", err)
}
if err := writeLogstashConfiguration(templates); err != nil {
glog.Fatalf("Could not write logstash configuration: %s", err)
return err
}
glog.V(2).Info("Starting logstash container")
if err := isvcs.Mgr.Notify("restart logstash"); err != nil {
glog.Fatalf("Could not start logstash container: %s", err)
return err
}
return nil
}
示例14: CmdServices
// Print the list of available services.
func (cli *ServicedCli) CmdServices(args ...string) error {
cmd := Subcmd("services", "[CMD]", "Show services")
var verbose bool
cmd.BoolVar(&verbose, "verbose", false, "Show JSON representation for each service")
var raw bool
cmd.BoolVar(&raw, "raw", false, "Don't show the header line")
var ascii bool
if os.Getenv("SERVICED_ASCII") == "1" {
ascii = true
}
cmd.BoolVar(&ascii, "ascii", ascii, "use ascii characters for service tree (env SERVICED_ASCII=1 will default to ascii)")
if err := cmd.Parse(args); err != nil {
return nil
}
if ascii {
tree_charset = tree_ascii
}
controlPlane := getClient()
var services []*dao.Service
err := controlPlane.GetServices(&empty, &services)
if err != nil {
glog.Fatalf("Could not get services: %v", err)
}
if verbose == false {
svcMap := &svcStub{}
svcMap.value = &dao.Service{}
generateSvcMap("", services, svcMap)
svcMap.treePrint(raw)
} else {
servicesJson, err := json.MarshalIndent(services, " ", " ")
if err != nil {
glog.Fatalf("Problem marshaling services object: %s", err)
}
fmt.Printf("%s\n", servicesJson)
}
return err
}
示例15: Exec
func (f *Forwarder) Exec(cfg *ProcessConfig) *ProcessInstance {
// TODO: make me more extensible
urlAddr, err := url.Parse(f.addr)
if err != nil {
glog.Fatalf("Not a valid path: %s (%v)", f.addr, err)
}
host := fmt.Sprintf("http://%s:50000/", strings.Split(urlAddr.Host, ":")[0])
// Dial the remote ProcessServer
client, err := socketio.Dial(host)
if err != nil {
glog.Fatalf("Unable to contact remote process server: %v", err)
}
client.On("connect", func(ns *socketio.NameSpace) {
if ns.Session.Values[PROCESSKEY] == nil {
ns.Emit("process", cfg)
} else {
glog.Fatalf("Trying to connect to a stale process!")
}
})
ns := client.Of("")
proc := &ProcessInstance{
Stdin: make(chan byte, 1024),
Stdout: make(chan byte, 1024),
Stderr: make(chan byte, 1024),
Result: make(chan Result),
}
client.On("disconnect", func(ns *socketio.NameSpace) {
glog.Infof("Disconnected!")
proc.Disconnect()
proc.Close()
})
go proc.ReadResponse(ns)
go proc.WriteRequest(ns)
go client.Run()
return proc
}