2018-11-08 17:22:26 +08:00
|
|
|
package model
|
|
|
|
|
2018-11-21 17:35:07 +08:00
|
|
|
import (
|
|
|
|
"os/user"
|
|
|
|
"runtime"
|
|
|
|
|
|
|
|
"github.com/goodrain/rainbond/cmd/gateway/option"
|
|
|
|
)
|
|
|
|
|
|
|
|
//Nginx nginx config model
|
2018-11-08 17:22:26 +08:00
|
|
|
type Nginx struct {
|
2018-11-21 17:35:07 +08:00
|
|
|
WorkerProcesses int
|
|
|
|
WorkerRlimitNofile int
|
|
|
|
ErrorLog string
|
|
|
|
User string
|
|
|
|
EventLog EventLog
|
|
|
|
Events Events
|
2018-11-23 14:34:44 +08:00
|
|
|
HTTP *HTTP
|
2018-11-08 17:22:26 +08:00
|
|
|
}
|
|
|
|
|
2018-11-23 14:34:44 +08:00
|
|
|
// EventLog -
|
2018-11-08 17:22:26 +08:00
|
|
|
type EventLog struct {
|
|
|
|
Path string
|
|
|
|
Level string
|
|
|
|
}
|
|
|
|
|
2018-11-21 17:35:07 +08:00
|
|
|
//Events nginx events config model
|
2018-11-08 17:22:26 +08:00
|
|
|
type Events struct {
|
|
|
|
WorkerConnections int
|
2018-11-21 17:35:07 +08:00
|
|
|
EnableEpoll bool
|
|
|
|
EnableMultiAccept bool
|
2018-11-08 17:22:26 +08:00
|
|
|
}
|
|
|
|
|
2018-11-21 17:35:07 +08:00
|
|
|
//NewNginx new nginx config
|
2018-12-02 21:09:32 +08:00
|
|
|
func NewNginx(conf option.Config) *Nginx {
|
2018-11-21 17:35:07 +08:00
|
|
|
if conf.NginxUser != "" {
|
|
|
|
if u, err := user.Current(); err == nil {
|
|
|
|
if conf.NginxUser == u.Username {
|
|
|
|
//if set user name like run user,do not set
|
|
|
|
conf.NginxUser = ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if conf.WorkerProcesses == 0 {
|
|
|
|
conf.WorkerProcesses = runtime.NumCPU()
|
|
|
|
}
|
2018-11-08 17:22:26 +08:00
|
|
|
return &Nginx{
|
2018-11-21 17:35:07 +08:00
|
|
|
WorkerProcesses: conf.WorkerProcesses,
|
|
|
|
WorkerRlimitNofile: conf.WorkerRlimitNofile,
|
|
|
|
User: conf.NginxUser,
|
|
|
|
ErrorLog: conf.ErrorLog,
|
|
|
|
Events: Events{
|
|
|
|
WorkerConnections: conf.WorkerConnections,
|
|
|
|
EnableEpoll: conf.EnableEpool,
|
|
|
|
EnableMultiAccept: conf.EnableMultiAccept,
|
2018-11-08 17:22:26 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|