mirror of https://github.com/docker/docs.git
separate pkgaction into 'pkgaction' and 'serviceaction'
ignored IntellJ IDEA files Signed-off-by: Xiaohui Liu <xiaohui.liu@ucloud.cn>
This commit is contained in:
parent
993b5f557f
commit
102007b231
|
@ -1,2 +1,4 @@
|
||||||
docker-machine*
|
docker-machine*
|
||||||
*.log
|
*.log
|
||||||
|
*.iml
|
||||||
|
.idea/
|
||||||
|
|
|
@ -15,6 +15,7 @@ import (
|
||||||
"github.com/docker/machine/libmachine/engine"
|
"github.com/docker/machine/libmachine/engine"
|
||||||
"github.com/docker/machine/libmachine/provision"
|
"github.com/docker/machine/libmachine/provision"
|
||||||
"github.com/docker/machine/libmachine/provision/pkgaction"
|
"github.com/docker/machine/libmachine/provision/pkgaction"
|
||||||
|
"github.com/docker/machine/libmachine/provision/serviceaction"
|
||||||
"github.com/docker/machine/libmachine/swarm"
|
"github.com/docker/machine/libmachine/swarm"
|
||||||
"github.com/docker/machine/log"
|
"github.com/docker/machine/log"
|
||||||
"github.com/docker/machine/ssh"
|
"github.com/docker/machine/ssh"
|
||||||
|
@ -244,7 +245,7 @@ func (h *Host) Upgrade() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := provisioner.Service("docker", pkgaction.Restart); err != nil {
|
if err := provisioner.Service("docker", serviceaction.Restart); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/docker/machine/libmachine/auth"
|
"github.com/docker/machine/libmachine/auth"
|
||||||
"github.com/docker/machine/libmachine/engine"
|
"github.com/docker/machine/libmachine/engine"
|
||||||
"github.com/docker/machine/libmachine/provision/pkgaction"
|
"github.com/docker/machine/libmachine/provision/pkgaction"
|
||||||
|
"github.com/docker/machine/libmachine/provision/serviceaction"
|
||||||
"github.com/docker/machine/libmachine/swarm"
|
"github.com/docker/machine/libmachine/swarm"
|
||||||
"github.com/docker/machine/log"
|
"github.com/docker/machine/log"
|
||||||
"github.com/docker/machine/state"
|
"github.com/docker/machine/state"
|
||||||
|
@ -36,7 +37,7 @@ type Boot2DockerProvisioner struct {
|
||||||
SwarmOptions swarm.SwarmOptions
|
SwarmOptions swarm.SwarmOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
func (provisioner *Boot2DockerProvisioner) Service(name string, action pkgaction.ServiceAction) error {
|
func (provisioner *Boot2DockerProvisioner) Service(name string, action serviceaction.ServiceAction) error {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/docker/machine/libmachine/auth"
|
"github.com/docker/machine/libmachine/auth"
|
||||||
"github.com/docker/machine/libmachine/engine"
|
"github.com/docker/machine/libmachine/engine"
|
||||||
"github.com/docker/machine/libmachine/provision/pkgaction"
|
"github.com/docker/machine/libmachine/provision/pkgaction"
|
||||||
|
"github.com/docker/machine/libmachine/provision/serviceaction"
|
||||||
"github.com/docker/machine/libmachine/swarm"
|
"github.com/docker/machine/libmachine/swarm"
|
||||||
"github.com/docker/machine/log"
|
"github.com/docker/machine/log"
|
||||||
"github.com/docker/machine/utils"
|
"github.com/docker/machine/utils"
|
||||||
|
@ -44,7 +45,7 @@ type CoreOSProvisioner struct {
|
||||||
GenericProvisioner
|
GenericProvisioner
|
||||||
}
|
}
|
||||||
|
|
||||||
func (provisioner *CoreOSProvisioner) Service(name string, action pkgaction.ServiceAction) error {
|
func (provisioner *CoreOSProvisioner) Service(name string, action serviceaction.ServiceAction) error {
|
||||||
// daemon-reload to catch config updates; systemd -- ugh
|
// daemon-reload to catch config updates; systemd -- ugh
|
||||||
if _, err := provisioner.SSHCommand("sudo systemctl daemon-reload"); err != nil {
|
if _, err := provisioner.SSHCommand("sudo systemctl daemon-reload"); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/docker/machine/libmachine/auth"
|
"github.com/docker/machine/libmachine/auth"
|
||||||
"github.com/docker/machine/libmachine/engine"
|
"github.com/docker/machine/libmachine/engine"
|
||||||
"github.com/docker/machine/libmachine/provision/pkgaction"
|
"github.com/docker/machine/libmachine/provision/pkgaction"
|
||||||
|
"github.com/docker/machine/libmachine/provision/serviceaction"
|
||||||
"github.com/docker/machine/libmachine/swarm"
|
"github.com/docker/machine/libmachine/swarm"
|
||||||
"github.com/docker/machine/log"
|
"github.com/docker/machine/log"
|
||||||
"github.com/docker/machine/utils"
|
"github.com/docker/machine/utils"
|
||||||
|
@ -38,7 +39,7 @@ type DebianProvisioner struct {
|
||||||
GenericProvisioner
|
GenericProvisioner
|
||||||
}
|
}
|
||||||
|
|
||||||
func (provisioner *DebianProvisioner) Service(name string, action pkgaction.ServiceAction) error {
|
func (provisioner *DebianProvisioner) Service(name string, action serviceaction.ServiceAction) error {
|
||||||
// daemon-reload to catch config updates; systemd -- ugh
|
// daemon-reload to catch config updates; systemd -- ugh
|
||||||
if _, err := provisioner.SSHCommand("sudo systemctl daemon-reload"); err != nil {
|
if _, err := provisioner.SSHCommand("sudo systemctl daemon-reload"); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -171,7 +172,7 @@ func (provisioner *DebianProvisioner) Provision(swarmOptions swarm.SwarmOptions,
|
||||||
|
|
||||||
// enable in systemd
|
// enable in systemd
|
||||||
log.Debug("enabling docker in systemd")
|
log.Debug("enabling docker in systemd")
|
||||||
if err := provisioner.Service("docker", pkgaction.Enable); err != nil {
|
if err := provisioner.Service("docker", serviceaction.Enable); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package pkgaction
|
||||||
|
|
||||||
|
type PackageAction int
|
||||||
|
|
||||||
|
const (
|
||||||
|
Install PackageAction = iota
|
||||||
|
Remove
|
||||||
|
Upgrade
|
||||||
|
)
|
||||||
|
|
||||||
|
var packageActions = []string{
|
||||||
|
"install",
|
||||||
|
"remove",
|
||||||
|
"upgrade",
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s PackageAction) String() string {
|
||||||
|
if int(s) >= 0 && int(s) < len(packageActions) {
|
||||||
|
return packageActions[s]
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"github.com/docker/machine/libmachine/auth"
|
"github.com/docker/machine/libmachine/auth"
|
||||||
"github.com/docker/machine/libmachine/engine"
|
"github.com/docker/machine/libmachine/engine"
|
||||||
"github.com/docker/machine/libmachine/provision/pkgaction"
|
"github.com/docker/machine/libmachine/provision/pkgaction"
|
||||||
|
"github.com/docker/machine/libmachine/provision/serviceaction"
|
||||||
"github.com/docker/machine/libmachine/swarm"
|
"github.com/docker/machine/libmachine/swarm"
|
||||||
"github.com/docker/machine/log"
|
"github.com/docker/machine/log"
|
||||||
)
|
)
|
||||||
|
@ -45,7 +46,7 @@ type Provisioner interface {
|
||||||
Provision(swarmOptions swarm.SwarmOptions, authOptions auth.AuthOptions, engineOptions engine.EngineOptions) error
|
Provision(swarmOptions swarm.SwarmOptions, authOptions auth.AuthOptions, engineOptions engine.EngineOptions) error
|
||||||
|
|
||||||
// Perform action on a named service e.g. stop
|
// Perform action on a named service e.g. stop
|
||||||
Service(name string, action pkgaction.ServiceAction) error
|
Service(name string, action serviceaction.ServiceAction) error
|
||||||
|
|
||||||
// Get the driver which is contained in the provisioner.
|
// Get the driver which is contained in the provisioner.
|
||||||
GetDriver() drivers.Driver
|
GetDriver() drivers.Driver
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/docker/machine/libmachine/auth"
|
"github.com/docker/machine/libmachine/auth"
|
||||||
"github.com/docker/machine/libmachine/engine"
|
"github.com/docker/machine/libmachine/engine"
|
||||||
"github.com/docker/machine/libmachine/provision/pkgaction"
|
"github.com/docker/machine/libmachine/provision/pkgaction"
|
||||||
|
"github.com/docker/machine/libmachine/provision/serviceaction"
|
||||||
"github.com/docker/machine/libmachine/swarm"
|
"github.com/docker/machine/libmachine/swarm"
|
||||||
"github.com/docker/machine/log"
|
"github.com/docker/machine/log"
|
||||||
"github.com/docker/machine/state"
|
"github.com/docker/machine/state"
|
||||||
|
@ -49,7 +50,7 @@ type RancherProvisioner struct {
|
||||||
GenericProvisioner
|
GenericProvisioner
|
||||||
}
|
}
|
||||||
|
|
||||||
func (provisioner *RancherProvisioner) Service(name string, action pkgaction.ServiceAction) error {
|
func (provisioner *RancherProvisioner) Service(name string, action serviceaction.ServiceAction) error {
|
||||||
command := fmt.Sprintf("sudo system-docker %s %s", action.String(), name)
|
command := fmt.Sprintf("sudo system-docker %s %s", action.String(), name)
|
||||||
|
|
||||||
if _, err := provisioner.SSHCommand(command); err != nil {
|
if _, err := provisioner.SSHCommand(command); err != nil {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/docker/machine/libmachine/auth"
|
"github.com/docker/machine/libmachine/auth"
|
||||||
"github.com/docker/machine/libmachine/engine"
|
"github.com/docker/machine/libmachine/engine"
|
||||||
"github.com/docker/machine/libmachine/provision/pkgaction"
|
"github.com/docker/machine/libmachine/provision/pkgaction"
|
||||||
|
"github.com/docker/machine/libmachine/provision/serviceaction"
|
||||||
"github.com/docker/machine/libmachine/swarm"
|
"github.com/docker/machine/libmachine/swarm"
|
||||||
"github.com/docker/machine/log"
|
"github.com/docker/machine/log"
|
||||||
"github.com/docker/machine/ssh"
|
"github.com/docker/machine/ssh"
|
||||||
|
@ -107,10 +108,10 @@ func (provisioner *RedHatProvisioner) SetHostname(hostname string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (provisioner *RedHatProvisioner) Service(name string, action pkgaction.ServiceAction) error {
|
func (provisioner *RedHatProvisioner) Service(name string, action serviceaction.ServiceAction) error {
|
||||||
reloadDaemon := false
|
reloadDaemon := false
|
||||||
switch action {
|
switch action {
|
||||||
case pkgaction.Start, pkgaction.Restart:
|
case serviceaction.Start, serviceaction.Restart:
|
||||||
reloadDaemon = true
|
reloadDaemon = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,11 +159,11 @@ func installDocker(provisioner *RedHatProvisioner) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := provisioner.Service("docker", pkgaction.Restart); err != nil {
|
if err := provisioner.Service("docker", serviceaction.Restart); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := provisioner.Service("docker", pkgaction.Enable); err != nil {
|
if err := provisioner.Service("docker", serviceaction.Enable); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package pkgaction
|
package serviceaction
|
||||||
|
|
||||||
type ServiceAction int
|
type ServiceAction int
|
||||||
|
|
||||||
|
@ -27,25 +27,3 @@ func (s ServiceAction) String() string {
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
type PackageAction int
|
|
||||||
|
|
||||||
const (
|
|
||||||
Install PackageAction = iota
|
|
||||||
Remove
|
|
||||||
Upgrade
|
|
||||||
)
|
|
||||||
|
|
||||||
var packageActions = []string{
|
|
||||||
"install",
|
|
||||||
"remove",
|
|
||||||
"upgrade",
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s PackageAction) String() string {
|
|
||||||
if int(s) >= 0 && int(s) < len(packageActions) {
|
|
||||||
return packageActions[s]
|
|
||||||
}
|
|
||||||
|
|
||||||
return ""
|
|
||||||
}
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
package serviceaction
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestActionValue(t *testing.T) {
|
||||||
|
if Restart.String() != "restart" {
|
||||||
|
t.Fatal("Expected %q but got %q", "install", Restart.String())
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"github.com/docker/machine/libmachine/auth"
|
"github.com/docker/machine/libmachine/auth"
|
||||||
"github.com/docker/machine/libmachine/engine"
|
"github.com/docker/machine/libmachine/engine"
|
||||||
"github.com/docker/machine/libmachine/provision/pkgaction"
|
"github.com/docker/machine/libmachine/provision/pkgaction"
|
||||||
|
"github.com/docker/machine/libmachine/provision/serviceaction"
|
||||||
"github.com/docker/machine/libmachine/swarm"
|
"github.com/docker/machine/libmachine/swarm"
|
||||||
"github.com/docker/machine/log"
|
"github.com/docker/machine/log"
|
||||||
"github.com/docker/machine/utils"
|
"github.com/docker/machine/utils"
|
||||||
|
@ -36,7 +37,7 @@ type UbuntuProvisioner struct {
|
||||||
GenericProvisioner
|
GenericProvisioner
|
||||||
}
|
}
|
||||||
|
|
||||||
func (provisioner *UbuntuProvisioner) Service(name string, action pkgaction.ServiceAction) error {
|
func (provisioner *UbuntuProvisioner) Service(name string, action serviceaction.ServiceAction) error {
|
||||||
command := fmt.Sprintf("sudo service %s %s", name, action.String())
|
command := fmt.Sprintf("sudo service %s %s", name, action.String())
|
||||||
|
|
||||||
if _, err := provisioner.SSHCommand(command); err != nil {
|
if _, err := provisioner.SSHCommand(command); err != nil {
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/machine/libmachine/auth"
|
"github.com/docker/machine/libmachine/auth"
|
||||||
"github.com/docker/machine/libmachine/provision/pkgaction"
|
"github.com/docker/machine/libmachine/provision/serviceaction"
|
||||||
"github.com/docker/machine/log"
|
"github.com/docker/machine/log"
|
||||||
"github.com/docker/machine/utils"
|
"github.com/docker/machine/utils"
|
||||||
)
|
)
|
||||||
|
@ -105,7 +105,7 @@ func ConfigureAuth(p Provisioner) error {
|
||||||
return fmt.Errorf("error generating server cert: %s", err)
|
return fmt.Errorf("error generating server cert: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := p.Service("docker", pkgaction.Stop); err != nil {
|
if err := p.Service("docker", serviceaction.Stop); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ func ConfigureAuth(p Provisioner) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := p.Service("docker", pkgaction.Start); err != nil {
|
if err := p.Service("docker", serviceaction.Start); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue