Browse Source

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

Allow UNIX socket in FastCGI mode (check if bind starts with /)
pull/147/merge
PaulC 5 years ago
committed by Andrei Marcu
parent
commit
0e763cb776
  1. 24
      server.go

24
server.go

@ -8,9 +8,11 @@ import (
"net/http/fcgi"
"net/url"
"os"
"os/signal"
"regexp"
"strconv"
"strings"
"syscall"
"time"
"github.com/GeertJohan/go.rice"
@ -277,7 +279,27 @@ func main() {
mux := setup()
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 {
log.Fatal("Could not bind: ", err)
}

Loading…
Cancel
Save