예제 #1
0
파일: main.go 프로젝트: LukeShu/periwinkle
func main() {
	options := cmdutil.Docopt(usage)
	config := cmdutil.GetConfig(options["-c"].(string))

	conflict := config.DB.Do(func(tx *periwinkle.Tx) {
		/*
			err := backend.DbSchema(tx)
			if err != nil {
				periwinkle.Logf("Encountered an error while setting up the database schema, not attempting to seed data:")
				periwinkle.LogErr(err)
				os.Exit(int(lsb.EXIT_FAILURE))
			}

			err = backend.DbSeed(tx)
			if err != nil {
				periwinkle.Logf("Encountered an error while seeding the database:")
				periwinkle.LogErr(err)
				os.Exit(int(lsb.EXIT_FAILURE))
			}
		*/
		test.Test(config, tx)
	})
	if conflict != nil {
		periwinkle.LogErr(conflict)
		os.Exit(int(lsb.EXIT_FAILURE))
	}
}
예제 #2
0
파일: main.go 프로젝트: LukeShu/periwinkle
func main() {
	options := cmdutil.Docopt(usage)
	config := cmdutil.GetConfig(options["-c"].(string))

	var ret pp.ExitStatus = pp.EX_OK
	defer func() {
		if reason := recover(); reason != nil {
			const size = 64 << 10
			buf := make([]byte, size)
			buf = buf[:runtime.Stack(buf, false)]
			st := fmt.Sprintf("%[1]T(%#[1]v) => %[1]v\n\n%[2]s", reason, string(buf))
			periwinkle.Logf("%s", st)
			ret = pp.EX_UNAVAILABLE
		}
		pp.Exit(ret)
	}()

	conflict := config.DB.Do(func(transaction *periwinkle.Tx) {
		msg := pp.Get()

		recipient := msg.ORIGINAL_RECIPIENT()
		if recipient == "" {
			periwinkle.Logf("ORIGINAL_RECIPIENT must be set")
			ret = pp.EX_USAGE
			return
		}
		parts := strings.SplitN(recipient, "@", 2)
		user := parts[0]
		domain := "localhost"
		if len(parts) == 2 {
			domain = parts[1]
		}
		domain = strings.ToLower(domain)

		reader, err := msg.Reader()
		if err != nil {
			periwinkle.LogErr(err)
			ret = pp.EX_NOINPUT
			return
		}

		if handler, ok := config.DomainHandlers[domain]; ok {
			ret = handler(reader, user, transaction, config)
		} else {
			ret = config.DefaultDomainHandler(reader, recipient, transaction, config)
		}
	})
	if conflict != nil {
		ret = pp.EX_DATAERR
	}
}
예제 #3
0
파일: main.go 프로젝트: LukeShu/periwinkle
func main() {
	options := cmdutil.Docopt(usage)

	args := []string{}
	if options["ADDR_TYPE"] != nil {
		args = append(args, options["ADDR_TYPE"].(string))
	}
	if options["ADDR"] != nil {
		args = append(args, options["ADDR"].(string))
	}
	socket := parseArgs(args)

	config := cmdutil.GetConfig(options["-c"].(string))

	signals := make(chan os.Signal)
	signal.Notify(signals, syscall.SIGTERM, syscall.SIGHUP)

	periwinkle.Logf("Ready; listening")
	sd.Notify(false, "READY=1")

	done := make(chan uint8)
	server := httpapi.MakeServer(socket, config)
	server.Start()
	go func() {
		err := server.Wait()
		if err != nil {
			periwinkle.LogErr(err)
			done <- 1
		} else {
			done <- 0
		}
	}()

	for {
		select {
		case sig := <-signals:
			switch sig {
			case syscall.SIGTERM:
				sd.Notify(false, "STOPPING=1")
				server.Stop()
			case syscall.SIGHUP:
				sd.Notify(false, "RELOADING=1")
				// TODO: reload configuration file
				sd.Notify(false, "READY=1")
			}
		case status := <-done:
			os.Exit(int(status))
		}
	}
}
예제 #4
0
파일: main.go 프로젝트: LukeShu/periwinkle
func main() {
	options := cmdutil.Docopt(usage)
	config := cmdutil.GetConfig(options["-c"].(string))

	conflict := config.DB.Do(func(tx *periwinkle.Tx) {
		err := backend.DbDrop(tx)
		if err != nil {
			periwinkle.LogErr(err)
			os.Exit(int(lsb.EXIT_FAILURE))
		}
	})
	if conflict != nil {
		periwinkle.LogErr(conflict)
		os.Exit(int(lsb.EXIT_FAILURE))
	}
}
예제 #5
0
파일: main.go 프로젝트: LukeShu/periwinkle
func main() {
	options := cmdutil.Docopt(usage)
	config := cmdutil.GetConfig(options["-c"].(string))

	for {
		time.Sleep(time.Second)
		conflict := config.DB.Do(func(tx *periwinkle.Tx) {
			numbers := backend.GetAllUsedTwilioNumbers(tx)

			for _, number := range numbers {
				checkNumber(config, tx, number)
			}
		})
		if conflict != nil {
			periwinkle.LogErr(conflict)
		}
		lastPoll = time.Now().UTC()
	}
}