package main import ( _ "net/http/pprof" "net/http" "sync" "regexp" "log" "github.com/microcosm-cc/bluemonday" "runtime" ) // Current instances var runninginstances map[string]RunningInstance var ri_mutex = &sync.Mutex{} func startpprof() { log.Print("Starting http/pprof on :7777") log.Fatal(http.ListenAndServe("127.0.0.1:7777", nil)) } func main() { // Initial Setup reportPostChan := make(chan ReportPost) runninginstances = make(map[string]RunningInstance) getSettings() go startpprof() pool := get_db_pool() for i := 0; i < settings.Database.Workers; i++ { go postHandler(reportPostChan, pool) } p = bluemonday.NewPolicy() spaceReg = regexp.MustCompile(`\s+`) for _, endpoint := range settings.Autostart { log.Print("Autostarting " + endpoint) ri_mutex.Lock() _, exists := runninginstances[endpoint] if exists == true { log.Print("Already exists: " + endpoint) } else { runninginstances[endpoint] = RunningInstance{} go StartInstance(endpoint, reportPostChan) } ri_mutex.Unlock() } go startctl(reportPostChan) go webmain(reportPostChan) runtime.Goexit() }