Skip to content

Commit

Permalink
skip port 25 check on Azure as well as GCE
Browse files Browse the repository at this point in the history
  • Loading branch information
HouzuoGuo committed Dec 23, 2017
1 parent 0be03c0 commit 359dd6c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion daemon/maintenance/maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (daemon *Daemon) runPortsCheck() error {
continue
}
for _, port := range ports {
if port == 25 && inet.IsGCE() {
if port == 25 && (inet.IsGCE() || inet.IsAzure()) {
daemon.logger.Info("runPortsCheck", "", nil, "because Google cloud forbids connection to port 25, port check will skip %s:25", host)
continue
}
Expand Down
18 changes: 18 additions & 0 deletions inet/ip.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package inet

import (
"io/ioutil"
"strings"
"sync"
"time"
Expand All @@ -12,6 +13,10 @@ var (
// isGCE is true only if IsGCE function has determined that the program is running on Google compute engine.
isGCE bool
isGCEOnce = new(sync.Once)

// isAzure is true only if IsAzure function has determined that the program is running on Microsoft Azure.
isAzure bool
isAzureOnce = new(sync.Once)
)

// IsGCE returns true only if the program is running on Google compute engine (or Google cloud platform, same thing).
Expand All @@ -28,6 +33,19 @@ func IsGCE() bool {
return isGCE
}

// IsAzure returns true only if the program is running on Microsoft Azure virtual machine.
func IsAzure() bool {
isAzureOnce.Do(func() {
content, err := ioutil.ReadFile("/var/lib/dhcp/dhclient.eth0.leases")
if err == nil {
if strings.Contains(string(content), "unknown-245") {
isAzure = true
}
}
})
return isAzure
}

/*
GetPublicIP returns the latest public IP address of the computer. If the IP address cannot be determined, it will return
an empty string. The function may take up to 3 seconds to return a value.
Expand Down

0 comments on commit 359dd6c

Please sign in to comment.