Skip to content

Commit

Permalink
replace packages for pid file writing and reading (TykTechnologies#2892)
Browse files Browse the repository at this point in the history
  • Loading branch information
gernest authored Feb 25, 2020
1 parent 0473476 commit 3224063
Show file tree
Hide file tree
Showing 14 changed files with 20 additions and 351 deletions.
23 changes: 19 additions & 4 deletions gateway/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
"github.com/TykTechnologies/tyk/user"
logstashHook "github.com/bshuster-repo/logrus-logstash-hook"
"github.com/evalphobia/logrus_sentry"
"github.com/facebookgo/pidfile"
graylogHook "github.com/gemnasium/logrus-graylog-hook"
"github.com/gorilla/mux"
"github.com/justinas/alice"
Expand Down Expand Up @@ -943,8 +942,7 @@ func initialiseSystem(ctx context.Context) error {

mainLog.Info("PIDFile location set to: ", config.Global().PIDFileLocation)

pidfile.SetPidfilePath(config.Global().PIDFileLocation)
if err := pidfile.Write(); err != nil {
if err := writePIDFile(); err != nil {
mainLog.Error("Failed to write PIDFile: ", err)
}

Expand All @@ -965,6 +963,23 @@ func initialiseSystem(ctx context.Context) error {
return nil
}

func writePIDFile() error {
file := config.Global().PIDFileLocation
if err := os.MkdirAll(filepath.Dir(file), 0755); err != nil {
return err
}
pid := strconv.Itoa(os.Getpid())
return ioutil.WriteFile(file, []byte(pid), 0600)
}

func readPIDFromFile() (int, error) {
b, err := ioutil.ReadFile(config.Global().PIDFileLocation)
if err != nil {
return 0, err
}
return strconv.Atoi(string(b))
}

// afterConfSetup takes care of non-sensical config values (such as zero
// timeouts) and sets up a few globals that depend on the config.
func afterConfSetup(conf *config.Config) {
Expand Down Expand Up @@ -1096,7 +1111,7 @@ var hostDetails struct {

func getHostDetails() {
var err error
if hostDetails.PID, err = pidfile.Read(); err != nil {
if hostDetails.PID, err = readPIDFromFile(); err != nil {
mainLog.Error("Failed ot get host pid: ", err)
}
if hostDetails.Hostname, err = os.Hostname(); err != nil {
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/emanoelxavier/openid2go v0.0.0-20190718021401-6345b638bfc9 // indirect
github.com/evalphobia/logrus_sentry v0.8.2
github.com/facebookgo/atomicfile v0.0.0-20151019160806-2de1f203e7d5 // indirect
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a // indirect
github.com/facebookgo/pidfile v0.0.0-20150612191647-f242e2999868
github.com/franela/goblin v0.0.0-20181003173013-ead4ad1d2727 // indirect
github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8
github.com/gemnasium/logrus-graylog-hook v2.0.7+incompatible
Expand Down
10 changes: 1 addition & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ github.com/TykTechnologies/leakybucket v0.0.0-20170301023702-71692c943e3c h1:j6f
github.com/TykTechnologies/leakybucket v0.0.0-20170301023702-71692c943e3c/go.mod h1:GnHUbsQx+ysI10osPhUdTmsxcE7ef64cVp38Fdyd7e0=
github.com/TykTechnologies/murmur3 v0.0.0-20180602122059-1915e687e465 h1:A2gBjoX8aF0G3GHEpHyj2f0ixuPkCgcGqmPdKHSkW+0=
github.com/TykTechnologies/murmur3 v0.0.0-20180602122059-1915e687e465/go.mod h1:sqH/SPFr11m9cahie7ulBuBX9TOhfBX1sp+qf9jh3Vg=
github.com/TykTechnologies/openid2go v0.0.0-20160817213554-aab5ce1231ab h1:mDQXuVURkWTbTPlxOWom6c68xdWzp6HQeWAEqv4l7Vo=
github.com/TykTechnologies/openid2go v0.0.0-20160817213554-aab5ce1231ab/go.mod h1:rGlqNE4CvxZIeiHp0mgrw+/jdGSjJzkZ0n78hhHMdfM=
github.com/TykTechnologies/openid2go v0.0.0-20200122120050-1b642583380a h1:EJ9SLNrXbH0ywWNb/AbnXlBAgJWVBoRO6UpDOzze3H4=
github.com/TykTechnologies/openid2go v0.0.0-20200122120050-1b642583380a/go.mod h1:rGlqNE4CvxZIeiHp0mgrw+/jdGSjJzkZ0n78hhHMdfM=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
Expand Down Expand Up @@ -67,12 +65,8 @@ github.com/emanoelxavier/openid2go v0.0.0-20190718021401-6345b638bfc9/go.mod h1:
github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g=
github.com/evalphobia/logrus_sentry v0.8.2 h1:dotxHq+YLZsT1Bb45bB5UQbfCh3gM/nFFetyN46VoDQ=
github.com/evalphobia/logrus_sentry v0.8.2/go.mod h1:pKcp+vriitUqu9KiWj/VRFbRfFNUwz95/UkgG8a6MNc=
github.com/facebookgo/atomicfile v0.0.0-20151019160806-2de1f203e7d5 h1:BBso6MBKW8ncyZLv37o+KNyy0HrrHgfnOaGQC2qvN+A=
github.com/facebookgo/atomicfile v0.0.0-20151019160806-2de1f203e7d5/go.mod h1:JpoxHjuQauoxiFMl1ie8Xc/7TfLuMZ5eOCONd1sUBHg=
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a h1:yDWHCSQ40h88yih2JAcL6Ls/kVkSE8GFACTGVnMPruw=
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a/go.mod h1:7Ga40egUymuWXxAe151lTNnCv97MddSOVsjpPPkityA=
github.com/facebookgo/pidfile v0.0.0-20150612191647-f242e2999868 h1:KZ75X3ZCl6yy4jg9R1ziYoCZFDBRqildm+fGComWU7U=
github.com/facebookgo/pidfile v0.0.0-20150612191647-f242e2999868/go.mod h1:3Hzo46xzfVpIdv4lJw7YBp9fUJ7HpUgbjH1fFDgy4qM=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/franela/goblin v0.0.0-20181003173013-ead4ad1d2727 h1:eouy4stZdUKn7n98c1+rdUTxWMg+jvhP+oHt0K8fiug=
Expand Down Expand Up @@ -265,8 +259,6 @@ github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUt
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/square/go-jose v0.0.0-20161027010314-63d7cfa0284d h1:QyNGtv0d6JyxKalOUN74OQDAY+Ivrtywpv8mDvnd9sc=
github.com/square/go-jose v0.0.0-20161027010314-63d7cfa0284d/go.mod h1:7MxpAF/1WTVUu8Am+T5kNy+t0902CaLWM4Z745MkOa8=
github.com/square/go-jose v2.4.1+incompatible h1:KFYc54wTtgnd3x4B/Y7Zr1s/QaEx2BNzRsB3Hae5LHo=
github.com/square/go-jose v2.4.1+incompatible/go.mod h1:7MxpAF/1WTVUu8Am+T5kNy+t0902CaLWM4Z745MkOa8=
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
Expand Down Expand Up @@ -394,4 +386,4 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
rsc.io/letsencrypt v0.0.2 h1:CWRvaqcmyyWMhhhGes73TvuIjf7O3Crq6F+Xid/cWNI=
rsc.io/letsencrypt v0.0.2/go.mod h1:buyQKZ6IXrRnB7TdkHP0RyEybLx18HHyOSoTyoOLqNY=
rsc.io/letsencrypt v0.0.2/go.mod h1:buyQKZ6IXrRnB7TdkHP0RyEybLx18HHyOSoTyoOLqNY=
20 changes: 0 additions & 20 deletions vendor/github.com/facebookgo/atomicfile/.travis.yml

This file was deleted.

59 changes: 0 additions & 59 deletions vendor/github.com/facebookgo/atomicfile/atomicfile.go

This file was deleted.

30 changes: 0 additions & 30 deletions vendor/github.com/facebookgo/atomicfile/license

This file was deleted.

33 changes: 0 additions & 33 deletions vendor/github.com/facebookgo/atomicfile/patents

This file was deleted.

9 changes: 0 additions & 9 deletions vendor/github.com/facebookgo/atomicfile/readme.md

This file was deleted.

24 changes: 0 additions & 24 deletions vendor/github.com/facebookgo/pidfile/.travis.yml

This file was deleted.

30 changes: 0 additions & 30 deletions vendor/github.com/facebookgo/pidfile/license

This file was deleted.

33 changes: 0 additions & 33 deletions vendor/github.com/facebookgo/pidfile/patents

This file was deleted.

Loading

0 comments on commit 3224063

Please sign in to comment.