Merge lp:~thumper/juju-core/upstart-retry-start-on-install into lp:~go-bot/juju-core/trunk

Proposed by Tim Penhey
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: 1918
Proposed branch: lp:~thumper/juju-core/upstart-retry-start-on-install
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 81 lines (+22/-8)
2 files modified
upstart/upstart.go (+16/-1)
upstart/upstart_test.go (+6/-7)
To merge this branch: bzr merge lp:~thumper/juju-core/upstart-retry-start-on-install
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+188761@code.launchpad.net

Commit message

Use a retry strategy to start new services.

On slower disks, upstart doesn't necessarily notice
the file straight away. Use a retry strategy to
start the newly written upstart file.

The first attempt happens straight away, so no slow
down on faster systems.

https://codereview.appspot.com/14260043/

Description of the change

Use a retry strategy to start new services.

On slower disks, upstart doesn't necessarily notice
the file straight away. Use a retry strategy to
start the newly written upstart file.

The first attempt happens straight away, so no slow
down on faster systems.

https://codereview.appspot.com/14260043/

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :
Download full text (3.2 KiB)

Reviewers: mp+188761_code.launchpad.net,

Message:
Please take a look.

Description:
Use a retry strategy to start new services.

On slower disks, upstart doesn't necessarily notice
the file straight away. Use a retry strategy to
start the newly written upstart file.

The first attempt happens straight away, so no slow
down on faster systems.

https://code.launchpad.net/~thumper/juju-core/upstart-retry-start-on-install/+merge/188761

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/14260043/

Affected files (+24, -8 lines):
   A [revision details]
   M upstart/upstart.go
   M upstart/upstart_test.go

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-20131002011707-z9ofwwxn0ra5xh9t
+New revision: <email address hidden>

Index: upstart/upstart.go
=== modified file 'upstart/upstart.go'
--- upstart/upstart.go 2013-10-01 21:09:59 +0000
+++ upstart/upstart.go 2013-10-02 03:44:40 +0000
@@ -13,10 +13,18 @@
   "path"
   "regexp"
   "text/template"
+ "time"
+
+ "launchpad.net/juju-core/utils"
  )

  var startedRE = regexp.MustCompile(`^.* start/running, process (\d+)\n$`)

+var InstallStartRetryAttempts = utils.AttemptStrategy{
+ Total: 1 * time.Second,
+ Delay: 250 * time.Millisecond,
+}
+
  // Service provides visibility into and control over an upstart service.
  type Service struct {
   Name string
@@ -181,7 +189,14 @@
   if err := ioutil.WriteFile(c.confPath(), conf, 0644); err != nil {
    return err
   }
- return c.Start()
+ // On slower disks, upstart may take a short time to realise
+ // that there is a service there.
+ for attempt := InstallStartRetryAttempts.Start(); attempt.Next(); {
+ if err = c.Start(); err == nil {
+ break
+ }
+ }
+ return err
  }

  // InstallCommands returns shell commands to install and start the service.

Index: upstart/upstart_test.go
=== modified file 'upstart/upstart_test.go'
--- upstart/upstart_test.go 2013-10-02 00:16:23 +0000
+++ upstart/upstart_test.go 2013-10-02 03:44:40 +0000
@@ -13,13 +13,15 @@
   gc "launchpad.net/gocheck"

   jc "launchpad.net/juju-core/testing/checkers"
+ "launchpad.net/juju-core/testing/testbase"
   "launchpad.net/juju-core/upstart"
+ "launchpad.net/juju-core/utils"
  )

  func Test(t *testing.T) { gc.TestingT(t) }

  type UpstartSuite struct {
- origPath string
+ testbase.LoggingSuite
   testPath string
   service *upstart.Service
  }
@@ -27,18 +29,15 @@
  var _ = gc.Suite(&UpstartSuite{})

  func (s *UpstartSuite) SetUpTest(c *gc.C) {
- s.origPath = os.Getenv("PATH")
+ origPath := os.Getenv("PATH")
   s.testPath = c.MkDir()
- os.Setenv("PATH", s.testPath+":"+s.origPath)
+ s.PatchEnvironment("PATH", s.testPath+":"+origPath)
+ s.PatchValue(&upstart.InstallStartRetryAttempts, utils.AttemptStrategy{})
   s.service = &upstart.Service{Name: "some-service", InitDir: c.MkDir()}
   _, err := os.Create(filepath.Join(s.service.InitDir, "some-service.conf"))
   c.Assert(err, gc.IsNil)
  }

-func (s *UpstartSuite) TearDownTest(c *gc.C) {
- os.Setenv("PATH...

Read more...

Revision history for this message
Andrew Wilkins (axwalk) wrote :

On 2013/10/02 03:48:39, thumper wrote:
> Please take a look.

LGTM

https://codereview.appspot.com/14260043/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'upstart/upstart.go'
2--- upstart/upstart.go 2013-10-01 21:09:59 +0000
3+++ upstart/upstart.go 2013-10-02 03:47:13 +0000
4@@ -13,10 +13,18 @@
5 "path"
6 "regexp"
7 "text/template"
8+ "time"
9+
10+ "launchpad.net/juju-core/utils"
11 )
12
13 var startedRE = regexp.MustCompile(`^.* start/running, process (\d+)\n$`)
14
15+var InstallStartRetryAttempts = utils.AttemptStrategy{
16+ Total: 1 * time.Second,
17+ Delay: 250 * time.Millisecond,
18+}
19+
20 // Service provides visibility into and control over an upstart service.
21 type Service struct {
22 Name string
23@@ -181,7 +189,14 @@
24 if err := ioutil.WriteFile(c.confPath(), conf, 0644); err != nil {
25 return err
26 }
27- return c.Start()
28+ // On slower disks, upstart may take a short time to realise
29+ // that there is a service there.
30+ for attempt := InstallStartRetryAttempts.Start(); attempt.Next(); {
31+ if err = c.Start(); err == nil {
32+ break
33+ }
34+ }
35+ return err
36 }
37
38 // InstallCommands returns shell commands to install and start the service.
39
40=== modified file 'upstart/upstart_test.go'
41--- upstart/upstart_test.go 2013-10-02 00:16:23 +0000
42+++ upstart/upstart_test.go 2013-10-02 03:47:13 +0000
43@@ -13,13 +13,15 @@
44 gc "launchpad.net/gocheck"
45
46 jc "launchpad.net/juju-core/testing/checkers"
47+ "launchpad.net/juju-core/testing/testbase"
48 "launchpad.net/juju-core/upstart"
49+ "launchpad.net/juju-core/utils"
50 )
51
52 func Test(t *testing.T) { gc.TestingT(t) }
53
54 type UpstartSuite struct {
55- origPath string
56+ testbase.LoggingSuite
57 testPath string
58 service *upstart.Service
59 }
60@@ -27,18 +29,15 @@
61 var _ = gc.Suite(&UpstartSuite{})
62
63 func (s *UpstartSuite) SetUpTest(c *gc.C) {
64- s.origPath = os.Getenv("PATH")
65+ origPath := os.Getenv("PATH")
66 s.testPath = c.MkDir()
67- os.Setenv("PATH", s.testPath+":"+s.origPath)
68+ s.PatchEnvironment("PATH", s.testPath+":"+origPath)
69+ s.PatchValue(&upstart.InstallStartRetryAttempts, utils.AttemptStrategy{})
70 s.service = &upstart.Service{Name: "some-service", InitDir: c.MkDir()}
71 _, err := os.Create(filepath.Join(s.service.InitDir, "some-service.conf"))
72 c.Assert(err, gc.IsNil)
73 }
74
75-func (s *UpstartSuite) TearDownTest(c *gc.C) {
76- os.Setenv("PATH", s.origPath)
77-}
78-
79 var checkargs = `
80 #!/bin/bash
81 if [ "$1" != "--system" ]; then

Subscribers

People subscribed via source and target branches

to status/vote changes: