@@ -2,9 +2,11 @@ package main
22
33import (
44 "flag"
5+ "fmt"
56 "log"
67 "os"
78 "os/signal"
9+ "strconv"
810 "syscall"
911 "time"
1012
@@ -13,18 +15,22 @@ import (
1315)
1416
1517var (
16- enablePublish bool
17- publishHost string
18- publishPath string
19- publishPort string
18+ logAddr string
19+ logPort int
20+ enablePublish bool
21+ publishHost string
22+ publishPath string
23+ publishPort string
2024 publishInterval int
2125 publishTTL int
2226)
2327
2428func init () {
29+ flag .StringVar (& logAddr , "log-addr" , "0.0.0.0" , "bind address for the logger" )
30+ flag .IntVar (& logPort , "log-port" , 514 , "bind port for the logger" )
2531 flag .BoolVar (& enablePublish , "publish" , false , "enable publishing to service discovery" )
26- flag .IntVar (& publishInterval , "publish-interval" , 10 , "publish interval in seconds" )
2732 flag .StringVar (& publishHost , "publish-host" , getopt ("HOST" , "127.0.0.1" ), "service discovery hostname" )
33+ flag .IntVar (& publishInterval , "publish-interval" , 10 , "publish interval in seconds" )
2834 flag .StringVar (& publishPath , "publish-path" , getopt ("ETCD_PATH" , "/deis/logs" ), "path to publish host/port information" )
2935 flag .StringVar (& publishPort , "publish-port" , getopt ("ETCD_PORT" , "4001" ), "service discovery port" )
3036 flag .IntVar (& publishTTL , "publish-ttl" , publishInterval * 2 , "publish TTL in seconds" )
@@ -33,29 +39,27 @@ func init() {
3339func main () {
3440 flag .Parse ()
3541
36- externalPort := getopt ("EXTERNAL_PORT" , "514" )
37-
3842 client := etcd .NewClient ([]string {"http://" + publishHost + ":" + publishPort })
3943
4044 // Wait for terminating signal
4145 exitChan := make (chan os.Signal , 2 )
4246 cleanupChan := make (chan bool )
4347 signal .Notify (exitChan , syscall .SIGTERM , syscall .SIGINT )
4448
45- go syslogd .Listen (exitChan , cleanupChan )
49+ go syslogd .Listen (exitChan , cleanupChan , fmt . Sprintf ( "%s:%d" , logAddr , logPort ) )
4650
4751 if enablePublish {
48- go publishService (client , publishHost , publishPath , externalPort , uint64 (time .Duration (publishTTL ).Seconds ()))
52+ go publishService (client , publishHost , publishPath , strconv . Itoa ( logPort ) , uint64 (time .Duration (publishTTL ).Seconds ()))
4953 }
5054
5155 // Wait for the proper shutdown of the syslog server before exit
5256 <- cleanupChan
5357}
5458
55- func publishService (client * etcd.Client , host string , etcdPath string , externalPort string , ttl uint64 ) {
59+ func publishService (client * etcd.Client , host string , etcdPath string , port string , ttl uint64 ) {
5660 for {
5761 setEtcd (client , etcdPath + "/host" , host , ttl )
58- setEtcd (client , etcdPath + "/port" , externalPort , ttl )
62+ setEtcd (client , etcdPath + "/port" , port , ttl )
5963 time .Sleep (time .Duration (publishInterval ))
6064 }
6165}
0 commit comments