Services can now write to pidfiles
This commit is contained in:
@@ -4,8 +4,9 @@ import "io"
|
||||
import "os"
|
||||
import "log"
|
||||
import "time"
|
||||
import "hnakra/rotate"
|
||||
import "hnakra/router"
|
||||
import "hnakra/rotate"
|
||||
import "hnakra/daemon"
|
||||
import "hnakra/routines"
|
||||
import "hnakra/router/rcon"
|
||||
import "hnakra/router/config"
|
||||
@@ -59,10 +60,10 @@ func main () {
|
||||
manager := routines.Manager { RestartDeadline: time.Second * 8 }
|
||||
rout := router.New(conf)
|
||||
srvhnakra := &srvhnakra.Server { Config: conf, Router: rout }
|
||||
manager.Append(srvhnakra.ListenAndServe)
|
||||
manager.Append(srvhnakra)
|
||||
if conf.HTTPSEnable() {
|
||||
srvhttps := &srvhttps.Server { Config: conf, Handler: rout }
|
||||
manager.Append(srvhttps.ListenAndServe)
|
||||
manager.Append(srvhttps)
|
||||
}
|
||||
|
||||
// set up rcon
|
||||
@@ -74,12 +75,19 @@ func main () {
|
||||
log.SetOutput(originalWriter)
|
||||
}
|
||||
|
||||
// be a daemon
|
||||
daemon.ShutdownOnSigint()
|
||||
pidfile := daemon.PidFile(os.Getenv("HNAKRA_PIDFILE"))
|
||||
if !pidfile.Empty() {
|
||||
err := pidfile.Start()
|
||||
if err != nil { log.Println("!!! could not write pid:", err) }
|
||||
}
|
||||
defer func () {
|
||||
err := pidfile.Close()
|
||||
if err != nil { log.Println("!!! could not delete pidfile:", err) }
|
||||
} ()
|
||||
|
||||
// run servers
|
||||
err = manager.Run()
|
||||
if err != nil { log.Println("XXX", err) }
|
||||
}
|
||||
|
||||
func httpsRoutine (server *srvhttps.Server) {
|
||||
err := server.ListenAndServe()
|
||||
if err != nil { log.Println("XXX", err) }
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ type Server struct {
|
||||
Router *router.Router
|
||||
}
|
||||
|
||||
func (server *Server) ListenAndServe () (err error) {
|
||||
func (server *Server) Run () (err error) {
|
||||
server.underlying, err = tls.Listen (
|
||||
"tcp", fmt.Sprint(":", server.Config.RouterPort()),
|
||||
config.TLSConfigFor(server.Config))
|
||||
@@ -29,6 +29,6 @@ func (server *Server) ListenAndServe () (err error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (server *Server) Close () error {
|
||||
func (server *Server) Shutdown () error {
|
||||
return server.underlying.Close()
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ type Server struct {
|
||||
Handler http.Handler
|
||||
}
|
||||
|
||||
func (server *Server) ListenAndServe () error {
|
||||
func (server *Server) Run () error {
|
||||
server.underlying = &http.Server {
|
||||
Addr: fmt.Sprint(":", server.Config.HTTPSPort()),
|
||||
// ReadHeaderTimeout: timeoutReadHeader * time.Second,
|
||||
@@ -26,6 +26,6 @@ func (server *Server) ListenAndServe () error {
|
||||
return server.underlying.ListenAndServeTLS("", "")
|
||||
}
|
||||
|
||||
func (server *Server) Close () error {
|
||||
func (server *Server) Shutdown () error {
|
||||
return server.underlying.Close()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user