From dce39b836a0fd6e37ab2499c2e0e232572c17ad6 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Fri, 6 Aug 2021 20:34:18 -0600 Subject: add redis process, put circus in charge of process management --- srv/cmd/mediocre-blog/main.go | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'srv/cmd') diff --git a/srv/cmd/mediocre-blog/main.go b/srv/cmd/mediocre-blog/main.go index 66c17ee..0a5f8b7 100644 --- a/srv/cmd/mediocre-blog/main.go +++ b/srv/cmd/mediocre-blog/main.go @@ -62,10 +62,6 @@ func main() { logger.Fatal(ctx, "-static-dir or -static-proxy-url is required") case *powSecret == "": logger.Fatal(ctx, "-pow-secret is required") - case *smtpAddr == "": - logger.Fatal(ctx, "-ml-smtp-addr is required") - case *smtpAuthStr == "": - logger.Fatal(ctx, "-ml-smtp-auth is required") } publicURL, err := url.Parse(*publicURLStr) @@ -87,14 +83,22 @@ func main() { } powTarget := uint32(powTargetUint) - smtpAuthParts := strings.SplitN(*smtpAuthStr, ":", 2) - if len(smtpAuthParts) < 2 { - logger.Fatal(ctx, "invalid -ml-smtp-auth") - } - smtpAuth := sasl.NewPlainClient("", smtpAuthParts[0], smtpAuthParts[1]) - smtpSendAs := smtpAuthParts[0] + var mailerCfg mailinglist.MailerParams - // initialization + if *smtpAddr != "" { + mailerCfg.SMTPAddr = *smtpAddr + smtpAuthParts := strings.SplitN(*smtpAuthStr, ":", 2) + if len(smtpAuthParts) < 2 { + logger.Fatal(ctx, "invalid -ml-smtp-auth") + } + mailerCfg.SMTPAuth = sasl.NewPlainClient("", smtpAuthParts[0], smtpAuthParts[1]) + mailerCfg.SendAs = smtpAuthParts[0] + + ctx = mctx.Annotate(ctx, + "smtpAddr", mailerCfg.SMTPAddr, + "smtpSendAs", mailerCfg.SendAs, + ) + } ctx = mctx.Annotate(ctx, "publicURL", publicURL.String(), @@ -102,10 +106,10 @@ func main() { "listenAddr", *listenAddr, "dataDir", *dataDir, "powTarget", fmt.Sprintf("%x", powTarget), - "smtpAddr", *smtpAddr, - "smtpSendAs", smtpSendAs, ) + // initialization + if *staticDir != "" { ctx = mctx.Annotate(ctx, "staticDir", *staticDir) } else { @@ -127,11 +131,13 @@ func main() { // sugar requirePow := func(h http.Handler) http.Handler { return requirePowMiddleware(powMgr, h) } - mailer := mailinglist.NewMailer(mailinglist.MailerParams{ - SMTPAddr: *smtpAddr, - SMTPAuth: smtpAuth, - SendAs: smtpSendAs, - }) + var mailer mailinglist.Mailer + if *smtpAddr == "" { + logger.Info(ctx, "-smtp-addr not given, using NullMailer") + mailer = mailinglist.NullMailer + } else { + mailer = mailinglist.NewMailer(mailerCfg) + } mlStore, err := mailinglist.NewStore(path.Join(*dataDir, "mailinglist.sqlite3")) if err != nil { -- cgit v1.2.3