New command line option -getStatus to view formatted download status; config now requires RPC socket path; queue.Close() now runs after interrupt is sent
This commit is contained in:
parent
7b8d4ed528
commit
e958dcb451
4 changed files with 222 additions and 6 deletions
cmd/hoarder
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/tblyler/hoarder/queue"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/rpc"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strconv"
|
||||
|
@ -19,6 +20,7 @@ var buildDate = "Unknown"
|
|||
func main() {
|
||||
version := flag.Bool("version", false, "display version info")
|
||||
configPath := flag.String("config", "", "path to the config file")
|
||||
getStatus := flag.Bool("getStatus", false, "get the status of the current downloads")
|
||||
flag.Parse()
|
||||
|
||||
if *version {
|
||||
|
@ -54,6 +56,29 @@ func main() {
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
if *getStatus {
|
||||
rpc, err := rpc.Dial("unix", config.RPCSocketPath)
|
||||
if err != nil {
|
||||
logger.Printf("Unable to open RPC socket file '%s': '%s'", config.RPCSocketPath, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer rpc.Close()
|
||||
|
||||
reply := ""
|
||||
err = rpc.Call("Status.Downloads", &queue.RPCArgs{}, &reply)
|
||||
if err != nil {
|
||||
logger.Printf("RPC call for download status failed: '%s'", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if len(reply) > 0 {
|
||||
fmt.Println(reply)
|
||||
} else {
|
||||
fmt.Println("No Downloads")
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
q, err := queue.NewQueue(config, logger)
|
||||
if err != nil {
|
||||
logger.Printf("Failed to start hoarder: '%s'", err)
|
||||
|
@ -74,4 +99,9 @@ func main() {
|
|||
logger.Println("Got signal ", sig, " quitting")
|
||||
stop <- true
|
||||
<-done
|
||||
|
||||
errs := q.Close()
|
||||
for _, err := range errs {
|
||||
logger.Println(err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue