This repository has been archived by the owner on Mar 22, 2021. It is now read-only.
forked from docker/machine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ubuntu_upstart.go
158 lines (125 loc) · 4.01 KB
/
ubuntu_upstart.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package provision
import (
"fmt"
"strconv"
"github.com/docker/machine/libmachine/auth"
"github.com/docker/machine/libmachine/drivers"
"github.com/docker/machine/libmachine/engine"
"github.com/docker/machine/libmachine/log"
"github.com/docker/machine/libmachine/mcnutils"
"github.com/docker/machine/libmachine/provision/pkgaction"
"github.com/docker/machine/libmachine/provision/serviceaction"
"github.com/docker/machine/libmachine/swarm"
)
func init() {
Register("Ubuntu-UpStart", &RegisteredProvisioner{
New: NewUbuntuProvisioner,
})
}
func NewUbuntuProvisioner(d drivers.Driver) Provisioner {
return &UbuntuProvisioner{
GenericProvisioner{
SSHCommander: GenericSSHCommander{Driver: d},
DockerOptionsDir: "/etc/docker",
DaemonOptionsFile: "/etc/default/docker",
OsReleaseID: "ubuntu",
Packages: []string{
"curl",
},
Driver: d,
},
}
}
type UbuntuProvisioner struct {
GenericProvisioner
}
func (provisioner *UbuntuProvisioner) String() string {
return "ubuntu(upstart)"
}
func (provisioner *UbuntuProvisioner) CompatibleWithHost() bool {
const FirstUbuntuSystemdVersion = 15.04
isUbuntu := provisioner.OsReleaseInfo.ID == provisioner.OsReleaseID
if !isUbuntu {
return false
}
versionNumber, err := strconv.ParseFloat(provisioner.OsReleaseInfo.VersionID, 64)
if err != nil {
return false
}
return versionNumber < FirstUbuntuSystemdVersion
}
func (provisioner *UbuntuProvisioner) Service(name string, action serviceaction.ServiceAction) error {
command := fmt.Sprintf("sudo service %s %s", name, action.String())
if _, err := provisioner.SSHCommand(command); err != nil {
return err
}
return nil
}
func (provisioner *UbuntuProvisioner) Package(name string, action pkgaction.PackageAction) error {
var packageAction string
updateMetadata := true
switch action {
case pkgaction.Install, pkgaction.Upgrade:
packageAction = "install"
case pkgaction.Remove, pkgaction.Purge:
packageAction = "remove"
updateMetadata = false
}
switch name {
case "docker":
name = "docker-engine"
}
if updateMetadata {
if err := waitForLockAptGetUpdate(provisioner); err != nil {
return err
}
}
command := fmt.Sprintf("DEBIAN_FRONTEND=noninteractive sudo -E apt-get %s -y -o Dpkg::Options::=\"--force-confnew\" %s", packageAction, name)
log.Debugf("package: action=%s name=%s", action.String(), name)
return waitForLock(provisioner, command)
}
func (provisioner *UbuntuProvisioner) dockerDaemonResponding() bool {
log.Debug("checking docker daemon")
if out, err := provisioner.SSHCommand("sudo docker version"); err != nil {
log.Warnf("Error getting SSH command to check if the daemon is up: %s", err)
log.Debugf("'sudo docker version' output:\n%s", out)
return false
}
// The daemon is up if the command worked. Carry on.
return true
}
func (provisioner *UbuntuProvisioner) Provision(swarmOptions swarm.Options, authOptions auth.Options, engineOptions engine.Options) error {
provisioner.SwarmOptions = swarmOptions
provisioner.AuthOptions = authOptions
provisioner.EngineOptions = engineOptions
swarmOptions.Env = engineOptions.Env
storageDriver, err := decideStorageDriver(provisioner, "overlay2", engineOptions.StorageDriver)
if err != nil {
return err
}
provisioner.EngineOptions.StorageDriver = storageDriver
if err := provisioner.SetHostname(provisioner.Driver.GetMachineName()); err != nil {
return err
}
for _, pkg := range provisioner.Packages {
if err := provisioner.Package(pkg, pkgaction.Install); err != nil {
return err
}
}
log.Info("Installing Docker...")
if err := installDockerGeneric(provisioner, engineOptions.InstallURL); err != nil {
return err
}
if err := mcnutils.WaitFor(provisioner.dockerDaemonResponding); err != nil {
return err
}
if err := makeDockerOptionsDir(provisioner); err != nil {
return err
}
provisioner.AuthOptions = setRemoteAuthOptions(provisioner)
if err := ConfigureAuth(provisioner); err != nil {
return err
}
err = configureSwarm(provisioner, swarmOptions, provisioner.AuthOptions)
return err
}