summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-09-21 16:22:26 +0300
committerWolfy-J <[email protected]>2018-09-21 16:22:26 +0300
commita6191395dbf15b5884999382a0fc6ca894367323 (patch)
tree2a110d84d061b4ff8aa06a57cc2b8e0d00120e7c
parentf44a1368c9da1dda098dad25ac9dcc4db40f24c1 (diff)
- added RR_HTTP env variable to php processes run under http service
- bugfix: ignored `--config` option - added shorthand for config `-c` - rr now changes working dir to the config location (allows relating paths for php scripts)
-rw-r--r--cmd/rr/cmd/root.go33
-rw-r--r--service/http/service.go11
2 files changed, 34 insertions, 10 deletions
diff --git a/cmd/rr/cmd/root.go b/cmd/rr/cmd/root.go
index 5e936580..4ab37967 100644
--- a/cmd/rr/cmd/root.go
+++ b/cmd/rr/cmd/root.go
@@ -27,6 +27,7 @@ import (
"github.com/spiral/roadrunner/cmd/rr/utils"
"github.com/spiral/roadrunner/service"
"os"
+ "path/filepath"
)
// Service bus for all the commands.
@@ -81,13 +82,6 @@ func (w *ViperWrapper) Unmarshal(out interface{}) error {
// Execute adds all child commands to the CLI command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the CLI.
func Execute() {
- if cfg := initConfig(cfgFile, []string{"."}, ".rr"); cfg != nil {
- if err := Container.Init(cfg); err != nil {
- utils.Printf("<red+hb>Error:</reset> <red>%s</reset>\n", err)
- os.Exit(1)
- }
- }
-
if err := CLI.Execute(); err != nil {
utils.Printf("<red+hb>Error:</reset> <red>%s</reset>\n", err)
os.Exit(1)
@@ -97,12 +91,19 @@ func Execute() {
func init() {
CLI.PersistentFlags().BoolVarP(&Verbose, "Verbose", "v", false, "Verbose output")
CLI.PersistentFlags().BoolVarP(&Debug, "debug", "d", false, "debug mode")
- CLI.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is .rr.yaml)")
+ CLI.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file (default is .rr.yaml)")
cobra.OnInitialize(func() {
if Verbose {
Logger.SetLevel(logrus.DebugLevel)
}
+
+ if cfg := initConfig(cfgFile, []string{"."}, ".rr"); cfg != nil {
+ if err := Container.Init(cfg); err != nil {
+ utils.Printf("<red+hb>Error:</reset> <red>%s</reset>\n", err)
+ os.Exit(1)
+ }
+ }
})
}
@@ -110,8 +111,24 @@ func initConfig(cfgFile string, path []string, name string) service.Config {
cfg := viper.New()
if cfgFile != "" {
+ if absPath, err := filepath.Abs(cfgFile); err == nil {
+ cfgFile = absPath
+
+ // force working absPath related to config file
+ if err := os.Chdir(filepath.Dir(absPath)); err != nil {
+ Logger.Error(err)
+ }
+ }
+
// Use cfg file from the flag.
cfg.SetConfigFile(cfgFile)
+
+ if dir, err := filepath.Abs(cfgFile); err == nil {
+ // force working absPath related to config file
+ if err := os.Chdir(filepath.Dir(dir)); err != nil {
+ Logger.Error(err)
+ }
+ }
} else {
// automatic location
for _, p := range path {
diff --git a/service/http/service.go b/service/http/service.go
index f988a843..ecce1c15 100644
--- a/service/http/service.go
+++ b/service/http/service.go
@@ -11,8 +11,13 @@ import (
"sync/atomic"
)
-// ID contains default svc name.
-const ID = "http"
+const (
+ // ID contains default svc name.
+ ID = "http"
+
+ // httpKey indicates to php process that it's running under http service
+ httpKey = "rr_http"
+)
// http middleware type.
type middleware func(f http.HandlerFunc) http.HandlerFunc
@@ -69,6 +74,8 @@ func (s *Service) Serve() error {
for k, v := range values {
s.cfg.Workers.SetEnv(k, v)
}
+
+ s.cfg.Workers.SetEnv(httpKey, "true")
}
rr := roadrunner.NewServer(s.cfg.Workers)