Support running on demand systemd socket activation

This commit is contained in:
Alexander Neumann
2021-08-09 16:06:35 +02:00
parent 32784a3072
commit f90205eefe
8 changed files with 92 additions and 9 deletions

View File

@@ -129,16 +129,17 @@ func runRoot(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
if !enabledTLS {
log.Printf("Starting server on %s\n", server.Listen)
err = http.ListenAndServe(server.Listen, handler)
} else {
log.Println("TLS enabled")
log.Printf("Private key: %s", privateKey)
log.Printf("Public key(certificate): %s", publicKey)
log.Printf("Starting server on %s\n", server.Listen)
err = http.ListenAndServeTLS(server.Listen, publicKey, privateKey, handler)
listener, err := findListener(server.Listen)
if err != nil {
return fmt.Errorf("unable to listen: %w", err)
}
if !enabledTLS {
err = http.Serve(listener, handler)
} else {
log.Printf("TLS enabled, private key %s, pubkey %v", privateKey, publicKey)
err = http.ServeTLS(listener, handler, publicKey, privateKey)
}
return err