Skip to content

Commit 17f59ae

Browse files
author
Matthew Fisher
committed
fix(router): revert symlink to /dev/stdout
Nginx cannot log to a device for some reason, so this will have to stay.
1 parent eb3f7e6 commit 17f59ae

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

router/Dockerfile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ RUN addgroup -S nginx && \
2121

2222
COPY rootfs /
2323

24-
# forward request and error logs to docker
25-
RUN ln -sf /dev/stdout /opt/nginx/logs/access.log
26-
RUN ln -sf /dev/stderr /opt/nginx/logs/error.log
27-
2824
# compile nginx from source
2925
RUN build
3026

router/cmd/boot/boot.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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 (
2021
var log = logrus.New()
2122

2223
const (
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

2730
func 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

8592
func 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+
164180
func publishService(
165181
client *etcd.Client,
166182
etcdPath string,

0 commit comments

Comments
 (0)