|
|
|
@ -1,14 +1,10 @@
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
"log"
|
|
|
|
|
"net/http"
|
|
|
|
|
"os"
|
|
|
|
|
"os/exec"
|
|
|
|
|
"os/signal"
|
|
|
|
|
"strconv"
|
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
@ -129,18 +125,10 @@ func main() {
|
|
|
|
|
Aliases: []string{"s"},
|
|
|
|
|
Usage: "start sisyphus daemon in the background",
|
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
|
// check if daemon already running.
|
|
|
|
|
if _, err := os.Stat(*pidfile); err == nil {
|
|
|
|
|
return cli.NewExitError("sisyphus running or "+*pidfile+" file exists.", 69)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmd := exec.Command(os.Args[0], "run")
|
|
|
|
|
cmd.Start()
|
|
|
|
|
log.Printf("starting sisyphus process ID [%v]\n", cmd.Process.Pid)
|
|
|
|
|
log.Println("sisyphus started")
|
|
|
|
|
err := savePID(*pidfile, cmd.Process.Pid)
|
|
|
|
|
err := daemonStart(*pidfile)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return cli.NewExitError(err, 73)
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
@ -152,43 +140,11 @@ func main() {
|
|
|
|
|
Usage: "stop sisyphus daemon",
|
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
|
|
|
|
|
|
_, err := os.Stat(*pidfile)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return cli.NewExitError("sisyphus is not running", 64)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
processIDRaw, err := ioutil.ReadFile(*pidfile)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return cli.NewExitError("sisyphus is not running", 64)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
processID, err := strconv.Atoi(string(processIDRaw))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return cli.NewExitError("unable to read and parse process id found in "+*pidfile, 74)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
process, err := os.FindProcess(processID)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
e := fmt.Sprintf("Unable to find process ID [%v] with error %v \n", processID, err)
|
|
|
|
|
return cli.NewExitError(e, 71)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// remove PID file
|
|
|
|
|
os.Remove(*pidfile)
|
|
|
|
|
|
|
|
|
|
log.Printf("stopping sisyphus process ID [%v]\n", processID)
|
|
|
|
|
// kill process and exit immediately
|
|
|
|
|
err = process.Kill()
|
|
|
|
|
|
|
|
|
|
err := daemonStop(*pidfile)
|
|
|
|
|
if err != nil {
|
|
|
|
|
e := fmt.Sprintf("Unable to kill process ID [%v] with error %v \n", processID, err)
|
|
|
|
|
return cli.NewExitError(e, 71)
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Println("sisyphus stopped")
|
|
|
|
|
os.Exit(0)
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
@ -197,31 +153,12 @@ func main() {
|
|
|
|
|
Aliases: []string{"r"},
|
|
|
|
|
Usage: "restart sisyphus daemon",
|
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
|
_, err := os.Stat(*pidfile)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return cli.NewExitError("sisyphus is not running", 64)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pid, err := ioutil.ReadFile(*pidfile)
|
|
|
|
|
err := daemonRestart(*pidfile)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return cli.NewExitError("sisyphus is not running", 64)
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmd := exec.Command(os.Args[0], "stop")
|
|
|
|
|
err = cmd.Start()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return cli.NewExitError(err, 64)
|
|
|
|
|
}
|
|
|
|
|
log.Printf("stopping sisyphus process ID [%v]\n", string(pid))
|
|
|
|
|
|
|
|
|
|
cmd = exec.Command(os.Args[0], "start")
|
|
|
|
|
err = cmd.Start()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return cli.NewExitError(err, 64)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Println("sisyphus restarted")
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|