git » chasquid » commit d0afe10

chasquid: Exit with code 0 on SIGINT/SIGTERM

author Alberto Bertogli
2025-08-03 16:45:58 UTC
committer Alberto Bertogli
2025-08-03 16:56:43 UTC
parent a9c1f88bd97a433c3451a3573901193f9cc205d4

chasquid: Exit with code 0 on SIGINT/SIGTERM

When we get SIGINT or SIGTERM, today chasquid exits with code 1. This
can confuse some of the supervision tools.

In particular, Docker and Kubernetes expect exit 0 upon an intentional
stop.

And systemd, the Restart= semantics make a difference with 0 and non-0,
and exiting with 1 prevents users from making that distinction.

This patch changes the SIGINT/SIGTERM exit code to 0, to make it easier
for users to set up things as desired in those environments.

Thanks to [Guiorgy@github](https://github.com/Guiorgy) for reporting
this problem in https://github.com/albertito/chasquid/pull/70.

chasquid.go +5 -1

diff --git a/chasquid.go b/chasquid.go
index a9bef08..18040e2 100644
--- a/chasquid.go
+++ b/chasquid.go
@@ -247,7 +247,11 @@ func signalHandler(dinfo *domaininfo.DB, srv *smtpsrv.Server) {
 			// Also trigger a server reload.
 			srv.Reload()
 		case syscall.SIGTERM, syscall.SIGINT:
-			log.Fatalf("Got signal to exit: %v", sig)
+			log.Infof("Got signal to exit: %v", sig)
+			// Ideally, we would shutdown the server gracefully, but for now
+			// we just exit. Note that in practice this is not a significant
+			// problem, as any in-flight transaction should be retried.
+			os.Exit(0)
 		default:
 			log.Errorf("Unexpected signal %v", sig)
 		}