store is sort of working
git-svn-id: https://weed-fs.googlecode.com/svn/trunk@3 282b0af5-e82d-9cf1-ede4-77906d7719d0
This commit is contained in:
47
weed-fs/src/cmd/agent.go
Normal file
47
weed-fs/src/cmd/agent.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"http"
|
||||
// "runtime"
|
||||
"log"
|
||||
"os"
|
||||
"exec"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func HelloServer(w http.ResponseWriter, req *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
w.Write([]byte("hello, world!\n"))
|
||||
}
|
||||
func ShellHandler(w http.ResponseWriter, r *http.Request) {
|
||||
name := r.FormValue("cmd")
|
||||
args := r.Form["arg"]
|
||||
dir := r.FormValue("dir")
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
|
||||
cmd := run(w, dir, name, args)
|
||||
cmd.Wait()
|
||||
}
|
||||
|
||||
func run(w http.ResponseWriter, dir string, name string, args []string) *exec.Cmd {
|
||||
cmd := exec.Command(name, args...)
|
||||
cmd.Dir = dir
|
||||
cmd.Env = os.Environ()
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stdout = w
|
||||
cmd.Stderr = w
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
fmt.Fprint(w, "could not execute", args, ":", cmd.Args, "\n", err,"\n")
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
func main() {
|
||||
// runtime.GOMAXPROCS(1)
|
||||
http.HandleFunc("/", HelloServer)
|
||||
http.HandleFunc("/shell", ShellHandler)
|
||||
|
||||
log.Println("Serving at http://127.0.0.1:8080/")
|
||||
http.ListenAndServe(":8080", nil)
|
||||
}
|
||||
Reference in New Issue
Block a user