[feature] Added systemd support
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
ceb3c4bba5
commit
41292b25e3
2
Makefile
2
Makefile
@ -7,7 +7,7 @@ race:
|
||||
go run --race cmd/server/main.go
|
||||
|
||||
build:
|
||||
go build -o build/server cmd/server/main.go
|
||||
GOOS=linux GOARCH=amd64 go build -o build/server cmd/server/main.go
|
||||
|
||||
test:
|
||||
go test -v -run=. test/**/*.go
|
||||
|
17
init/api-server.service
Normal file
17
init/api-server.service
Normal file
@ -0,0 +1,17 @@
|
||||
#FIXME: FIX PATHS
|
||||
|
||||
[Unit]
|
||||
Requires=network-online.target
|
||||
After=network-online.target
|
||||
Requires=api-server.socket
|
||||
|
||||
[Service]
|
||||
ExecStart=/home/keedosn/go/src/git.pbiernat.dev/api-prototype/build/server
|
||||
WorkingDirectory=/home/keedosn/go/src/git.pbiernat.dev/api-prototype
|
||||
User=keedosn
|
||||
Group=keedosn
|
||||
NonBlocking=true
|
||||
StandardOutput=append:/home/keedosn/go/src/git.pbiernat.dev/api-prototype/build/err.log
|
||||
StandardError=append:/home/keedosn/go/src/git.pbiernat.dev/api-prototype/build/err.log
|
||||
SyslogIdentifier=api-server
|
||||
|
7
init/api-server.socket
Normal file
7
init/api-server.socket
Normal file
@ -0,0 +1,7 @@
|
||||
[Unit]
|
||||
Description=API Server socket
|
||||
|
||||
[Socket]
|
||||
ListenStream=10080
|
||||
NoDelay=true
|
||||
|
@ -5,7 +5,10 @@ import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
def "git.pbiernat.dev/golang/rest-api-prototype/internal/app/definition"
|
||||
@ -30,8 +33,18 @@ func NewServer(env *handler.Env) *Server {
|
||||
|
||||
func (s *Server) Start() {
|
||||
log.Println("Server listening on " + s.Addr)
|
||||
if err := s.ListenAndServe(); err != nil {
|
||||
log.Println(err)
|
||||
|
||||
if os.Getenv("LISTEN_PID") == strconv.Itoa(os.Getpid()) {
|
||||
// systemd run
|
||||
f := os.NewFile(3, "from systemd")
|
||||
l, err := net.FileListener(f)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
http.Serve(l, nil)
|
||||
} else {
|
||||
// manual run
|
||||
log.Fatalln(s.ListenAndServe())
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user