Update
This commit is contained in:
BIN
deploy/bin/register-service
Executable file
BIN
deploy/bin/register-service
Executable file
Binary file not shown.
57
deploy/bin/register-service.go
Normal file
57
deploy/bin/register-service.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
addr, port := env("API_REGISTRY_ADDR", "api-registry"), env("API_REGISTRY_PORT", "8501")
|
||||
regUrl := "https://" + addr + ":" + port + "/v1/agent/service/register?replace-existing-checks=true"
|
||||
regData, err := os.ReadFile("/.app.config")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
ip := getIP()
|
||||
strRegData := string(regData)
|
||||
strRegData = strings.Replace(strRegData, "__IP__", ip, -1)
|
||||
|
||||
req, err := http.NewRequest(http.MethodPut, regUrl, strings.NewReader(strRegData))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
log.Printf(err.Error())
|
||||
log.Fatal(err)
|
||||
}
|
||||
var respBody []byte
|
||||
resp.Body.Read(respBody)
|
||||
|
||||
log.Printf("Successfully registered")
|
||||
}
|
||||
|
||||
func env(name, def string) string {
|
||||
val := os.Getenv(name)
|
||||
|
||||
if len(val) == 0 {
|
||||
return def
|
||||
}
|
||||
|
||||
return val
|
||||
}
|
||||
|
||||
func getIP() string {
|
||||
host, _ := os.Hostname()
|
||||
ips, _ := net.LookupIP(host)
|
||||
for _, ip := range ips {
|
||||
return ip.String()
|
||||
}
|
||||
|
||||
return host
|
||||
}
|
||||
9
deploy/bin/update-resolv.sh
Executable file
9
deploy/bin/update-resolv.sh
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# modify /etc/resolv.conf
|
||||
registryIP=$(nslookup -type=A api-registry. | awk '/^Name:/ {c=2;N=$2} !--c {print N,$2}' | awk '{printf "%s", $2}')
|
||||
resolvFile=$(cat /etc/resolv.conf)
|
||||
|
||||
echo -e "nameserver $registryIP" >>/etc/resolv.conf
|
||||
# echo "$registryIP registry.service.ego.io" >> /etc/hosts # Add consul host with static IP (consul register itself as 127.0.0.1)
|
||||
# nslookup api-registry
|
||||
Reference in New Issue
Block a user