albertito / chasquid

SMTP (email) server with a focus on simplicity, security, and ease of operation [mirror]
https://blitiri.com.ar/p/chasquid/
Other
868 stars 56 forks source link

Add /exit to monitoring server #13

Closed ThinkChaos closed 3 years ago

ThinkChaos commented 3 years ago

Allows terminating chasquid via the network. Useful to trigger a restart (if there is an init system to relaunch chasquid) and thus reload certificates.

Fixes #12

albertito commented 3 years ago

Thanks for sending this!

What do you think of just adding this endpoint to the monitoring server?

The monitoring server is quite sensitive since it can contain private information in the logs and dumps, so it's important not to expose it already, and clear in documentation, defaults, etc.

My suggestion is to add something like this to monitoring.go:

// In launchMonitoringServer:
//         http.HandleFunc("/quit", quitHandler)

func quitHandler(w http.ResponseWriter, r *http.Request) {
        if r.Method != "POST" {
                http.Error(w, "Use POST method for quitting", http.StatusMethodNotAllowed)
                return
        }

        log.Info("Received /quit")
        os.Exit(0)
}

What do you think?

albertito commented 3 years ago

This looks great!

Sorry I won't be able to merge this right now, but I'll post another update once it's been added, hopefully tomorrow :)

Thanks again!

albertito commented 3 years ago

Merged to the next branch in commit 99ec58bfcd, with two amends: I added some tests, and I also adjusted the shutdown to happen after srv.Shutdown call completes, instead of server return, as per the Server.Shutdown docs.

If you have any further suggestions, please let me know! I'm happy to amend or split these changes if you prefer.

I will keep this change in next for a bit and once it has gotten enough exposure I'll move it to master, for inclusion in the next release.

Thanks a lot again!