Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2)

Delta Between Two Patch Sets: cmd/jujud/unit.go

Issue 6561063: cmd/jujud: implement uniter upgrade
Left Patch Set: cmd/jujud: implement uniter upgrade Created 12 years, 6 months ago
Right Patch Set: cmd/jujud: implement uniter upgrade Created 12 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « cmd/jujud/machine.go ('k') | cmd/jujud/upgrade.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 package main 1 package main
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "launchpad.net/gnuflag" 5 "launchpad.net/gnuflag"
6 "launchpad.net/juju-core/cmd" 6 "launchpad.net/juju-core/cmd"
7 "launchpad.net/juju-core/environs"
8 "launchpad.net/juju-core/log" 7 "launchpad.net/juju-core/log"
9 "launchpad.net/juju-core/state" 8 "launchpad.net/juju-core/state"
10 "launchpad.net/juju-core/worker/uniter" 9 "launchpad.net/juju-core/worker/uniter"
11 "launchpad.net/tomb" 10 "launchpad.net/tomb"
12 "time" 11 "time"
13 ) 12 )
14 13
15 // UnitAgent is a cmd.Command responsible for running a unit agent. 14 // UnitAgent is a cmd.Command responsible for running a unit agent.
16 type UnitAgent struct { 15 type UnitAgent struct {
17 tomb tomb.Tomb 16 tomb tomb.Tomb
(...skipping 23 matching lines...) Expand all
41 } 40 }
42 41
43 // Stop stops the unit agent. 42 // Stop stops the unit agent.
44 func (a *UnitAgent) Stop() error { 43 func (a *UnitAgent) Stop() error {
45 a.tomb.Kill(nil) 44 a.tomb.Kill(nil)
46 return a.tomb.Wait() 45 return a.tomb.Wait()
47 } 46 }
48 47
49 // Run runs a unit agent. 48 // Run runs a unit agent.
50 func (a *UnitAgent) Run(ctx *cmd.Context) error { 49 func (a *UnitAgent) Run(ctx *cmd.Context) error {
50 defer log.Printf("unit agent exiting")
51 defer a.tomb.Done() 51 defer a.tomb.Done()
52 for a.tomb.Err() == tomb.ErrStillAlive { 52 for a.tomb.Err() == tomb.ErrStillAlive {
53 » » unit, err := a.runOnce() 53 » » err := a.runOnce()
54 » » if ug, ok := err.(*UpgradedError); ok { 54 » » if ug, ok := err.(*UpgradeReadyError); ok {
55 » » » tools, err1 := environs.ChangeAgentTools(a.Conf.DataDir, unit.PathKey(), ug.Binary) 55 » » » if err = ug.ChangeAgentTools(); err == nil {
56 » » » if err1 == nil {
57 » » » » log.Printf("exiting to upgrade to %v from %q", t ools.Binary, tools.URL)
58 // Return and let upstart deal with the restart. 56 // Return and let upstart deal with the restart.
59 » » » » return nil 57 » » » » return ug
60 } 58 }
61 » » » err = err1 59 » » }
60 » » if err == nil {
61 » » » log.Printf("uniter: workers died with no error")
62 » » } else {
63 » » » log.Printf("uniter: %v", err)
62 } 64 }
63 select { 65 select {
64 case <-a.tomb.Dying(): 66 case <-a.tomb.Dying():
65 a.tomb.Kill(err) 67 a.tomb.Kill(err)
66 case <-time.After(retryDelay): 68 case <-time.After(retryDelay):
67 » » » log.Printf("rerunning uniter after error: %v", err) 69 » » » log.Printf("rerunning uniter")
68 } 70 }
69 } 71 }
70 return a.tomb.Err() 72 return a.tomb.Err()
71 } 73 }
72 74
73 // runOnce runs a uniter once. 75 // runOnce runs a uniter once.
74 func (a *UnitAgent) runOnce() (*state.Unit, error) { 76 func (a *UnitAgent) runOnce() error {
75 st, err := state.Open(&a.Conf.StateInfo) 77 st, err := state.Open(&a.Conf.StateInfo)
76 if err != nil { 78 if err != nil {
77 » » return nil, err 79 » » return err
78 } 80 }
79 defer st.Close() 81 defer st.Close()
80 unit, err := st.Unit(a.UnitName) 82 unit, err := st.Unit(a.UnitName)
81 if err != nil { 83 if err != nil {
82 » » return nil, err 84 » » return err
83 } 85 }
84 » return unit, runTasks(a.tomb.Dying(), 86 » return runTasks(a.tomb.Dying(),
85 uniter.NewUniter(st, unit.Name(), a.Conf.DataDir), 87 uniter.NewUniter(st, unit.Name(), a.Conf.DataDir),
86 NewUpgrader(st, unit, a.Conf.DataDir), 88 NewUpgrader(st, unit, a.Conf.DataDir),
87 ) 89 )
88 } 90 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b