Add Email-Forwarder watch container
This commit is contained in:
parent
88e82286d8
commit
ba53f8bb19
5 changed files with 36 additions and 10 deletions
|
|
@ -21,7 +21,10 @@ import (
|
|||
//
|
||||
// name = Konto-Name oder "all". watch = true -> Delta-Schleife bis Abbruch
|
||||
// (Cutover-Fenster), sonst einmaliger Durchlauf.
|
||||
func RunMigration(name string, watch bool) error {
|
||||
func RunMigration(name string, watch bool, interval time.Duration) error {
|
||||
if interval <= 0 {
|
||||
interval = 60 * time.Second
|
||||
}
|
||||
for {
|
||||
var accounts []Account
|
||||
var err error
|
||||
|
|
@ -32,21 +35,29 @@ func RunMigration(name string, watch bool) error {
|
|||
a, err = GetAccount(name)
|
||||
accounts = []Account{a}
|
||||
}
|
||||
if err != nil {
|
||||
if err != nil && !watch {
|
||||
return err
|
||||
}
|
||||
for _, a := range accounts {
|
||||
if !a.Active {
|
||||
continue
|
||||
}
|
||||
if err := migrateAccount(a); err != nil {
|
||||
return err
|
||||
if err != nil {
|
||||
log.Printf("watch load accounts failed: %v", err)
|
||||
} else {
|
||||
for _, a := range accounts {
|
||||
if !a.Active {
|
||||
continue
|
||||
}
|
||||
if err := migrateAccount(a); err != nil {
|
||||
if !watch {
|
||||
return err
|
||||
}
|
||||
log.Printf("watch migration failed for %s: %v", a.Name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
if !watch {
|
||||
return nil
|
||||
}
|
||||
time.Sleep(60 * time.Second)
|
||||
log.Printf("watch sleeping %s", interval)
|
||||
time.Sleep(interval)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ install -m0644 "$APP_DIR/Containerfile" "$APP_DIR/build/Containerfile"
|
|||
|
||||
podman build -t "$IMAGE_NAME" -f "$APP_DIR/build/Containerfile" "$APP_DIR/build"
|
||||
|
||||
podman rm -f "${WATCH_CONTAINER_NAME:-email-forwarder-watch}" >/dev/null 2>&1 || true
|
||||
podman rm -f "$CONTAINER_NAME" >/dev/null 2>&1 || true
|
||||
podman pod rm -f "$POD_NAME" >/dev/null 2>&1 || true
|
||||
podman pod create --name "$POD_NAME" --network "$NETWORK" -p "$HOST_BIND:$APP_PORT:$APP_PORT" >/dev/null
|
||||
|
|
@ -40,6 +41,14 @@ podman run -d --name "$CONTAINER_NAME" --pod "$POD_NAME" \
|
|||
-v "$APP_DIR/backup:/app/backup:Z" \
|
||||
"$IMAGE_NAME" >/dev/null
|
||||
|
||||
if [ -n "${WATCH_ACCOUNT:-}" ]; then
|
||||
podman run -d --name "${WATCH_CONTAINER_NAME:-email-forwarder-watch}" --pod "$POD_NAME" \
|
||||
--restart=unless-stopped \
|
||||
-v "$APP_DIR/data:/app/data:Z" \
|
||||
-v "$APP_DIR/backup:/app/backup:Z" \
|
||||
"$IMAGE_NAME" --run "$WATCH_ACCOUNT" --watch --watch-interval "${WATCH_INTERVAL:-60s}" >/dev/null
|
||||
fi
|
||||
|
||||
for _ in {1..20}; do
|
||||
if curl -fsS "http://$HOST_BIND:$APP_PORT/" >/dev/null 2>&1; then
|
||||
echo "Email-Forwarder reachable at http://$HOST_BIND:$APP_PORT/"
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ set -a
|
|||
source ./config.env
|
||||
set +a
|
||||
|
||||
podman rm -f "${WATCH_CONTAINER_NAME:-email-forwarder-watch}" >/dev/null 2>&1 || true
|
||||
podman rm -f "$CONTAINER_NAME" >/dev/null 2>&1 || true
|
||||
podman pod rm -f "$POD_NAME" >/dev/null 2>&1 || true
|
||||
echo "Runtime removed. Persistent data kept at $APP_DIR/data and $APP_DIR/backup"
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
SERVICE_NAME=Email-Forwarder
|
||||
POD_NAME=email-forwarder-pod
|
||||
CONTAINER_NAME=email-forwarder
|
||||
WATCH_CONTAINER_NAME=email-forwarder-watch
|
||||
IMAGE_NAME=localhost/email-forwarder:test
|
||||
NETWORK=base-net
|
||||
HOST_BIND=127.0.0.1
|
||||
APP_PORT=8087
|
||||
WATCH_ACCOUNT=codex-to-vdevop03
|
||||
WATCH_INTERVAL=60s
|
||||
BUILD_SRC=/mnt/DATA/Build/Email-Forwarder
|
||||
DEVOP_CONTAINER=DevOp-Pod-build
|
||||
APP_DIR=/mnt/DATA/Containers/Test-Container/Email-Forwarder-Pod
|
||||
|
|
|
|||
4
main.go
4
main.go
|
|
@ -7,6 +7,7 @@ import (
|
|||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"emailforwarder/backend"
|
||||
)
|
||||
|
|
@ -17,6 +18,7 @@ var frontend embed.FS
|
|||
func main() {
|
||||
runOnce := flag.String("run", "", "einen Umzugs-Job einmalig ausfuehren (Konto-Name oder 'all'), ohne Web-UI")
|
||||
watch := flag.Bool("watch", false, "Delta-Sync in Schleife bis Stop (Cutover-Fenster)")
|
||||
watchInterval := flag.Duration("watch-interval", 60*time.Second, "Pause zwischen Watch-Durchlaeufen")
|
||||
seedAccount := flag.String("seed-account", "", "Konto aus lokaler JSON-Datei in die DB schreiben (nur CLI/Test)")
|
||||
checkAccount := flag.String("check-account", "", "Konto-Logins pruefen und INBOX zaehlen, ohne zu kopieren")
|
||||
flag.Parse()
|
||||
|
|
@ -42,7 +44,7 @@ func main() {
|
|||
|
||||
// CLI-Modus: ohne Web laufen lassen (Cronjob / Cutover).
|
||||
if *runOnce != "" {
|
||||
must(backend.RunMigration(*runOnce, *watch))
|
||||
must(backend.RunMigration(*runOnce, *watch, *watchInterval))
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue