[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [check/master] Add command line flags for pid, port and log paths.
commit 9c13763316a894b48a97ceec6cd4f8a106b814ce
Author: Arlo Breault <arlolra@xxxxxxxxx>
Date: Fri Oct 25 16:32:32 2013 -0700
Add command line flags for pid, port and log paths.
---
check.go | 29 ++++++++++++++++++++---------
1 file changed, 20 insertions(+), 9 deletions(-)
diff --git a/check.go b/check.go
index 3cdc989..76cdd25 100644
--- a/check.go
+++ b/check.go
@@ -1,17 +1,34 @@
package main
import (
+ "flag"
"fmt"
"github.com/samuel/go-gettext/gettext"
"log"
"net/http"
"os"
+ "path"
)
func main() {
+ // command line args
+ logPath := flag.String("log", "", "path to log file; otherwise stdout")
+ pidPath := flag.String("pid", "./", "path to create pid")
+ port := flag.Int("port", 8000, "port to listen on")
+ flag.Parse()
+
+ // log to file
+ if len(*logPath) > 0 {
+ f, err := os.Create(*logPath)
+ if err != nil {
+ log.Fatal(err)
+ }
+ log.SetOutput(f)
+ }
+
// write pid
- pid, err := os.Create("check.pid")
+ pid, err := os.Create(path.Join(*pidPath, "check.pid"))
if err != nil {
log.Fatal(err)
}
@@ -22,12 +39,6 @@ func main() {
log.Fatal(err)
}
- // determine which port to run on
- port := os.Getenv("PORT")
- if len(port) == 0 {
- port = "8000"
- }
-
// load i18n
domain, err := gettext.NewDomain("check", "locale")
if err != nil {
@@ -51,7 +62,7 @@ func main() {
http.HandleFunc("/cgi-bin/TorBulkExitList.py", bulk)
// start the server
- log.Printf("Listening on port: %s\n", port)
- log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil))
+ log.Printf("Listening on port: %d\n", *port)
+ log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), nil))
}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits