@@ -11,6 +11,7 @@ import (
1111 "syscall"
1212 "time"
1313
14+ "github.com/ActiveState/tail"
1415 "github.com/Sirupsen/logrus"
1516 "github.com/coreos/go-etcd/etcd"
1617
@@ -20,8 +21,10 @@ import (
2021var log = logrus .New ()
2122
2223const (
23- timeout time.Duration = 10 * time .Second
24- ttl time.Duration = timeout * 2
24+ timeout time.Duration = 10 * time .Second
25+ ttl time.Duration = timeout * 2
26+ nginxAccessLog string = "/opt/nginx/logs/access.log"
27+ nginxErrorLog string = "/opt/nginx/logs/error.log"
2528)
2629
2730func main () {
@@ -62,6 +65,9 @@ func main() {
6265
6366 log .Info ("Starting Nginx..." )
6467
68+ go tailFile (nginxAccessLog )
69+ go tailFile (nginxErrorLog )
70+
6571 nginxChan := make (chan bool )
6672 go launchNginx (nginxChan )
6773 <- nginxChan
@@ -80,6 +86,7 @@ func main() {
8086 exitChan := make (chan os.Signal , 2 )
8187 signal .Notify (exitChan , syscall .SIGTERM , syscall .SIGINT )
8288 <- exitChan
89+ tail .Cleanup ()
8390}
8491
8592func launchCron () {
@@ -161,6 +168,15 @@ func mkfifo(path string) {
161168 }
162169}
163170
171+ func tailFile (path string ) {
172+ mkfifo (path )
173+ t , _ := tail .TailFile (path , tail.Config {Follow : true })
174+
175+ for line := range t .Lines {
176+ log .Info (line .Text )
177+ }
178+ }
179+
164180func publishService (
165181 client * etcd.Client ,
166182 etcdPath string ,
0 commit comments