Add a service manager to main (future use)

This commit is contained in:
Jakob Borg 2015-04-25 18:19:53 +09:00
parent 2a60f4b1e9
commit bb31b1785b

View File

@ -39,6 +39,7 @@ import (
"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/errors"
"github.com/syndtr/goleveldb/leveldb/opt"
"github.com/thejerf/suture"
"golang.org/x/crypto/bcrypt"
)
@ -373,7 +374,15 @@ func main() {
}
func syncthingMain() {
var err error
// Create a main service manager. We'll add things to this as we go along.
// We want any logging it does to go through our log system, with INFO
// severity.
mainSvc := suture.New("main", suture.Spec{
Log: func(line string) {
l.Infoln(line)
},
})
mainSvc.ServeBackground()
if len(os.Getenv("GOMAXPROCS")) == 0 {
runtime.GOMAXPROCS(runtime.NumCPU())
@ -382,7 +391,7 @@ func syncthingMain() {
events.Default.Log(events.Starting, map[string]string{"home": baseDirs["config"]})
// Ensure that that we have a certificate and key.
cert, err = tls.LoadX509KeyPair(locations[locCertFile], locations[locKeyFile])
cert, err := tls.LoadX509KeyPair(locations[locCertFile], locations[locKeyFile])
if err != nil {
cert, err = newCertificate(locations[locCertFile], locations[locKeyFile], tlsDefaultCommonName)
if err != nil {
@ -639,6 +648,8 @@ func syncthingMain() {
code := <-stop
mainSvc.Stop()
l.Okln("Exiting")
os.Exit(code)
}