Allow UNIX socket in FastCGI mode (check if bind starts with /) (#190)

Allow UNIX socket in FastCGI mode (check if bind starts with /)
This commit is contained in:
PaulC 2019-12-03 02:24:11 +00:00 committed by Andrei Marcu
parent bf090c5119
commit 0e763cb776
1 changed files with 23 additions and 1 deletions

View File

@ -8,9 +8,11 @@ import (
"net/http/fcgi" "net/http/fcgi"
"net/url" "net/url"
"os" "os"
"os/signal"
"regexp" "regexp"
"strconv" "strconv"
"strings" "strings"
"syscall"
"time" "time"
"github.com/GeertJohan/go.rice" "github.com/GeertJohan/go.rice"
@ -277,7 +279,27 @@ func main() {
mux := setup() mux := setup()
if Config.fastcgi { if Config.fastcgi {
listener, err := net.Listen("tcp", Config.bind) var listener net.Listener
var err error
if Config.bind[0] == '/' {
// UNIX path
listener, err = net.ListenUnix("unix", &net.UnixAddr{Name: Config.bind, Net: "unix"})
cleanup := func() {
log.Print("Removing FastCGI socket")
os.Remove(Config.bind)
}
defer cleanup()
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
sig := <-sigs
log.Print("Signal: ", sig)
cleanup()
os.Exit(0)
}()
} else {
listener, err = net.Listen("tcp", Config.bind)
}
if err != nil { if err != nil {
log.Fatal("Could not bind: ", err) log.Fatal("Could not bind: ", err)
} }