90 lines
1.9 KiB
Go
90 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
_ "net/http/pprof"
|
|
"regexp"
|
|
"runtime"
|
|
"sync"
|
|
"time"
|
|
"github.com/microcosm-cc/bluemonday"
|
|
)
|
|
|
|
// Current instances
|
|
var runninginstances map[string]RunningInstance
|
|
var ri_mutex = &sync.Mutex{}
|
|
|
|
func startpprof() {
|
|
logInfo("Starting http/pprof on :7777")
|
|
logFatal.Fatal(http.ListenAndServe("127.0.0.1:7777", nil))
|
|
}
|
|
|
|
func statusReport() {
|
|
for {
|
|
running := 0
|
|
keepalive := 0
|
|
unsupported := 0
|
|
|
|
mastodon := 0
|
|
pleroma := 0
|
|
other := 0
|
|
ri_mutex.Lock()
|
|
for _, o := range runninginstances {
|
|
if o.Status == 200 {
|
|
running = running + 1
|
|
} else if o.Status == 607 { // Keepalive
|
|
keepalive = keepalive + 1
|
|
} else if o.Status == 605 {// Unsupported instance
|
|
unsupported = unsupported + 1
|
|
}
|
|
|
|
if o.Software == "mastodon" && o.Status == 200 {
|
|
mastodon = mastodon + 1
|
|
} else if o.Software == "pleroma" && o.Status == 200 {
|
|
pleroma = pleroma + 1
|
|
} else if o.Status == 200 {
|
|
other = other + 1
|
|
}
|
|
}
|
|
ri_mutex.Unlock()
|
|
logInfo("Running:",running," Keepalive:", keepalive, " Unsupported:", unsupported, " M:", mastodon, ",P:",pleroma,",O:",other)
|
|
time.Sleep(time.Second*60)
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
// Initial Setup
|
|
logInit()
|
|
runninginstances = make(map[string]RunningInstance)
|
|
|
|
getSettings()
|
|
if len(settings.Proxies) > 0 {
|
|
for i := 0; i < len(settings.Proxies); i++ {
|
|
logInfo("Using proxy: ", settings.Proxies[i].Host, ":", settings.Proxies[i].Port)
|
|
}
|
|
}
|
|
go startpprof()
|
|
|
|
pool = getDbPool()
|
|
|
|
p = bluemonday.NewPolicy()
|
|
spaceReg = regexp.MustCompile(`[\s\t\.]+`)
|
|
removeHTMLReg = regexp.MustCompile(`<\/?\s*br\s*>`)
|
|
re = regexp.MustCompile("^https?://([^/]*)/(.*)$")
|
|
matchurl = regexp.MustCompile("http?s://[\\w\\-]+\\.[\\w\\-]+\\S*")
|
|
|
|
for _, endpoint := range settings.Autostart {
|
|
logInfo("Autostarting " + endpoint)
|
|
_, exists := GetRunner(endpoint)
|
|
if exists == false {
|
|
go StartInstance(endpoint)
|
|
}
|
|
}
|
|
|
|
go startctl()
|
|
//go webmain()
|
|
go statusReport()
|
|
|
|
runtime.Goexit()
|
|
}
|