diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0a996453f..d7129f87a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -241,10 +241,10 @@ jobs: - name: PostgreSQL inbound migration contention run: | set -o pipefail - go test ./internal/web/service -run '^TestMigrationRequirementsRejectsLiveNodeMergePostgres$' -count=1 -v | tee /tmp/postgres-inbound-migration.log + go test -p=1 ./internal/database ./internal/web/service -run '^(TestInitDBKeepsRestorePoolPrivate|TestMigrationRequirementsRejectsLiveNodeMergePostgres|TestInboundMigrationAllowsPostgresReaders)$' -count=1 -v | tee /tmp/postgres-inbound-migration.log passed=$(grep -c -- '^--- PASS' /tmp/postgres-inbound-migration.log || true) - if [ "$passed" -ne 1 ]; then - echo "expected the PostgreSQL inbound migration contention test to pass, got $passed" >&2 + if [ "$passed" -ne 3 ]; then + echo "expected 3 passing PostgreSQL inbound migration and restore tests, got $passed" >&2 exit 1 fi diff --git a/internal/database/db.go b/internal/database/db.go index f5f530211..9f264298c 100644 --- a/internal/database/db.go +++ b/internal/database/db.go @@ -38,6 +38,7 @@ import ( ) var db *gorm.DB +var publishedDB atomic.Pointer[gorm.DB] var connectionGeneration atomic.Uint64 @@ -52,13 +53,11 @@ const ( ) func IsPostgres() bool { - if db == nil { - return config.GetDBKind() == "postgres" - } - return db.Name() == "postgres" + return config.GetDBKind() == DialectPostgres } func Dialect() string { + db := GetDB() if db == nil { return "" } @@ -3483,6 +3482,13 @@ func isTableEmpty(tableName string) (bool, error) { } func InitDB(dbPath string) error { + return InitDBBeforePublish(dbPath, nil) +} + +// InitDBBeforePublish initializes a replacement pool and runs finish before +// making it visible to requests and jobs. If finish fails, the initialized +// pool is still published so the panel can report the error and recover. +func InitDBBeforePublish(dbPath string, finish func(*gorm.DB) error) error { var gormLogger logger.Interface if config.IsDebug() { gormLogger = logger.New( @@ -3588,8 +3594,13 @@ func InitDB(dbPath string) error { if err := runSeeders(isUsersEmpty); err != nil { return err } + var finishErr error + if finish != nil { + finishErr = finish(db) + } + publishedDB.Store(db) connectionGeneration.Add(1) - return nil + return finishErr } func normalizeApiTokenCreatedAtSeconds() error { @@ -3721,7 +3732,7 @@ func CloseDB() error { } func GetDB() *gorm.DB { - return db + return publishedDB.Load() } func IsNotFound(err error) bool { diff --git a/internal/database/db_reopen_test.go b/internal/database/db_reopen_test.go index c3c856161..ccec56542 100644 --- a/internal/database/db_reopen_test.go +++ b/internal/database/db_reopen_test.go @@ -1,8 +1,12 @@ package database import ( + "database/sql" + "errors" "path/filepath" "testing" + + "gorm.io/gorm" ) // A replaced pool that stays open keeps its database file open; Windows then @@ -25,3 +29,28 @@ func TestInitDBClosesThePoolItReplaces(t *testing.T) { t.Fatalf("replaced pool Ping() = %v, want sql: database is closed", err) } } + +func TestInitDBKeepsRestorePoolPrivate(t *testing.T) { + initMigrateDB(t) + previous := GetDB() + dbPath := filepath.Join(t.TempDir(), "restored.db") + finishErr := errors.New("restore migration failed") + var replacement *gorm.DB + err := InitDBBeforePublish(dbPath, func(db *gorm.DB) error { + replacement = db + if GetDB() != previous || db == previous { + t.Fatal("the replacement pool was visible during restore migration") + } + if err := GetDB().Exec("SELECT 1").Error; !errors.Is(err, sql.ErrConnDone) && + (err == nil || err.Error() != "sql: database is closed") { + t.Fatalf("request could still use the old pool: %v", err) + } + if err := db.Exec("SELECT 1").Error; err != nil { + t.Fatalf("restore could not use the replacement pool: %v", err) + } + return finishErr + }) + if !errors.Is(err, finishErr) || GetDB() != replacement { + t.Fatalf("restore failure was not surfaced with a usable pool: %v", err) + } +} diff --git a/internal/web/service/inbound_migration.go b/internal/web/service/inbound_migration.go index 8facfeb7a..5fa9671a5 100644 --- a/internal/web/service/inbound_migration.go +++ b/internal/web/service/inbound_migration.go @@ -39,21 +39,14 @@ func removeOrphanedMigrationTraffics(db *gorm.DB) error { return nil } -func runInboundMigration(migrate func(*gorm.DB) error) error { - db := database.GetDB() +var errInboundMigrationBusy = errors.New("database is busy; retry the inbound migration after active database work has stopped") + +func runInboundMigration(db *gorm.DB, repairSchema bool, migrate func(*gorm.DB) error) error { started := time.Now() err := db.Transaction(func(tx *gorm.DB) error { if tx.Name() == database.DialectPostgres { - // Take maintenance locks before touching any of these tables. NOWAIT - // also protects against writers in another process or an older panel. - err := tx.Exec(`LOCK TABLE inbounds, client_traffics, clients, client_inbounds, client_groups, - nodes, api_tokens, outbound_subscriptions IN ACCESS EXCLUSIVE MODE NOWAIT`).Error - if err != nil { - var pgErr *pgconn.PgError - if errors.As(err, &pgErr) && pgErr.Code == "55P03" { - return fmt.Errorf("database is busy; retry the inbound migration after active database work has stopped: %w", err) - } - return fmt.Errorf("lock inbound migration tables: %w", err) + if err := preparePostgresInboundMigration(tx, repairSchema); err != nil { + return err } } return migrate(tx) @@ -67,17 +60,77 @@ func runInboundMigration(migrate func(*gorm.DB) error) error { return err } +func lockInboundMigrationTables(tx *gorm.DB, tables, mode string) error { + err := tx.Exec("LOCK TABLE " + tables + " IN " + mode + " MODE NOWAIT").Error + var pgErr *pgconn.PgError + if errors.As(err, &pgErr) && pgErr.Code == "55P03" { + return fmt.Errorf("%w: %w", errInboundMigrationBusy, err) + } + if err != nil { + return fmt.Errorf("lock inbound migration tables: %w", err) + } + return nil +} + +func preparePostgresInboundMigration(tx *gorm.DB, repairSchema bool) error { + // EXCLUSIVE admits plain SELECTs and excludes writes and SELECT FOR UPDATE. + // Acquire the complete write set before DDL or DML, without waiting behind a live writer. + if err := lockInboundMigrationTables(tx, "inbounds, client_traffics, clients, client_inbounds, client_groups", "EXCLUSIVE"); err != nil || !repairSchema { + return err + } + + var changes []struct{ TableName, ColumnName string } + if err := tx.Raw(` + SELECT legacy.table_name, legacy.column_name + FROM (VALUES + ('inbounds', 'all_time'), ('client_traffics', 'all_time'), + ('inbounds', 'enable'), ('client_traffics', 'enable'), + ('clients', 'enable'), ('nodes', 'enable'), + ('api_tokens', 'enabled'), ('outbound_subscriptions', 'enabled') + ) AS legacy(table_name, column_name) + JOIN pg_catalog.pg_attribute AS a + ON a.attrelid = pg_catalog.to_regclass(legacy.table_name) + AND a.attname = legacy.column_name AND a.attnum > 0 AND NOT a.attisdropped + WHERE legacy.column_name = 'all_time' OR a.atttypid <> 'pg_catalog.bool'::regtype + ORDER BY legacy.table_name, legacy.column_name`).Scan(&changes).Error; err != nil { + return fmt.Errorf("inspect legacy inbound migration columns: %w", err) + } + var tables []string + for _, change := range changes { + if len(tables) == 0 || tables[len(tables)-1] != change.TableName { + tables = append(tables, change.TableName) + } + } + if len(tables) > 0 { + // ALTER TABLE needs ACCESS EXCLUSIVE, but upgraded schemas need no DDL. + if err := lockInboundMigrationTables(tx, strings.Join(tables, ", "), "ACCESS EXCLUSIVE"); err != nil { + return err + } + } + for _, change := range changes { + table, col := change.TableName, change.ColumnName + stmt := fmt.Sprintf("ALTER TABLE %s DROP COLUMN %s", table, col) + if col != "all_time" { + stmt = fmt.Sprintf("ALTER TABLE %s ALTER COLUMN %s TYPE boolean USING (CASE WHEN %s::text IN ('1','true','t','yes') THEN true ELSE false END)", table, col, col) + } + if err := tx.Exec(stmt).Error; err != nil { + return fmt.Errorf("normalize legacy column %s.%s: %w", table, col, err) + } + } + return nil +} + func (s *InboundService) MigrationRequirements() error { - return runInboundMigration(s.migrationRequirements) + return runInboundMigration(database.GetDB(), true, s.migrationRequirements) } func (s *InboundService) migrationRequirements(tx *gorm.DB) (err error) { - if tx.Migrator().HasColumn(&model.Inbound{}, "all_time") { + if tx.Name() == database.DialectSQLite && tx.Migrator().HasColumn(&model.Inbound{}, "all_time") { if err = tx.Migrator().DropColumn(&model.Inbound{}, "all_time"); err != nil { return } } - if tx.Migrator().HasColumn(&xray.ClientTraffic{}, "all_time") { + if tx.Name() == database.DialectSQLite && tx.Migrator().HasColumn(&xray.ClientTraffic{}, "all_time") { if err = tx.Migrator().DropColumn(&xray.ClientTraffic{}, "all_time"); err != nil { return } @@ -86,39 +139,6 @@ func (s *InboundService) migrationRequirements(tx *gorm.DB) (err error) { return } - // Normalize "enable" columns to boolean on Postgres. Legacy SQLite data - // (0/1 integers), partial migrations, or mixed write paths (public API - // inbound updates that flow through UpdateClientStat + client syncs, plus - // node traffic merge deltas) can leave the column as integer or with mixed - // interpretation. This (combined with the dialect-aware - // ClientTrafficEnableMergeExpr) prevents type problems in the node traffic - // sync merge (SetRemoteTraffic) and makes the sync robust even when - // inbounds are updated via the public API (incl. ones carrying - // externalProxy in streamSettings). The same expression is also safe on - // SQLite (no PG :: casts). - if database.IsPostgres() { - // Use DO block so it is idempotent and doesn't fail if already boolean. - normalizeBool := func(table, col string) error { - return tx.Exec(fmt.Sprintf(` - DO $$ - BEGIN - IF EXISTS ( - SELECT 1 FROM information_schema.columns - WHERE table_name = '%s' AND column_name = '%s' - AND data_type <> 'boolean' - ) THEN - ALTER TABLE %s ALTER COLUMN %s - TYPE boolean USING (CASE WHEN %s::text IN ('1','true','t','yes') THEN true ELSE false END); - END IF; - END $$;`, table, col, table, col, col)).Error - } - for _, column := range [][2]string{{"inbounds", "enable"}, {"client_traffics", "enable"}, {"nodes", "enable"}, {"clients", "enable"}, {"api_tokens", "enabled"}, {"outbound_subscriptions", "enabled"}} { - if err = normalizeBool(column[0], column[1]); err != nil { - return - } - } - } - // Fix inbounds based problems var inbounds []*model.Inbound err = tx.Model(model.Inbound{}).Where("protocol IN (?)", []string{"vmess", "vless", "trojan", "shadowsocks", "hysteria"}).Find(&inbounds).Error @@ -307,7 +327,11 @@ func (s *InboundService) migrationRequirements(tx *gorm.DB) (err error) { } func (s *InboundService) MigrateDB() error { - return runInboundMigration(func(tx *gorm.DB) error { + return s.migrateDB(database.GetDB()) +} + +func (s *InboundService) migrateDB(db *gorm.DB) error { + return runInboundMigration(db, true, func(tx *gorm.DB) error { if err := s.migrationRequirements(tx); err != nil { return fmt.Errorf("inbound migration requirements: %w", err) } @@ -326,7 +350,7 @@ func (s *InboundService) MigrateDB() error { // Vision. Idempotent: once a client carries the flow it is skipped, so this is a // no-op on healthy installs and on subsequent boots. func (s *InboundService) MigrationRestoreVisionFlow() { - if err := runInboundMigration(s.migrationRestoreVisionFlow); err != nil { + if err := runInboundMigration(database.GetDB(), false, s.migrationRestoreVisionFlow); err != nil { logger.Warning("MigrationRestoreVisionFlow failed:", err) } } diff --git a/internal/web/service/inbound_migration_contention_test.go b/internal/web/service/inbound_migration_contention_test.go index be66e2fd6..f2039bbbd 100644 --- a/internal/web/service/inbound_migration_contention_test.go +++ b/internal/web/service/inbound_migration_contention_test.go @@ -1,6 +1,7 @@ package service import ( + "context" "errors" "fmt" "path/filepath" @@ -19,6 +20,57 @@ import ( "github.com/mhsanaei/3x-ui/v3/internal/xray" ) +func TestInboundMigrationAllowsPostgresReaders(t *testing.T) { + if config.GetDBKind() != database.DialectPostgres { + t.Skip("requires PostgreSQL table locks") + } + db := initNodeSnapshotDB(t, filepath.Join(t.TempDir(), "migration-reader.db")) + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + reader := db.WithContext(ctx).Begin() + if reader.Error != nil { + t.Fatal(reader.Error) + } + defer reader.Rollback() + if err := reader.Exec("SELECT id FROM inbounds").Error; err != nil { + t.Fatal(err) + } + + if err := runInboundMigration(db, true, func(tx *gorm.DB) error { + if err := db.WithContext(ctx).Exec("SELECT id FROM inbounds").Error; err != nil { + return fmt.Errorf("reader during migration: %w", err) + } + return tx.Exec("UPDATE inbounds SET remark = remark").Error + }); err != nil { + t.Fatalf("a pre-existing or new reader blocked the migration: %v", err) + } + if err := reader.Rollback().Error; err != nil { + t.Fatal(err) + } + + if err := db.Exec("ALTER TABLE inbounds ADD COLUMN all_time bigint").Error; err != nil { + t.Fatal(err) + } + reader = db.WithContext(ctx).Begin() + if reader.Error != nil { + t.Fatal(reader.Error) + } + defer reader.Rollback() + if err := reader.Exec("SELECT id FROM inbounds").Error; err != nil { + t.Fatal(err) + } + svc := &InboundService{} + if err := svc.MigrationRequirements(); !errors.Is(err, errInboundMigrationBusy) { + t.Fatalf("legacy DDL with a reader: %v, want immediate lock-conflict error", err) + } + if err := reader.Rollback().Error; err != nil { + t.Fatal(err) + } + if err := svc.MigrationRequirements(); err != nil || db.Migrator().HasColumn(&model.Inbound{}, "all_time") { + t.Fatalf("legacy column not removed after reader finished: %v", err) + } +} + func TestMigrationRequirementsRejectsLiveNodeMergePostgres(t *testing.T) { if config.GetDBKind() != database.DialectPostgres { t.Skip("requires PostgreSQL table locks") diff --git a/internal/web/service/server.go b/internal/web/service/server.go index 37643aa3b..ef0e6918b 100644 --- a/internal/web/service/server.go +++ b/internal/web/service/server.go @@ -52,6 +52,7 @@ import ( "github.com/shirou/gopsutil/v4/host" "github.com/shirou/gopsutil/v4/load" "github.com/shirou/gopsutil/v4/mem" + "gorm.io/gorm" ) // ProcessState represents the current state of a system process. @@ -1881,14 +1882,13 @@ func captureHostBoundSettings() hostBoundSnapshot { } func restoreHostBoundSettings(snap hostBoundSnapshot) { - if !snap.taken { + restoreHostBoundSettingsOn(database.GetDB(), snap) +} + +func restoreHostBoundSettingsOn(db *gorm.DB, snap hostBoundSnapshot) { + if !snap.taken || db == nil { return } - db := database.GetDB() - if db == nil { - return - } - settingSvc := &SettingService{} for _, key := range hostBoundSettingKeys { if _, had := snap.present[key]; !had { // Absent because it is minted on demand, not because a default applied: @@ -1903,7 +1903,7 @@ func restoreHostBoundSettings(snap hostBoundSnapshot) { } // saveSetting rather than Assign(struct): GORM drops zero-valued fields from // the assignment map, so an empty local value never overwrote the import. - if err := settingSvc.saveSetting(key, snap.values[key]); err != nil { + if err := saveSettingOn(db, key, snap.values[key]); err != nil { logger.Warningf("Import: could not restore setting %q for this machine: %v", key, err) } } @@ -2205,7 +2205,12 @@ func sniffUploadKind(file multipart.File) (int, error) { return sniffImportKind(header[:n]), nil } +var postgresImportMu sync.Mutex + func (s *ServerService) importPostgresDB(file multipart.File, keepHostSettings bool) error { + postgresImportMu.Lock() + defer postgresImportMu.Unlock() + kind, err := sniffUploadKind(file) if err != nil { return common.NewErrorf("Error reading uploaded file: %v", err) @@ -2222,6 +2227,33 @@ func (s *ServerService) importPostgresDB(file multipart.File, keepHostSettings b } } +func (s *ServerService) reopenPostgresAfterImport(imported bool, keptSettings hostBoundSnapshot) error { + var migrationErr error + err := database.InitDBBeforePublish(config.GetDBPath(), func(db *gorm.DB) error { + if !imported { + return nil + } + restoreHostBoundSettingsOn(db, keptSettings) + // Jobs and requests still see the closed pool. Another process may + // briefly hold locks, so retry only lock acquisition, before any writes. + deadline := time.Now().Add(10 * time.Second) + for { + migrationErr = s.inboundService.migrateDB(db) + if !errors.Is(migrationErr, errInboundMigrationBusy) || time.Now().After(deadline) { + return migrationErr + } + time.Sleep(100 * time.Millisecond) + } + }) + if migrationErr != nil { + return fmt.Errorf("database data was imported, but inbound migration failed: %w", migrationErr) + } + if err != nil { + return fmt.Errorf("reopening PostgreSQL after import failed: %w", err) + } + return nil +} + func (s *ServerService) restorePostgresDump(file multipart.File, keepHostSettings bool) error { bin, err := exec.LookPath("pg_restore") if err != nil { @@ -2283,18 +2315,13 @@ func (s *ServerService) restorePostgresDump(file multipart.File, keepHostSetting cmd.Stderr = &stderr runErr := cmd.Run() - if errInit := database.InitDB(config.GetDBPath()); errInit != nil { - return common.NewErrorf("Restore finished but reopening the database failed: %v", errInit) + if err := s.reopenPostgresAfterImport(runErr == nil, keptSettings); err != nil { + return err } - restoreHostBoundSettings(keptSettings) if runErr != nil { return common.NewErrorf("pg_restore failed (database left unchanged): %v: %s", runErr, strings.TrimSpace(stderr.String())) } - if err := s.inboundService.MigrateDB(); err != nil { - return common.NewErrorf("Restored DB but inbound migration failed: %v", err) - } - xrayStopped = false if err := s.restartXrayService(XrayOriginDatabaseRestore); err != nil { return common.NewErrorf("Restored DB but failed to start Xray: %v", err) @@ -2357,19 +2384,12 @@ func (s *ServerService) migrateSQLiteIntoPostgres(file multipart.File, isSQLDump migrateErr := database.MigrateData(dbPath, config.GetDBDSN()) - if errInit := database.InitDB(config.GetDBPath()); errInit != nil { - return common.NewErrorf("Restore finished but reopening the database failed: %v", errInit) - } - if migrateErr == nil { - restoreHostBoundSettings(keptSettings) + if err := s.reopenPostgresAfterImport(migrateErr == nil, keptSettings); err != nil { + return err } if migrateErr != nil { return common.NewErrorf("Importing the SQLite data into PostgreSQL failed: %v; the import runs in a single transaction, so the database was left unchanged", migrateErr) } - if err := s.inboundService.MigrateDB(); err != nil { - return common.NewErrorf("Imported DB but inbound migration failed: %v", err) - } - xrayStopped = false if err := s.restartXrayService(XrayOriginDatabaseRestore); err != nil { return common.NewErrorf("Restored DB but failed to start Xray: %v", err) diff --git a/internal/web/service/setting.go b/internal/web/service/setting.go index f801e920e..f5ab63fc7 100644 --- a/internal/web/service/setting.go +++ b/internal/web/service/setting.go @@ -465,8 +465,12 @@ func (s *SettingService) getSetting(key string) (*model.Setting, error) { } func (s *SettingService) saveSetting(key string, value string) error { - setting, err := s.getSetting(key) - db := database.GetDB() + return saveSettingOn(database.GetDB(), key, value) +} + +func saveSettingOn(db *gorm.DB, key string, value string) error { + var setting model.Setting + err := db.Where("key = ?", key).First(&setting).Error if database.IsNotFound(err) { return db.Create(&model.Setting{ Key: key, @@ -477,7 +481,7 @@ func (s *SettingService) saveSetting(key string, value string) error { } setting.Key = key setting.Value = value - return db.Save(setting).Error + return db.Save(&setting).Error } func (s *SettingService) getString(key string) (string, error) { diff --git a/scripts_base_path_test.go b/scripts_base_path_test.go index 0fba126c7..0d3e2f8fa 100644 --- a/scripts_base_path_test.go +++ b/scripts_base_path_test.go @@ -31,7 +31,11 @@ func scriptFunction(t *testing.T, script, name string) string { const settingsCLIMock = `#!/bin/bash set -eu state=$TEST_SETTINGS_DIR -if [[ "$1" == migrate ]]; then exit 0; fi +if [[ "$1" == migrate ]]; then + printf 'migrate\n' >> "$state/lifecycle" + if [[ "$TEST_READ_MODE" == migration_failure ]]; then exit 1; fi + exit 0 +fi shift case "$1" in -show) @@ -145,7 +149,8 @@ fail2ban_mode=install body := scriptFunction(t, script, parent) startCall := function if script == "update.sh" { - startCall = "setup_fail2ban" + startCall = `echo -e "${green}Migrating database...${plain}"` + driver += scriptFunction(t, script, "_fail") } start := strings.Index(body, "\n "+startCall) if start < 0 { @@ -277,6 +282,8 @@ func TestScriptConfigReadFailureKeepsServiceSetup(t *testing.T) { wantLifecycle, wantServices := "fail2ban\nunit\n", "daemon-reload\nenable x-ui\nstart x-ui\n" if script == "install.sh" { wantServices = "daemon-reload\nenable x-ui\nrestart x-ui\n" + } else { + wantLifecycle = "migrate\n" + wantLifecycle } for name, want := range map[string]string{ "path": "/a/", "username": "admin", "password": "admin", "writes": "", @@ -289,3 +296,16 @@ func TestScriptConfigReadFailureKeepsServiceSetup(t *testing.T) { }) } } + +func TestUpdateMigrationFailurePreventsServiceStart(t *testing.T) { + dir, out, err := runScriptConfig(t, "update.sh", "/a/", false, "migration_failure", 1, true) + if err == nil || !strings.Contains(out, "Database migration failed") { + t.Fatalf("migration failure should abort the update: %v\n%s", err, out) + } + if got := readScriptState(t, dir, "restarts"); got != "" { + t.Fatalf("service started after a failed migration: %q", got) + } + if got := readScriptState(t, dir, "lifecycle"); got != "migrate\n" { + t.Fatalf("lifecycle after failed migration: %q", got) + } +} diff --git a/update.sh b/update.sh index 7d7e3a1ff..dc0ffa818 100755 --- a/update.sh +++ b/update.sh @@ -172,7 +172,6 @@ config_after_update() { echo -e "${yellow}x-ui settings:${plain}" ${xui_folder}/x-ui setting -show true - ${xui_folder}/x-ui migrate # Properly detect empty cert by checking if cert: line exists and has content after it local existing_cert=$(${xui_folder}/x-ui setting -getCert true 2> /dev/null | grep 'cert:' | awk -F': ' '{print $2}' | tr -d '[:space:]') @@ -680,10 +679,11 @@ update_x-ui() { chmod 640 ${xui_folder}/bin/config.json > /dev/null 2>&1 fi - # Finish the schema/data migrations before the service starts, so the service and - # config_after_update's CLI calls never run them on the same database at once (#6728). + # Finish the schema/data migrations before the service starts. echo -e "${green}Migrating database...${plain}" - "${xui_folder}/x-ui" migrate + if ! "${xui_folder}/x-ui" migrate; then + _fail "ERROR: Database migration failed; x-ui was not started." + fi setup_fail2ban if [[ $release == "alpine" ]]; then