From d4fd6b99251da37f322b07f6a63724318a134170 Mon Sep 17 00:00:00 2001 From: Adam Cooke Date: Fri, 5 May 2017 11:42:28 +0100 Subject: [PATCH] By default, we will now listen directly on various ports [breaking] This allows us to avoid messing around with changes to iptables and generally makes installation easier for everyone. If you have an instance of postal before this, you will need to do a couple of things to ensure your installation continues to work. 1. You will need to specify a `fast_server.bind_address` in your postal.yml configuration file. This is the IP that you dedicated to the fast server. 2. You will need to allow Ruby to listen on privileged ports (sudo setcap 'cap_net_bind_service=+ep' /usr/bin/ruby2.3). 3. You will need to remove any iptables rules that you may have added previously to accomodate the older way of doing this. --- config/postal.defaults.yml | 10 ++++------ config/postal.example.yml | 1 + lib/postal/fast_server/server.rb | 9 +++++++-- lib/postal/smtp_server/server.rb | 5 ++--- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/config/postal.defaults.yml b/config/postal.defaults.yml index a0bd18a..6fbb9f4 100644 --- a/config/postal.defaults.yml +++ b/config/postal.defaults.yml @@ -22,8 +22,8 @@ web_server: fast_server: enabled: false bind_address: 0.0.0.0 - port: 5010 - ssl_port: 5011 + port: 80 + ssl_port: 443 proxy_protocol: false default_private_key_path: # Defaults to config/fast_server.key default_tls_certificate_path: # Defaults to config/fast_server.cert @@ -58,14 +58,12 @@ workers: quantity: 1 smtp_server: + port: 25 tls_enabled: false tls_certificate_path: # Defaults to config/smtp.crt tls_private_key_path: # Defaults to config/smtp.key proxy_protocol: false log_connect: true - evented: true - ports: - - 2525 smtp_relays: - @@ -88,7 +86,7 @@ dns: smtp: host: 127.0.0.1 - port: 2525 + port: 25 username: # Complete when Postal is running and you can password: # generate the credentials within the interface. from_name: Postal diff --git a/config/postal.example.yml b/config/postal.example.yml index 098c7fa..0820989 100644 --- a/config/postal.example.yml +++ b/config/postal.example.yml @@ -8,6 +8,7 @@ fast_server: # This can be enabled to enable click & open tracking on emails. It is disabled by # default as it requires a separate static IP address on your server. enabled: false + bind_address: general: # This can be changed to allow messages to be sent from multiple IP addresses diff --git a/lib/postal/fast_server/server.rb b/lib/postal/fast_server/server.rb index 7c99db0..5320792 100644 --- a/lib/postal/fast_server/server.rb +++ b/lib/postal/fast_server/server.rb @@ -6,14 +6,19 @@ module Postal class Server def run + if Postal.config.fast_server.bind_address.blank? + Postal.logger_for(:fast_server).info "Cannot start fast server because no bind address has been specified" + exit 1 + end + Thread.abort_on_exception = true TrackCertificate server_sockets = { TCPServer.new(Postal.config.fast_server.bind_address, Postal.config.fast_server.ssl_port) => {:ssl => true}, TCPServer.new(Postal.config.fast_server.bind_address, Postal.config.fast_server.port) => {:ssl => false}, } - Postal.logger_for(:fast_server).info("Fast server started listening on HTTP port #{Postal.config.fast_server.port}") - Postal.logger_for(:fast_server).info("Fast server started listening on HTTPS port #{Postal.config.fast_server.ssl_port}") + Postal.logger_for(:fast_server).info("Fast server started listening on HTTP (#{Postal.config.fast_server.bind_address}:#{Postal.config.fast_server.port})") + Postal.logger_for(:fast_server).info("Fast server started listening on HTTPS port (#{Postal.config.fast_server.bind_address}:#{Postal.config.fast_server.ssl_port})") loop do client = nil ios = select(server_sockets.keys, nil, nil, 1) diff --git a/lib/postal/smtp_server/server.rb b/lib/postal/smtp_server/server.rb index 7d14426..4cd5d46 100644 --- a/lib/postal/smtp_server/server.rb +++ b/lib/postal/smtp_server/server.rb @@ -7,7 +7,6 @@ module Postal def initialize(options = {}) @options = options - @options[:ports] ||= Postal.config.smtp_server.ports @options[:debug] ||= false prepare_environment end @@ -49,7 +48,7 @@ module Postal if ENV['SERVER_FD'] @server = TCPServer.for_fd(ENV['SERVER_FD'].to_i) else - @server = TCPServer.open('::', @options[:ports].first) + @server = TCPServer.open('::', Postal.config.smtp_server.port) end @server.autoclose = false @server.close_on_exec = false @@ -62,7 +61,7 @@ module Postal @server.setsockopt(Socket::SOL_TCP, Socket::TCP_KEEPCNT, 5) end ENV['SERVER_FD'] = @server.to_i.to_s - logger.info "Listening" + logger.info "Listening on port #{Postal.config.smtp_server.port}" end def unlisten