Skip to content

Instantly share code, notes, and snippets.

@mchome
Last active September 3, 2019 08:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mchome/f73e91322991800ba30c7e49728677af to your computer and use it in GitHub Desktop.
Save mchome/f73e91322991800ba30c7e49728677af to your computer and use it in GitHub Desktop.
kill dogcom
package main
import (
"net/http"
"os/exec"
)
func indexHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("It works!"))
}
func killDogcomHandler(w http.ResponseWriter, r *http.Request) {
_, err := exec.Command("sh", "-c", "/etc/init.d/dogcom", "stop").Output()
if (err != nil) {
_, err := exec.Command("sh", "-c", "killall", "dogcom").Output()
if (err != nil) {
w.Write([]byte("Failed!"))
return
}
}
w.Write([]byte("Succeeded!"))
}
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", indexHandler)
mux.HandleFunc("/killdogcom", killDogcomHandler)
http.ListenAndServe("0.0.0.0:12121", mux)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment