58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/microcosm-cc/bluemonday"
|
|
"log"
|
|
"net/http"
|
|
_ "net/http/pprof"
|
|
"regexp"
|
|
"runtime"
|
|
"sync"
|
|
"github.com/jackc/pgx/pgxpool"
|
|
)
|
|
|
|
// Current instances
|
|
var runninginstances map[string]RunningInstance
|
|
var ri_mutex = &sync.Mutex{}
|
|
var pool *pgxpool.Pool
|
|
var requestconnchan chan ConnRequest
|
|
|
|
func startpprof() {
|
|
log.Print("Starting http/pprof on :7777")
|
|
log.Fatal(http.ListenAndServe("127.0.0.1:7777", nil))
|
|
}
|
|
|
|
func main() {
|
|
// Initial Setup
|
|
runninginstances = make(map[string]RunningInstance)
|
|
requestconnchan = make(chan ConnRequest)
|
|
|
|
getSettings()
|
|
go startpprof()
|
|
|
|
pool = getDbPool()
|
|
|
|
for i := 0; i < settings.Database.Workers; i++ {
|
|
go requestConn()
|
|
}
|
|
|
|
p = bluemonday.NewPolicy()
|
|
spaceReg = regexp.MustCompile(`\s+`)
|
|
|
|
for _, endpoint := range settings.Autostart {
|
|
log.Print("Autostarting " + endpoint)
|
|
ri_mutex.Lock()
|
|
_, exists := runninginstances[endpoint]
|
|
if exists == false {
|
|
runninginstances[endpoint] = RunningInstance{}
|
|
go StartInstance(endpoint)
|
|
}
|
|
ri_mutex.Unlock()
|
|
}
|
|
|
|
go startctl()
|
|
go webmain()
|
|
|
|
runtime.Goexit()
|
|
}
|