From 3468a8cb8aaaf63386a45ec75e832e6ddab71920 Mon Sep 17 00:00:00 2001 From: Alex Jaspersen Date: Sun, 17 May 2020 05:00:04 +0000 Subject: [PATCH 1/2] Add support for Unix domain sockets. This adds a new configuration option, socket-path, instead of using host. --- conventional.yaml | 2 ++ irc/mysql/config.go | 1 + irc/mysql/history.go | 4 +++- oragono.yaml | 2 ++ 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/conventional.yaml b/conventional.yaml index d39b3195..cd1ae1d4 100644 --- a/conventional.yaml +++ b/conventional.yaml @@ -665,6 +665,8 @@ datastore: host: "localhost" # port is unnecessary for connections via unix domain socket: #port: 3306 + # if socket-path is set, it will be used instead of host:port + #socket-path: "/var/run/mysqld/mysqld.sock" user: "oragono" password: "hunter2" history-database: "oragono_history" diff --git a/irc/mysql/config.go b/irc/mysql/config.go index c4a19ae5..2c4ff54c 100644 --- a/irc/mysql/config.go +++ b/irc/mysql/config.go @@ -12,6 +12,7 @@ type Config struct { Enabled bool Host string Port int + SocketPath string `yaml:"socket-path"` User string Password string HistoryDatabase string `yaml:"history-database"` diff --git a/irc/mysql/history.go b/irc/mysql/history.go index b1b86a23..5a6cb000 100644 --- a/irc/mysql/history.go +++ b/irc/mysql/history.go @@ -88,7 +88,9 @@ func (mysql *MySQL) getExpireTime() (expireTime time.Duration) { func (m *MySQL) Open() (err error) { var address string - if m.config.Port != 0 { + if m.config.SocketPath != "" { + address = fmt.Sprintf("unix(%s)", m.config.SocketPath) + } else if m.config.Port != 0 { address = fmt.Sprintf("tcp(%s:%d)", m.config.Host, m.config.Port) } diff --git a/oragono.yaml b/oragono.yaml index 90e43920..9f4ed2f7 100644 --- a/oragono.yaml +++ b/oragono.yaml @@ -686,6 +686,8 @@ datastore: host: "localhost" # port is unnecessary for connections via unix domain socket: #port: 3306 + # if socket-path is set, it will be used instead of host:port + #socket-path: "/var/run/mysqld/mysqld.sock" user: "oragono" password: "hunter2" history-database: "oragono_history" From fc1d6ee724af18696f4534dfddc4f965a073ba69 Mon Sep 17 00:00:00 2001 From: Alex Jaspersen Date: Sun, 17 May 2020 05:13:10 +0000 Subject: [PATCH 2/2] Uncomment MySQL port in default configs. This ensures that host:port is used rather than an empty address, which defaults to 127.0.0.1:3306 (ignoring the host in the config). --- conventional.yaml | 3 +-- oragono.yaml | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/conventional.yaml b/conventional.yaml index cd1ae1d4..bf587af7 100644 --- a/conventional.yaml +++ b/conventional.yaml @@ -663,8 +663,7 @@ datastore: mysql: enabled: false host: "localhost" - # port is unnecessary for connections via unix domain socket: - #port: 3306 + port: 3306 # if socket-path is set, it will be used instead of host:port #socket-path: "/var/run/mysqld/mysqld.sock" user: "oragono" diff --git a/oragono.yaml b/oragono.yaml index 9f4ed2f7..dfb799b4 100644 --- a/oragono.yaml +++ b/oragono.yaml @@ -684,8 +684,7 @@ datastore: mysql: enabled: false host: "localhost" - # port is unnecessary for connections via unix domain socket: - #port: 3306 + port: 3306 # if socket-path is set, it will be used instead of host:port #socket-path: "/var/run/mysqld/mysqld.sock" user: "oragono"