zm_event_start.sh: How to set mysql unix socket?

Forum for questions and support relating to the 1.34.x releases only.
Post Reply
User avatar
Bluemax
Posts: 121
Joined: Wed Jun 12, 2019 5:15 pm

zm_event_start.sh: How to set mysql unix socket?

Post by Bluemax »

I've initially set up ZMES/opencv doing the postinstall tests:

Code: Select all

$ sudo -u nginx /var/lib/zmeventnotification/bin/zm_event_start.sh 3211 1
  File "/usr/lib/python3.8/site-packages/mysql/connector/network.py", line 606, in open_connection
    self.sock.connect(sockaddr)
ConnectionRefusedError: [Errno 111] Connection refused

  File "/usr/lib/python3.8/site-packages/mysql/connector/network.py", line 608, in open_connection
    raise errors.InterfaceError(
mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on 'localhost:3306' (111 Connection refused)

  File "/usr/lib/python3.8/site-packages/pyzm/ZMLog.py", line 157, in init
    syslog.syslog (syslog.LOG_ERR, format_string("Turning DB logging off. Could not connect to DB, message was:" + str(e)))
NameError: name 'format_string' is not defined
1) Where do i configure the db connection to '/run/mysqld/mysqld.sock' (instead of 'localhost:3306')?

2) I've noticed that the script searches for '/etc/zm/zm.conf'. The ZMES created that folder itself (/etc/zm). My 'zm.conf' is at '/etc/zm.conf' though. Even if i symlink the file it doesn't honor the /etc/conf.d files (01-system-paths.conf, 02-multiserver.conf, 03-myconf.conf) that are mandatory as the 'zm.conf' says "DO NOT EDIT THIS FILE! Use conf.d instead". I've done so and Zoneminder works properly but ZMES doesn't seem to honor it. Is the conf.d concept abandoned or something? Can the ZMES be configured to a different zm.conf path?
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: zm_event_start.sh: How to set mysql unix socket?

Post by asker »

On 2)
I've just added the ability to make it easier to override settings.

pyzm as you know is not deeply integrated into ZM. There are several things that it doesn't have access to, one being what is the actual installed configuration path of config files. It assumes "/etc/zm" but in your case it is different. pyzm itself lets you override these settings, but you are using zm_detect which in turn uses pyzm and it is therefore not possible to change it unless you change zm_detect, which is undesirable.

I've now added a "config" option in objectconfig.ini called pyzm_overrides that lets you override all these settings. See https://github.com/pliablepixels/zmeven ... ig.ini#L18

Please upgrade via ./install.sh (this will also update pyzm to .17)


On 1) I don't understand.
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
User avatar
Bluemax
Posts: 121
Joined: Wed Jun 12, 2019 5:15 pm

Re: zm_event_start.sh: How to set mysql unix socket?

Post by Bluemax »

Thanks, will test that. I probably should send-in some upstream patches (to Alpine Linux) to get the ZM_CONFIG_DIR fixed.

Regarding question 1: I'm following your Test operation guide. 'zm_event_start.sh' seems to try to connect to the mysql database by network port (localhost:3306). Something i don't have. I have a local 'unix stream socket' instead (/run/mysqld/mysqld.sock). Its much faster and the better IPC approach (no network stack overhead). Maybe this can be solved with your new override patch already (by 'host' parameter). Will test that on the next attempt as well.

Actually, this is the full error message. The first lines are from 'opencv/bin/setup_vars_opencv4.sh' as i haven't installed the opencv python module globally yet ('import cv2' works properly).

Code: Select all

$ sudo -u nginx /var/lib/zmeventnotification/bin/zm_event_start.sh 3211 1
Setting vars for OpenCV 4.3.0-pre
Append PYTHONPATH: /var/lib/opencv/bin/../lib/python3.8/site-packages
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/mysql/connector/network.py", line 606, in open_connection
    self.sock.connect(sockaddr)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 2285, in _wrap_pool_connect
    return fn()
  File "/usr/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 303, in unique_connection
    return _ConnectionFairy._checkout(self)
  File "/usr/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 773, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
  File "/usr/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 492, in checkout
    rec = pool._do_get()
  File "/usr/lib/python3.8/site-packages/sqlalchemy/pool/impl.py", line 139, in _do_get
    self._dec_overflow()
  File "/usr/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__
    compat.raise_(
  File "/usr/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
    raise exception
  File "/usr/lib/python3.8/site-packages/sqlalchemy/pool/impl.py", line 136, in _do_get
    return self._create_connection()
  File "/usr/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 308, in _create_connection
    return _ConnectionRecord(self)
  File "/usr/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 437, in __init__
    self.__connect(first_connect_check=True)
  File "/usr/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 657, in __connect
    pool.logger.debug("Error on connect(): %s", e)
  File "/usr/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__
    compat.raise_(
  File "/usr/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
    raise exception
  File "/usr/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 652, in __connect
    connection = pool._invoke_creator(self)
  File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/strategies.py", line 114, in connect
    return dialect.connect(*cargs, **cparams)
  File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 488, in connect
    return self.dbapi.connect(*cargs, **cparams)
  File "/usr/lib/python3.8/site-packages/mysql/connector/__init__.py", line 219, in connect
    return MySQLConnection(*args, **kwargs)
  File "/usr/lib/python3.8/site-packages/mysql/connector/connection.py", line 104, in __init__
    self.connect(**kwargs)
  File "/usr/lib/python3.8/site-packages/mysql/connector/abstracts.py", line 960, in connect
    self._open_connection()
  File "/usr/lib/python3.8/site-packages/mysql/connector/connection.py", line 288, in _open_connection
    self._socket.open_connection()
  File "/usr/lib/python3.8/site-packages/mysql/connector/network.py", line 608, in open_connection
    raise errors.InterfaceError(
mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on 'localhost:3306' (111 Connection refused)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/pyzm/ZMLog.py", line 151, in init
    conn = engine.connect()
  File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 2218, in connect
    return self._connection_cls(self, **kwargs)
  File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 103, in __init__
    else engine.raw_connection()
  File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 2317, in raw_connection
    return self._wrap_pool_connect(
  File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 2288, in _wrap_pool_connect
    Connection._handle_dbapi_exception_noconnection(
  File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1554, in _handle_dbapi_exception_noconnection
    util.raise_(
  File "/usr/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
    raise exception
  File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 2285, in _wrap_pool_connect
    return fn()
  File "/usr/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 303, in unique_connection
    return _ConnectionFairy._checkout(self)
  File "/usr/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 773, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
  File "/usr/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 492, in checkout
    rec = pool._do_get()
  File "/usr/lib/python3.8/site-packages/sqlalchemy/pool/impl.py", line 139, in _do_get
    self._dec_overflow()
  File "/usr/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__
    compat.raise_(
  File "/usr/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
    raise exception
  File "/usr/lib/python3.8/site-packages/sqlalchemy/pool/impl.py", line 136, in _do_get
    return self._create_connection()
  File "/usr/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 308, in _create_connection
    return _ConnectionRecord(self)
  File "/usr/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 437, in __init__
    self.__connect(first_connect_check=True)
  File "/usr/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 657, in __connect
    pool.logger.debug("Error on connect(): %s", e)
  File "/usr/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__
    compat.raise_(
  File "/usr/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
    raise exception
  File "/usr/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 652, in __connect
    connection = pool._invoke_creator(self)
  File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/strategies.py", line 114, in connect
    return dialect.connect(*cargs, **cparams)
  File "/usr/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 488, in connect
    return self.dbapi.connect(*cargs, **cparams)
  File "/usr/lib/python3.8/site-packages/mysql/connector/__init__.py", line 219, in connect
    return MySQLConnection(*args, **kwargs)
  File "/usr/lib/python3.8/site-packages/mysql/connector/connection.py", line 104, in __init__
    self.connect(**kwargs)
  File "/usr/lib/python3.8/site-packages/mysql/connector/abstracts.py", line 960, in connect
    self._open_connection()
  File "/usr/lib/python3.8/site-packages/mysql/connector/connection.py", line 288, in _open_connection
    self._socket.open_connection()
  File "/usr/lib/python3.8/site-packages/mysql/connector/network.py", line 608, in open_connection
    raise errors.InterfaceError(
sqlalchemy.exc.InterfaceError: (mysql.connector.errors.InterfaceError) 2003: Can't connect to MySQL server on 'localhost:3306' (111 Connection refused)
(Background on this error at: http://sqlalche.me/e/rvf5)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/var/lib/zmeventnotification/bin/zm_detect.py", line 146, in <module>
    log.init(process_name='zmesdetect_' + 'm' + args['monitorid'])
  File "/usr/lib/python3.8/site-packages/zmes_hook_helpers/log.py", line 39, in init
    g.logger = wrapperLogger(name=process_name, dump_console=dump_console)
  File "/usr/lib/python3.8/site-packages/zmes_hook_helpers/log.py", line 10, in __init__
    zmlog.init(name=name)
  File "/usr/lib/python3.8/site-packages/pyzm/ZMLog.py", line 157, in init
    syslog.syslog (syslog.LOG_ERR, format_string("Turning DB logging off. Could not connect to DB, message was:" + str(e)))
NameError: name 'format_string' is not defined
Last edited by Bluemax on Sat Mar 21, 2020 9:58 pm, edited 1 time in total.
User avatar
asker
Posts: 1553
Joined: Sun Mar 01, 2015 12:12 pm

Re: zm_event_start.sh: How to set mysql unix socket?

Post by asker »

I think with the updated changes, it should automatically turn off DB logging if it can't connect instead of throwing an exception.
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
Post Reply