1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/integration/plugin/logging/cmd/close_on_start/main.go
Brian Goff e7479e3ab8 Fix logging plugin crash unrecoverable
In cases where a logging plugin has crashed when the daemon tries to
copy the container stdio to the logging plugin it returns a broken pipe
error and any log entries that occurr while the plugin is down are lost.

Fix this by opening read+write in the daemon so logs are not lost while
the plugin is down.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2018-05-14 16:51:56 -04:00

48 lines
986 B
Go

package main
import (
"encoding/json"
"fmt"
"net"
"net/http"
"os"
)
type start struct {
File string
}
func main() {
l, err := net.Listen("unix", "/run/docker/plugins/plugin.sock")
if err != nil {
panic(err)
}
mux := http.NewServeMux()
mux.HandleFunc("/LogDriver.StartLogging", func(w http.ResponseWriter, req *http.Request) {
startReq := &start{}
if err := json.NewDecoder(req.Body).Decode(startReq); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
f, err := os.OpenFile(startReq.File, os.O_RDONLY, 0600)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Close the file immediately, this allows us to test what happens in the daemon when the plugin has closed the
// file or, for example, the plugin has crashed.
f.Close()
w.WriteHeader(http.StatusOK)
fmt.Fprintln(w, `{}`)
})
server := http.Server{
Addr: l.Addr().String(),
Handler: mux,
}
server.Serve(l)
}