[dev.icinga.com #1107] add db socket as config option in ido2db.cfg for mysql and postgresql #507

Closed
icinga-migration opened this Issue Jan 12, 2011 · 7 comments

Projects

None yet

1 participant

@icinga-migration
Member

This issue has been migrated from Redmine: https://dev.icinga.com/issues/1107

Created by mfriedrich on 2011-01-12 14:35:24 +00:00

Assignee: mfriedrich
Status: Resolved (closed on 2011-03-23 15:10:58 +00:00)
Target Version: 1.4
Last Update: 2014-12-08 14:46:12 +00:00 (in Redmine)


props to sven nierlein

evaluate if possible for libdbi/libpq/ocilib

diff --git a/include/db.h b/include/db.h
index 650b3a5..d82ef31 100644
--- a/include/db.h
+++ b/include/db.h
@@ -20,6 +20,7 @@ typedef struct ndo2db_dbconfig_struct{
  char *password;
  char *dbname;
  char *dbprefix;
+ char *dbsocket;
  unsigned long max_timedevents_age;
  unsigned long max_systemcommands_age;
  unsigned long max_servicechecks_age;
diff --git a/src/db.c b/src/db.c
index e06afc1..8fb74e5 100644
--- a/src/db.c
+++ b/src/db.c
@@ -206,7 +206,7 @@ int ndo2db_db_connect(ndo2db_idi *idi){
  switch(idi->dbinfo.server_type){
  case NDO2DB_DBSERVER_MYSQL:
 #ifdef USE_MYSQL
-   if(!mysql_real_connect(&idi->dbin-fo.mysql_conn,ndo2db_db_settings.host,ndo2db_db_settings.username,ndo2db_db_settings.password,ndo2db_db_settings.dbname,ndo2db_db_settings.port,NULL,0)){
+   if(!mysql_real_connect(&idi->dbin-fo.mysql_conn,ndo2db_db_settings.host,ndo2db_db_settings.username,ndo2db_db_settings.password,ndo2db_db_settings.dbname,ndo2db_db_settings.port,ndo2db_db_settings.dbsocket,0)){

      mysql_close(&idi->dbinfo.mysql_conn);
      syslog(LOG_USER|LOG_INFO,"Error: Could not connect to MySQL database: %s",mysql_error(&idi->dbinfo.mysql_conn));
diff --git a/src/ndo2db.c b/src/ndo2db.c
index f4c6499..dfd3151 100644
--- a/src/ndo2db.c
+++ b/src/ndo2db.c
@@ -417,6 +417,10 @@ int ndo2db_process_config_var(char *arg){
  else if(!strcmp(var,"db_port")){
    ndo2db_db_settings.port=atoi(val);
          }
+ else if(!strcmp(var,"db_socket")){
+   if((ndo2db_db_settings.dbsocket=strdup(val))==NULL)
+     return NDO_ERROR;
+         }
  else if(!strcmp(var,"db_user")){
    if((ndo2db_db_settings.username=strdup(val))==NULL)
      return NDO_ERROR;

Changesets

2011-03-23 14:09:30 +00:00 by mfriedrich b3422ee

idoutils: add db socket as config option in ido2db.cfg for mysql and postgresql #1107

fixes #1107
Member

Updated by mfriedrich on 2011-01-20 11:48:04 +00:00

  • Status changed from New to Assigned
  • Assigned to set to mfriedrich

libdbi mysql

http://libdbi-drivers.sourceforge.net/docs/dbd\_mysql.pdf

mysql_unix_socket

so this might be implemented against mysql only.

Member

Updated by mfriedrich on 2011-03-16 17:44:05 +00:00

  • Target Version set to 1.4
Member

Updated by mfriedrich on 2011-03-23 13:28:38 +00:00

  • Done % changed from 0 to 50

added db_socket in cfg, commented out db_port. then changed in my.cnf the default socket to something else.

# service ido2db stop
# vim /etc/my.cnf
# service mysqld restart (only do that on a test system with all write processes stopped!!)
# service ido2db

Mar 23 14:11:17 xxx ido2db: Error: Could not connect to mysql database: 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Mar 23 14:11:17 xxx ido2db: Error: database connection failed, forced client disconnect... 

give it the correct socket like from my.cnf

#socket=/var/lib/mysql/mysql.sock
socket=/var/run/mysql/mysql.sock

into ido2db.cfg

#db_port=3306

db_socket=/var/run/mysql/mysql.sock

looks good :)

Mar 23 14:26:17 xxx ido2db: Handling client connection... 
Mar 23 14:26:17 xxx ido2db: Successfully connected to mysql database

need to test that on pgsql too, where the port just gets overwritten.

http://libdbi-drivers.sourceforge.net/docs/dbd\_pgsql/options.html

Member

Updated by mfriedrich on 2011-03-23 14:01:46 +00:00

  • Done % changed from 50 to 90

the default pgsql socket is in /tmp/ named .s.PGSQL.5432

as it seems you can't change the name, but the unix_socket_directory in /var/lib/pgsql/data/postgresql.conf and restart the server.

doing this, and using the db_socket directive with the appropriate value, it takes the socket and connects flawlessly.

Member

Updated by mfriedrich on 2011-03-23 14:06:22 +00:00

  • Subject changed from add db socket as config option to add db socket as config option in ido2db.cfg for mysql and postgresql
  • Category set to 26
Member

Updated by mfriedrich on 2011-03-23 15:10:58 +00:00

  • Status changed from Assigned to Resolved
  • Done % changed from 90 to 100

Applied in changeset b3422ee.

Member

Updated by mfriedrich on 2014-12-08 14:46:12 +00:00

  • Project changed from 18 to Core, Classic UI, IDOUtils
  • Category changed from 26 to IDOUtils
@icinga-migration icinga-migration added this to the 1.4 milestone Jan 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment