11package main
22
33import (
4+ "flag"
45 "log"
56 "os"
67 "os/signal"
78 "syscall"
89 "time"
910
1011 "github.com/coreos/go-etcd/etcd"
11-
1212 "github.com/deis/deis/logger/syslogd"
1313)
1414
15- const (
16- timeout time.Duration = 10 * time .Second
17- ttl time.Duration = timeout * 2
15+ var (
16+ publishHost string
17+ publishPath string
18+ publishPort string
19+ publishInterval int
20+ publishTTL int
1821)
1922
20- func main () {
21- host := getopt ("HOST" , "127.0.0.1" )
23+ func init () {
24+ flag .IntVar (& publishInterval , "publish-interval" , 10 , "publish interval in seconds" )
25+ flag .StringVar (& publishHost , "publish-host" , getopt ("HOST" , "127.0.0.1" ), "service discovery hostname" )
26+ flag .StringVar (& publishPath , "publish-path" , getopt ("ETCD_PATH" , "/deis/logs" ), "path to publish host/port information" )
27+ flag .StringVar (& publishPort , "publish-port" , getopt ("ETCD_PORT" , "4001" ), "service discovery port" )
28+ flag .IntVar (& publishTTL , "publish-ttl" , publishInterval * 2 , "publish TTL in seconds" )
29+ }
2230
23- etcdPort := getopt ( "ETCD_PORT" , "4001" )
24- etcdPath := getopt ( "ETCD_PATH" , "/deis/logs" )
31+ func main () {
32+ flag . Parse ( )
2533
2634 externalPort := getopt ("EXTERNAL_PORT" , "514" )
2735
28- client := etcd .NewClient ([]string {"http://" + host + ":" + etcdPort })
36+ client := etcd .NewClient ([]string {"http://" + publishHost + ":" + publishPort })
2937
3038 // Wait for terminating signal
3139 exitChan := make (chan os.Signal , 2 )
@@ -34,7 +42,7 @@ func main() {
3442
3543 go syslogd .Listen (exitChan , cleanupChan )
3644
37- go publishService (client , host , etcdPath , externalPort , uint64 (ttl .Seconds ()))
45+ go publishService (client , publishHost , publishPath , externalPort , uint64 (time . Duration ( publishTTL ) .Seconds ()))
3846
3947 // Wait for the proper shutdown of the syslog server before exit
4048 <- cleanupChan
@@ -44,7 +52,7 @@ func publishService(client *etcd.Client, host string, etcdPath string, externalP
4452 for {
4553 setEtcd (client , etcdPath + "/host" , host , ttl )
4654 setEtcd (client , etcdPath + "/port" , externalPort , ttl )
47- time .Sleep (timeout )
55+ time .Sleep (time . Duration ( publishInterval ) )
4856 }
4957}
5058
0 commit comments