Skip to content
Browse files

Remove Process.Detached option

The Detached option was more useful when we did the double-fork self-detaching.
Since removing the double-fork, this option is less useful and will likely lead
to more confusion than convenience, where convenience was just gonit writing the
pid file.

With this option removed, processes are required to write their own pid file.

Change-Id: Id28025bfe3c58ed376f352f0d2f258b2792daa9a
  • Loading branch information...
1 parent 65f6245 commit 6d63c290fc0758c5778a449b21d4086727206ceb @dougm dougm committed
Showing with 17 additions and 35 deletions.
  1. +0 −1 configmanager.go
  2. +3 −10 process.go
  3. +2 −14 process_test.go
  4. +10 −10 test/helper/helper.go
  5. +2 −0 test/process/main.go
View
1 configmanager.go
@@ -64,7 +64,6 @@ type Process struct {
Stderr string
Env []string
Dir string
- Detached bool
Description string
DependsOn []string
Actions map[string][]string
View
13 process.go
@@ -103,10 +103,8 @@ func (p *Process) Spawn(program string) (*exec.Cmd, error) {
return cmd, err
}
-// Start a process:
-// If Detached == true; process must detached itself and
-// manage its own Pidfile.
-// Otherwise; we will detach the process and manage its Pidfile.
+// Start a process.
+// Process must manage its own Pidfile.
func (p *Process) StartProcess() (int, error) {
cmd, err := p.Spawn(p.Start)
if err != nil {
@@ -116,12 +114,7 @@ func (p *Process) StartProcess() (int, error) {
pid := cmd.Process.Pid
- if p.Detached {
- err = cmd.Wait()
- } else {
- err = p.SavePid(pid)
- go cmd.Wait()
- }
+ go cmd.Wait()
return pid, err
}
View
16 process_test.go
@@ -34,15 +34,6 @@ func processInfo(p *Process) *helper.ProcessInfo {
// these assertions apply to any daemon process
func assertProcessInfo(c *C, process *Process, info *helper.ProcessInfo) {
selfInfo := helper.CurrentProcessInfo()
- var ppid int
-
- if process.Detached {
- ppid = 1
- } else {
- ppid = selfInfo.Pid
- }
-
- c.Check(ppid, Equals, info.Ppid) // parent pid
c.Check(selfInfo.Pgrp, Not(Equals), info.Pgrp) // process group will change
@@ -108,11 +99,8 @@ func (s *ProcessSuite) TestSimple(c *C) {
info := processInfo(process)
- if process.Detached {
- c.Check(true, Equals, grandArgs(info.Args))
- } else {
- c.Check(pid, Equals, info.Pid)
- }
+ c.Check(pid, Equals, info.Pid)
+
assertProcessInfo(c, process, info)
err = process.StopProcess()
View
20 test/helper/helper.go
@@ -212,6 +212,7 @@ func NewTestProcess(name string, flags []string, detached bool) *Process {
TestProcess,
"-d", dir,
"-n", name,
+ "-p", pidfile,
}
for _, arg := range flags {
@@ -220,7 +221,7 @@ func NewTestProcess(name string, flags []string, detached bool) *Process {
if detached {
// process will detach itself
- args = append(args, "-F", "-p", pidfile)
+ args = append(args, "-F")
// configure stop + restart commands with
// the same flags as the start command
@@ -230,15 +231,14 @@ func NewTestProcess(name string, flags []string, detached bool) *Process {
start = mkcmd(args, "start")
return &Process{
- Name: name,
- Start: strings.Join(start, " "),
- Stop: strings.Join(stop, " "),
- Restart: strings.Join(restart, " "),
- Dir: dir,
- Stderr: logfile,
- Stdout: logfile,
- Pidfile: pidfile,
- Detached: detached,
+ Name: name,
+ Start: strings.Join(start, " "),
+ Stop: strings.Join(stop, " "),
+ Restart: strings.Join(restart, " "),
+ Dir: dir,
+ Stderr: logfile,
+ Stdout: logfile,
+ Pidfile: pidfile,
}
}
View
2 test/process/main.go
@@ -132,6 +132,8 @@ func main() {
}
savePid()
go handleSignals()
+ } else {
+ savePid()
}
saveProcessInfo()

0 comments on commit 6d63c29

Please sign in to comment.
Something went wrong with that request. Please try again.