func execShell(job *worker.Job) (result []byte, err error) { log.Messagef("[Shell]Received: Handle=%s", job.Handle) defer log.Messagef("[Shell]Finished: Handle=%s", job.Handle) log.Debugf("[Shell]Received: Handle=%s, UID=%s, Data=%v", job.Handle, job.UniqueId, job.Data) var sh *ShExec if sh, err = NewShExec(*basedir, job); err != nil { return } sh.Logger = log.DefaultLogger return sh.Exec() }
func execPHP(job *worker.Job) (result []byte, err error) { log.Messagef("[PHP]Received: Handle=%s", job.Handle) defer log.Messagef("[PHP]Finished: Handle=%s", job.Handle) log.Debugf("[PHP]Received: Handle=%s, UID=%s, Data=%v", job.Handle, job.UniqueId, job.Data) var sh *ShExec if sh, err = NewShExec(*basedir, job); err != nil { return } sh.Prepend("-f", sh.Name+".php") sh.Name = "php" sh.Logger = log.DefaultLogger return sh.Exec() }
func main() { // prepare the configuration config, err := InitConfig() if err != nil { log.Error(err) return } // make PID file if config.Pid != "" { p, err := pid.New(config.Pid) if err != nil { log.Error(err) return } defer p.Close() } log.Message("Starting...") if config.Ca != "" || config.Cert != "" || config.Key != "" { log.Messagef("Setting TLS (CA=%s; Cert=%s; Key=%s)...", config.Ca, config.Cert, config.Key) } g, err := gleam.New(config.Etcd, config.Script, config.Cert, config.Key, config.Ca) if err != nil { log.Error(err) return } defer g.Close() g.ErrHandler = func(err error) { log.Error(err) } log.Messagef("Watching(Name = %s)...", config.Name) g.WatchNode(config.Name) for _, r := range config.Region { log.Messagef("Watching(Region = %s)...", r) g.WatchRegion(r) } go g.Serve() // signal handler sh := signal.NewHandler() sh.Bind(os.Interrupt, func() bool { return true }) go func() { g.Wait() if err := signal.Send(os.Getpid(), os.Interrupt); err != nil { panic(err) } }() sh.Loop() log.Message("Exit!") }
func echo(w http.ResponseWriter, r *http.Request) { wechat.Handle(w, r, func(r *wechat.Request) (resp *wechat.Response, err error) { log.Messagef("ACCESS: %V", r) resp = wechat.NewResponse() resp.ToUserName = r.FromUserName resp.FromUserName = r.ToUserName resp.MsgType = wechat.Text resp.Content = r.Content return }) }
func writeAndLog(w http.ResponseWriter, r *http.Request, status int, data []byte) { log.Messagef("%s %s %q %d %q", r.RemoteAddr, r.Method, r.URL.String(), status, data) if w != nil { w.WriteHeader(status) if data != nil { if _, err := w.Write(data); err != nil { log.Errorf("%s %s %q %d %q", r.RemoteAddr, r.Method, r.URL.String(), status, err) } } } }
func main() { defer func() { log.Message("Exit.") time.Sleep(time.Microsecond * 100) }() log.Message("Starting...") http.HandleFunc("/wechat", echo) go func() { log.Messagef("Bind to [%s]", *addr) if err := http.ListenAndServe(*addr, nil); err != nil { log.Error(err) signal.Send(os.Getpid(), os.Interrupt) } }() // signal handler sh := signal.NewHandler() sh.Bind(os.Interrupt, func() bool { return true }) sh.Loop() }
func main() { conn, err := doozer.DialUri(*uri, *buri) if err != nil { log.Error(err) return } defer conn.Close() rev, err := conn.Rev() if err != nil { log.Error(err) return } if (*region)[0] != '/' { *region = "/" + *region } var path string if *pid == 0 { path = fmt.Sprintf("%s/wire", *region) } else { path = fmt.Sprintf("%s/node/%d", *region, *pid) } params := make([]interface{}, flag.NArg()) for i := 0; i < flag.NArg(); i++ { params[i] = interface{}(flag.Arg(i)) } f := &node.ZFunc{Name: *fn, Params: params} body, err := json.Marshal(f) if err != nil { log.Error(err) return } rev, err = conn.Set(path, rev, body) if err != nil { log.Error(err) return } log.Messagef("Rev: %d", rev) time.Sleep(time.Second) }