Skip to content

Kill and restart the browser #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 29, 2016
Prev Previous commit
Revert "Debug informations"
This reverts commit 797caa8.
  • Loading branch information
matteosuppo committed Jan 29, 2016
commit 58f468d7fe96cb8a2b5bbda16b960b7fae31dc7a
6 changes: 3 additions & 3 deletions killbrowser.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ func killBrowserHandler(c *gin.Context) {
command, err := findBrowser(data.Process)

if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"when": "find", "err": err.Error()})
c.JSON(http.StatusInternalServerError, err.Error())
return
}

if data.Action == "kill" || data.Action == "restart" {
_, err := killBrowser(data.Process)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"when": "kill", "err": err.Error()})
c.JSON(http.StatusInternalServerError, err.Error())
return
}
}

if data.Action == "restart" {
_, err := startBrowser(command, data.URL)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"when": "start", "err": err.Error()})
c.JSON(http.StatusInternalServerError, err.Error())
return
}
}
Expand Down
18 changes: 0 additions & 18 deletions killbrowser_linux.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"log"
"os/exec"
"strings"
)
Expand All @@ -11,33 +10,16 @@ func findBrowser(process string) ([]byte, error) {
grep := exec.Command("grep", process)
head := exec.Command("head", "-n", "1")

log.Println("ps command:")
log.Printf("%+v", ps)

log.Println("grep command:")
log.Printf("%+v", grep)

log.Println("head command:")
log.Printf("%+v", head)

return pipe_commands(ps, grep, head)
}

func killBrowser(process string) ([]byte, error) {
cmd := exec.Command("pkill", "-9", process)

log.Println("kill command:")
log.Printf("%+v", cmd)

return cmd.Output()
}

func startBrowser(command []byte, url string) ([]byte, error) {
parts := strings.Split(string(command), " ")
cmd := exec.Command(parts[0], url)

log.Println("start command:")
log.Printf("%+v", cmd)

return cmd.Output()
}