github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/upgrades/steps_24.go (about) 1 // Copyright 2017 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package upgrades 5 6 import ( 7 "os" 8 "path/filepath" 9 10 "github.com/juju/errors" 11 "github.com/juju/utils/series" 12 13 "github.com/juju/juju/service" 14 ) 15 16 // stateStepsFor24 returns upgrade steps for Juju 2.4.0 that manipulate state directly. 17 func stateStepsFor24() []Step { 18 return []Step{ 19 &upgradeStep{ 20 description: "move or drop the old audit log collection", 21 targets: []Target{DatabaseMaster}, 22 run: func(context Context) error { 23 return context.State().MoveOldAuditLog() 24 }, 25 }, 26 &upgradeStep{ 27 description: "move controller info Mongo space to controller config HA space if valid", 28 targets: []Target{DatabaseMaster}, 29 run: func(context Context) error { 30 return context.State().MoveMongoSpaceToHASpaceConfig() 31 }, 32 }, 33 &upgradeStep{ 34 description: "create empty application settings for all applications", 35 targets: []Target{DatabaseMaster}, 36 run: func(context Context) error { 37 return context.State().CreateMissingApplicationConfig() 38 }, 39 }, 40 &upgradeStep{ 41 description: "remove votingmachineids", 42 targets: []Target{DatabaseMaster}, 43 run: func(context Context) error { 44 return context.State().RemoveVotingMachineIds() 45 }, 46 }, 47 &upgradeStep{ 48 description: "add cloud model counts", 49 targets: []Target{DatabaseMaster}, 50 run: func(context Context) error { 51 return context.State().AddCloudModelCounts() 52 }, 53 }, 54 &upgradeStep{ 55 description: "bootstrap raft cluster", 56 targets: []Target{Controller}, 57 run: BootstrapRaft, 58 }, 59 } 60 } 61 62 // stepsFor24 returns upgrade steps for Juju 2.4. 63 func stepsFor24() []Step { 64 return []Step{ 65 &upgradeStep{ 66 description: "Install the service file in Standard location '/lib/systemd'", 67 targets: []Target{AllMachines}, 68 run: installServiceFile, 69 }, 70 } 71 } 72 73 // install the service files in Standard location - '/lib/systemd/system path. 74 func installServiceFile(context Context) error { 75 hostSeries, err := series.HostSeries() 76 if err == nil { 77 initName, err := service.VersionInitSystem(hostSeries) 78 if err != nil { 79 logger.Errorf("unsuccessful writing the service files in /lib/systemd/system path") 80 return err 81 } else { 82 if initName == service.InitSystemSystemd { 83 oldDataDir := context.AgentConfig().DataDir() 84 oldInitDataDir := filepath.Join(oldDataDir, "init") 85 86 sysdManager := service.NewServiceManagerWithDefaults() 87 err = sysdManager.WriteServiceFiles() 88 if err != nil { 89 logger.Errorf("unsuccessful writing the service files in /lib/systemd/system path") 90 return err 91 } 92 // Cleanup the old dir - /var/lib/init 93 return os.RemoveAll(oldInitDataDir) 94 } else { 95 logger.Infof("upgrade to systemd possible only for 'xenial' and above") 96 return nil 97 } 98 } 99 } else { 100 return errors.Trace(err) 101 } 102 }