Skip to content

Commit

Permalink
#99 pid file made configurable from aah.conf (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm committed Aug 22, 2017
1 parent 07732f9 commit fae4b30
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
8 changes: 4 additions & 4 deletions aah_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,15 @@ func TestAahLogDir(t *testing.T) {
}

func TestWritePID(t *testing.T) {
pidfile := filepath.Join(getTestdataPath(), "test-app.pid")
defer ess.DeleteFiles(pidfile)
pidfile := filepath.Join(getTestdataPath(), "test-app")
defer ess.DeleteFiles(pidfile + ".pid")

cfgDir := filepath.Join(getTestdataPath(), appConfigDir())
err := initConfig(cfgDir)
assert.Nil(t, err)

writePID("test-app", getTestdataPath())
assert.True(t, ess.IsFileExists(pidfile))
writePID(AppConfig(), "test-app", getTestdataPath())
assert.True(t, ess.IsFileExists(pidfile+".pid"))
}

func TestAahBuildInfo(t *testing.T) {
Expand Down
10 changes: 10 additions & 0 deletions param_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"reflect"
"strings"
"testing"
"time"

"aahframework.org/ahttp.v0"
"aahframework.org/config.v0"
Expand Down Expand Up @@ -157,3 +159,11 @@ func TestParamContentNegotiation(t *testing.T) {

isContentNegotiationEnabled = false
}

func TestParamAddValueParser(t *testing.T) {
err := AddValueParser(reflect.TypeOf(time.Time{}), func(key string, typ reflect.Type, params url.Values) (reflect.Value, error) {
return reflect.Value{}, nil
})
assert.NotNil(t, err)
assert.Equal(t, "valpar: value parser is already exists", err.Error())
}
2 changes: 1 addition & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func Start() {

aahServer.SetKeepAlivesEnabled(AppConfig().BoolDefault("server.keep_alive", true))

go writePID(getBinaryFileName(), AppBaseDir())
go writePID(AppConfig(), getBinaryFileName(), AppBaseDir())
go listenSignals()

// Unix Socket
Expand Down
17 changes: 14 additions & 3 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"strings"

"aahframework.org/ahttp.v0"
"aahframework.org/config.v0"
"aahframework.org/essentials.v0"
"aahframework.org/log.v0"
)
Expand Down Expand Up @@ -67,10 +68,20 @@ func checkSSLConfigValues(isSSLEnabled, isLetsEncrypt bool, sslCert, sslKey stri
return nil
}

func writePID(appBinaryName, appBaseDir string) {
func writePID(cfg *config.Config, appBinaryName, appBaseDir string) {
// Get the application PID
appPID = os.Getpid()
pidfile := filepath.Join(appBaseDir, appBinaryName+".pid")
if err := ioutil.WriteFile(pidfile, []byte(strconv.Itoa(appPID)), 0644); err != nil {

pidFile := cfg.StringDefault("pid_file", "")
if ess.IsStrEmpty(pidFile) {
pidFile = filepath.Join(appBaseDir, appBinaryName)
}

if !strings.HasSuffix(pidFile, ".pid") {
pidFile += ".pid"
}

if err := ioutil.WriteFile(pidFile, []byte(strconv.Itoa(appPID)), 0644); err != nil {
log.Error(err)
}
}
Expand Down

0 comments on commit fae4b30

Please sign in to comment.