2020-11-10 21:53:46 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-12-17 04:23:25 +00:00
|
|
|
"github.com/microcosm-cc/bluemonday"
|
|
|
|
"log"
|
2020-11-10 21:53:46 -05:00
|
|
|
"net/http"
|
2020-12-17 04:23:25 +00:00
|
|
|
_ "net/http/pprof"
|
2020-12-06 18:05:17 -05:00
|
|
|
"regexp"
|
2020-12-14 23:09:51 +00:00
|
|
|
"runtime"
|
2020-12-17 04:23:25 +00:00
|
|
|
"sync"
|
2020-12-18 06:06:32 +00:00
|
|
|
"github.com/jackc/pgx/pgxpool"
|
2020-11-10 21:53:46 -05:00
|
|
|
)
|
|
|
|
|
2020-11-17 18:28:59 -05:00
|
|
|
// Current instances
|
|
|
|
var runninginstances map[string]RunningInstance
|
|
|
|
var ri_mutex = &sync.Mutex{}
|
2020-12-18 06:06:32 +00:00
|
|
|
var pool *pgxpool.Pool
|
2020-11-10 21:53:46 -05:00
|
|
|
|
2020-11-24 20:36:47 -05:00
|
|
|
func startpprof() {
|
|
|
|
log.Print("Starting http/pprof on :7777")
|
|
|
|
log.Fatal(http.ListenAndServe("127.0.0.1:7777", nil))
|
|
|
|
}
|
2020-11-10 21:53:46 -05:00
|
|
|
|
2020-11-24 20:36:47 -05:00
|
|
|
func main() {
|
2020-11-10 21:53:46 -05:00
|
|
|
// Initial Setup
|
2020-11-24 20:36:47 -05:00
|
|
|
runninginstances = make(map[string]RunningInstance)
|
2020-11-10 21:53:46 -05:00
|
|
|
|
2020-12-03 17:26:38 -05:00
|
|
|
getSettings()
|
2020-11-24 20:36:47 -05:00
|
|
|
go startpprof()
|
2020-11-16 00:10:33 -05:00
|
|
|
|
2020-12-18 06:06:32 +00:00
|
|
|
pool = getDbPool()
|
2020-12-03 17:26:38 -05:00
|
|
|
|
2020-12-06 18:05:17 -05:00
|
|
|
p = bluemonday.NewPolicy()
|
|
|
|
spaceReg = regexp.MustCompile(`\s+`)
|
2020-12-03 17:26:38 -05:00
|
|
|
|
|
|
|
for _, endpoint := range settings.Autostart {
|
|
|
|
log.Print("Autostarting " + endpoint)
|
|
|
|
ri_mutex.Lock()
|
|
|
|
_, exists := runninginstances[endpoint]
|
2020-12-17 18:26:55 +00:00
|
|
|
if exists == false {
|
2020-12-03 17:26:38 -05:00
|
|
|
runninginstances[endpoint] = RunningInstance{}
|
2020-12-22 20:36:37 +00:00
|
|
|
go StartInstance(endpoint)
|
2020-12-03 17:26:38 -05:00
|
|
|
}
|
|
|
|
ri_mutex.Unlock()
|
|
|
|
}
|
|
|
|
|
2020-12-22 20:36:37 +00:00
|
|
|
go startctl()
|
|
|
|
go webmain()
|
2020-12-14 23:09:51 +00:00
|
|
|
|
|
|
|
runtime.Goexit()
|
2020-11-10 21:53:46 -05:00
|
|
|
}
|