diff --git a/tools/phpfpm/process.go b/tools/phpfpm/process.go index 6d8e4d1..9f91707 100644 --- a/tools/phpfpm/process.go +++ b/tools/phpfpm/process.go @@ -60,25 +60,51 @@ func NewProcess(phpFpm string) *Process { // SaveConfig generates config file according to the // process attributes -func (proc *Process) SaveConfig(path string) { +func (proc *Process) SaveConfig(path string) (err error) { proc.ConfigFile = path - proc.Config().SaveTo(proc.ConfigFile) + c, err := proc.Config() + if err != nil { + return + } + err = c.SaveTo(proc.ConfigFile) + return } // Config generates an minimalistic config ini file // in *ini.File format. You may then use SaveTo(path) // to save it -func (proc *Process) Config() (f *ini.File) { +func (proc *Process) Config() (f *ini.File, err error) { + var s *ini.Section f = ini.Empty() - f.NewSection("global") - f.Section("global").NewKey("pid", proc.PidFile) - f.Section("global").NewKey("error_log", proc.ErrorLog) - f.NewSection("www") - f.Section("www").NewKey("listen", proc.Listen) - f.Section("www").NewKey("pm", "static") - f.Section("www").NewKey("pm.max_children", fmt.Sprintf("%d", proc.Worker)) + + // global + if s, err = f.NewSection("global"); err != nil { + return + } + if _, err = s.NewKey("pid", proc.PidFile); err != nil { + return + } + if _, err = s.NewKey("error_log", proc.ErrorLog); err != nil { + return + } + + // www + if s, err = f.NewSection("www"); err != nil { + return + } + if _, err = s.NewKey("listen", proc.Listen); err != nil { + return + } + if _, err = s.NewKey("pm", "static"); err != nil { + return + } + if _, err = s.NewKey("pm.max_children", fmt.Sprintf("%d", proc.Worker)); err != nil { + return + } if proc.User != "" { - f.Section("www").NewKey("user", proc.User) + if _, err = s.NewKey("user", proc.User); err != nil { + return + } } return } diff --git a/tools/phpfpm/process_test.go b/tools/phpfpm/process_test.go index a6bc98a..e7a48b3 100644 --- a/tools/phpfpm/process_test.go +++ b/tools/phpfpm/process_test.go @@ -99,7 +99,10 @@ func TestProcess_StartStop(t *testing.T) { process := phpfpm.NewProcess(path) process.SetDatadir(basepath + "/var") process.User = username - process.SaveConfig(basepath + "/etc/test.startstop.conf") + if err := process.SaveConfig(basepath + "/etc/test.startstop.conf"); err != nil { + t.Errorf("unexpected error: %s", err.Error()) + return + } if err := process.Start(); err != nil { t.Errorf("unexpected error: %s", err.Error())