mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Supply MySQL database hostname when using Unix sockets to connect (#7471)
* Supply MySQL database hostname when using Unix sockets to connect * Pass unix_socket parameter when db_socket is set * Set db_host to localhost when db_socket is set
This commit is contained in:
@@ -39,7 +39,7 @@ $config['db_port']=$dbport;
|
||||
$config['db_socket']=$dbsocket;
|
||||
|
||||
if (!empty($config['db_socket'])) {
|
||||
$config['db_host'] = '';
|
||||
$config['db_host'] = 'localhost';
|
||||
$config['db_port'] = null;
|
||||
} else {
|
||||
$config['db_socket'] = null;
|
||||
|
@@ -79,12 +79,9 @@ db_username = config['db_user']
|
||||
db_password = config['db_pass']
|
||||
db_port = int(config['db_port'])
|
||||
|
||||
if config['db_host'][:5].lower() == 'unix:':
|
||||
if config['db_socket']:
|
||||
db_server = config['db_host']
|
||||
db_port = 0
|
||||
elif config['db_socket']:
|
||||
db_server = config['db_socket']
|
||||
db_port = 0
|
||||
db_socket = config['db_socket']
|
||||
else:
|
||||
db_server = config['db_host']
|
||||
|
||||
@@ -93,8 +90,8 @@ db_dbname = config['db_name']
|
||||
|
||||
def db_open():
|
||||
try:
|
||||
if db_port == 0:
|
||||
db = MySQLdb.connect(host=db_server, user=db_username, passwd=db_password, db=db_dbname)
|
||||
if db_socket:
|
||||
db = MySQLdb.connect(host=db_server, unix_socket=db_socket, user=db_username, passwd=db_password, db=db_dbname)
|
||||
else:
|
||||
db = MySQLdb.connect(host=db_server, port=db_port, user=db_username, passwd=db_password, db=db_dbname)
|
||||
return db
|
||||
|
Reference in New Issue
Block a user