From b42701e4efffadf80d6877c183e1935065dad9e8 Mon Sep 17 00:00:00 2001 From: Farhan Khan Date: Sat, 11 Dec 2021 00:32:32 -0500 Subject: [PATCH] Adding autostart from database --- fedilogue/fedilogue.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/fedilogue/fedilogue.go b/fedilogue/fedilogue.go index 863f11c..df97bfb 100644 --- a/fedilogue/fedilogue.go +++ b/fedilogue/fedilogue.go @@ -3,8 +3,9 @@ package main import ( "net/http" _ "net/http/pprof" - "regexp" + "context" "runtime" + "regexp" "sync" "time" @@ -82,6 +83,28 @@ func main() { re = regexp.MustCompile("^https?://([^/]*)/(.*)$") matchurl = regexp.MustCompile("http?s://[\\w\\-]+\\.[\\w\\-]+\\S*") + // Start instances located in database + rows, err := pool.Query(context.Background(), "SELECT endpoint FROM instances") + if err != nil { + logErr("Unable to select from instances") + return + } + defer rows.Close() + + for rows.Next() { + var endpoint string + err = rows.Scan(&endpoint) + if err != nil { + logErr("Unable to iterate") + return + } + _, exists := GetRunner(endpoint) + if exists == false { + go StartInstance(endpoint) + } + } + + // Start from Autostart list for _, endpoint := range settings.Autostart { logInfo("Autostarting " + endpoint) _, exists := GetRunner(endpoint)