1
0
Fork 0
mirror of synced 2024-12-19 04:41:05 -05:00

Fix Replication

Fixes issue when set to `slave` mode, also fix creation of subdirectories
from the assets received and fix probe port when waiting to slave process
to finish.
This commit is contained in:
Pmoranga 2023-04-19 19:00:46 -03:00
parent a973b88463
commit 213e1d7b0f
3 changed files with 22 additions and 10 deletions

View file

@ -288,6 +288,17 @@ func extractFromArchive(archive, path string) error {
log.Fatalf("extractFromArchive: Mkdir() failed: %s", err.Error()) log.Fatalf("extractFromArchive: Mkdir() failed: %s", err.Error())
} }
case tar.TypeReg: case tar.TypeReg:
s := strings.Split(header.Name, "/")
dir := ""
for len(s) > 1 {
dir, s = dir+"/"+s[0], s[1:]
if _, err := os.Stat(path + dir); os.IsNotExist(err) {
if err := os.Mkdir(path+dir, 0755); err != nil {
log.Fatalf("extractFromArchive: Mkdir() subdir failed: %s", err.Error())
}
}
}
outFile, err := os.Create(path + "/" + header.Name) outFile, err := os.Create(path + "/" + header.Name)
if err != nil { if err != nil {
log.Fatalf("extractFromArchive: Create() failed: %s", err.Error()) log.Fatalf("extractFromArchive: Create() failed: %s", err.Error())

19
main.go
View file

@ -9,11 +9,7 @@ import (
"encoding/pem" "encoding/pem"
"errors" "errors"
"fmt" "fmt"
"github.com/google/uuid"
"io/ioutil" "io/ioutil"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"net" "net"
"net/http" "net/http"
"os" "os"
@ -25,6 +21,11 @@ import (
"time" "time"
"unicode/utf8" "unicode/utf8"
"github.com/google/uuid"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"github.com/gobuffalo/packr/v2" "github.com/gobuffalo/packr/v2"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
@ -509,6 +510,11 @@ func main() {
ovpnAdmin.mgmtInterfaces[parts[0]] = parts[len(parts)-1] ovpnAdmin.mgmtInterfaces[parts[0]] = parts[len(parts)-1]
} }
if ovpnAdmin.role == "slave" {
ovpnAdmin.syncDataFromMaster()
go ovpnAdmin.syncWithMaster()
}
ovpnAdmin.mgmtSetTimeFormat() ovpnAdmin.mgmtSetTimeFormat()
ovpnAdmin.registerMetrics() ovpnAdmin.registerMetrics()
@ -536,11 +542,6 @@ func main() {
ovpnAdmin.modules = append(ovpnAdmin.modules, "ccd") ovpnAdmin.modules = append(ovpnAdmin.modules, "ccd")
} }
if ovpnAdmin.role == "slave" {
ovpnAdmin.syncDataFromMaster()
go ovpnAdmin.syncWithMaster()
}
ovpnAdmin.templates = packr.New("template", "./templates") ovpnAdmin.templates = packr.New("template", "./templates")
staticBox := packr.New("static", "./frontend/static") staticBox := packr.New("static", "./frontend/static")

View file

@ -15,7 +15,7 @@ if [ -e "$SERVER_CERT" ]; then
else else
if [ ${OVPN_ROLE:-"master"} = "slave" ]; then if [ ${OVPN_ROLE:-"master"} = "slave" ]; then
echo "Waiting for initial sync data from master" echo "Waiting for initial sync data from master"
while [ $(wget -q localhost/api/sync/last/try -O - | wc -m) -lt 1 ] while [ $(wget -q localhost:${OVPN_LISTEN_PORT:-8080}/api/sync/last/try -O - | wc -m) -lt 1 ]
do do
sleep 5 sleep 5
done done