Пример #1
0
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()
}
Пример #2
0
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()
}
Пример #3
0
func main() {
	log.Message("Starting ... ")
	defer func() {
		time.Sleep(time.Second)
		log.Message("Shutdown complate!")
	}()

	// init profiling file
	if *proffile != "" {
		log.Debugf("Open a profiling file: %s", *proffile)
		if err := prof.Start(*proffile); err != nil {
			log.Error(err)
		} else {
			defer prof.Stop()
		}
	}

	// init heap dumping file
	if *dumpfile != "" {
		log.Debugf("Open a heap dumping file: %s", *dumpfile)
		if err := prof.NewDump(*dumpfile); err != nil {
			log.Error(err)
		} else {
			defer prof.CloseDump()
			go func() {
				for prof.Dumping {
					time.Sleep(time.Duration(*dumptime) * time.Second)
					prof.Dump()
				}
			}()
		}
	}

	// init pid file
	log.Debugf("Open a pid file: %s", *pidfile)
	if pidFile, err := pid.New(*pidfile); err != nil {
		log.Error(err)
	} else {
		defer pidFile.Close()
	}

	w := worker.New(*joblimit)
	if err := w.AddServer(*gearmand); err != nil {
		log.Error(err)
		return
	}
	if err := w.AddFunc("exec", execShell, uint32(*timeout)); err != nil {
		log.Error(err)
		return
	}
	if err := w.AddFunc("execphp", execPHP, uint32(*timeout)); err != nil {
		log.Error(err)
		return
	}
	defer w.Close()
	go w.Work()

	// signal handler
	sh := signal.NewHandler()
	sh.Bind(os.Interrupt, func() bool { return true })
	sh.Loop()
}
Пример #4
0
func (t *_task) Exec() error {
	log.Debugf("Task %d Executed.", t.Id())
	return nil
}