ETCDIR for sysutils/mqttwarn is not as expected

I modified my mqttwarn scripts today to ignore some messages.

When restarting it, it wouldn’t. No output whatsoever.

[20:07 mqtt01 dvl ~] % sudo service mqttwarn restart
mqttwarn not running? (check /var/run/mqttwarn/mqttwarn.pid).
Starting mqttwarn.
[20:07 mqtt01 dvl ~] % sudo ps auwwx  | grep warn
dvl          4191  0.0  0.0    13836  2408  1  S+J  20:07    0:00.00 grep warn

Eventually, I tried running it by hand:

[20:08 mqtt01 dvl ~] % sudo /usr/local/bin/mqttwarn
Traceback (most recent call last):
  File "/usr/local/bin/mqttwarn", line 8, in 
    sys.exit(run())
             ^^^^^
  File "/usr/local/lib/python3.11/site-packages/mqttwarn/commands.py", line 93, in run
    run_mqttwarn(configfile=options["--config-file"])
  File "/usr/local/lib/python3.11/site-packages/mqttwarn/commands.py", line 140, in run_mqttwarn
    config = load_configuration(configfile=configfile, name=scriptname)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/mqttwarn/configuration.py", line 262, in load_configuration
    raise FileNotFoundError('Configuration file "{}" does not exist'.format(configfile))
FileNotFoundError: Configuration file "mqttwarn.ini" does not exist

Where is that mqttwarn.ini?

[20:08 mqtt01 dvl ~] % locate mqttwarn.ini
/usr/local/etc/mqttwarn/mqttwarn.ini
/usr/local/etc/py311-mqttwarn/mqttwarn.ini
/usr/local/etc/py311-mqttwarn/mqttwarn.ini.sample
/usr/local/lib/python3.11/site-packages/mqttwarn/examples/basic/mqttwarn.ini

What’s this /usr/local/etc/py311-mqttwarn directory? That’s not right. It should not have that prefix.

[20:08 mqtt01 dvl ~] % pkg which /usr/local/etc/py311-mqttwarn/mqttwarn.ini.sample 
/usr/local/etc/py311-mqttwarn/mqttwarn.ini.sample was installed by package py311-mqttwarn-0.35.0_1

Installed by the package. That’s not right. I don’t know why this is the way it is:

[20:41 mydev dvl /usr/ports/sysutils/py-mqttwarn] % make -V ETCDIR           
/usr/local/etc/py311-mqttwarn

There’s nothing in here:

[20:41 mydev dvl /usr/ports/sysutils/py-mqttwarn] % grep -r ETCDIR *
Makefile:	${MKDIR} ${STAGEDIR}${ETCDIR}
Makefile:	${INSTALL_SCRIPT} ${WRKSRC}/mqttwarn/examples/basic/mqttwarn.ini ${STAGEDIR}${ETCDIR}/mqttwarn.ini.sample
Makefile:	@${ECHO_CMD} "@dir ${ETCDIR}" >> ${TMPPLIST}
Makefile:	@${ECHO_CMD} "@sample(mqttwarn,mqttwarn,0640) ${ETCDIR}/mqttwarn.ini.sample" >> ${TMPPLIST}

Back to getting it started

Next, I added the configuration file via full path:

[20:09 mqtt01 dvl ~] % sudo /usr/local/bin/mqttwarn --config-file=/usr/local/etc/mqttwarn/mqttwarn.ini
Traceback (most recent call last):
  File "/usr/local/bin/mqttwarn", line 8, in 
    sys.exit(run())
             ^^^^^
  File "/usr/local/lib/python3.11/site-packages/mqttwarn/commands.py", line 93, in run
    run_mqttwarn(configfile=options["--config-file"])
  File "/usr/local/lib/python3.11/site-packages/mqttwarn/commands.py", line 140, in run_mqttwarn
    config = load_configuration(configfile=configfile, name=scriptname)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/mqttwarn/configuration.py", line 273, in load_configuration
    return Config(configfile, defaults=defaults)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/mqttwarn/configuration.py", line 175, in __init__
    self.functions = load_functions(functions_file)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/mqttwarn/util.py", line 227, in load_functions
    py_mod = load_module_from_file(filepath)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/mqttwarn/util.py", line 156, in load_module_from_file
    loader.exec_module(mod)
  File "", line 936, in exec_module
  File "", line 1074, in get_code
  File "", line 1004, in source_to_code
  File "", line 241, in _call_with_frames_removed
  File "/usr/local/etc/mqttwarn/my-functions.py", line 26
    if data['user'] == 'dvl'::
                             ^
SyntaxError: invalid syntax

OK, I fixed my syntax error, and tried again:

[20:22 mqtt01 dvl /usr/local/etc/py311-mqttwarn] % sudo /usr/local/bin/mqttwarn --config-file=/usr/local/etc/mqttwarn/mqttwarn.ini
2025-10-12 20:22:47,887 INFO     [mqttwarn.commands         ] Starting mqttwarn
2025-10-12 20:22:47,887 INFO     [mqttwarn.commands         ] Log level is DEBUG
2025-10-12 20:22:47,887 DEBUG    [mqttwarn.core             ] Trying to load built-in service "file" from "file"
2025-10-12 20:22:47,890 DEBUG    [mqttwarn.core             ] Trying to load service "file" from file "/usr/local/lib/python3.11/site-packages/mqttwarn/services/file.py"
2025-10-12 20:22:47,891 INFO     [mqttwarn.core             ] Successfully loaded service "file"
2025-10-12 20:22:47,891 DEBUG    [mqttwarn.core             ] Trying to load built-in service "pushover" from "pushover"
2025-10-12 20:22:47,891 DEBUG    [mqttwarn.core             ] Trying to load service "pushover" from file "/usr/local/lib/python3.11/site-packages/mqttwarn/services/pushover.py"
2025-10-12 20:22:47,981 INFO     [mqttwarn.core             ] Successfully loaded service "pushover"
2025-10-12 20:22:47,981 DEBUG    [mqttwarn.core             ] Trying to load built-in service "log" from "log"
2025-10-12 20:22:47,981 DEBUG    [mqttwarn.core             ] Trying to load service "log" from file "/usr/local/lib/python3.11/site-packages/mqttwarn/services/log.py"
2025-10-12 20:22:47,983 INFO     [mqttwarn.core             ] Successfully loaded service "log"
2025-10-12 20:22:47,983 DEBUG    [mqttwarn.core             ] Attempting connection to MQTT broker mqtt01.int.unixathome.org:8883
2025-10-12 20:22:47,983 DEBUG    [mqttwarn.core             ] Setting LWT to clients/mqttwarn
2025-10-12 20:22:48,022 INFO     [mqttwarn.core             ] Starting 1 worker threads
2025-10-12 20:22:48,022 DEBUG    [mqttwarn.core             ] Job queue has 0 items to process
2025-10-12 20:22:48,023 DEBUG    [mqttwarn.core             ] Connected to MQTT broker, subscribing to topics
2025-10-12 20:22:48,023 DEBUG    [mqttwarn.core             ] Cleansession==False; previous subscriptions for clientid mqttwarn remain active on broker
2025-10-12 20:22:48,023 DEBUG    [mqttwarn.core             ] Subscribing to test/+ (qos=0)
2025-10-12 20:22:48,023 DEBUG    [mqttwarn.core             ] Subscribing to logging/hare (qos=0)
^C2025-10-12 20:22:49,681 DEBUG    [mqttwarn.core             ] Disconnecting from MQTT broker
2025-10-12 20:22:49,681 INFO     [mqttwarn.core             ] Clean disconnection from broker
2025-10-12 20:22:49,682 INFO     [mqttwarn.core             ] Waiting for queue to drain
2025-10-12 20:22:49,682 DEBUG    [mqttwarn.core             ] Exiting on signal 2

There, it’s running.

Fixing the rc.d start

To fix the start via service, I added a symlink.

[20:21 mqtt01 dvl /usr/local/etc/py311-mqttwarn] % ls -l
total 9
-rw-r-----  1 mqttwarn mqttwarn 3831 2024.06.29 15:51 mqttwarn.ini
-rw-r-----  1 mqttwarn mqttwarn 3831 2024.06.29 15:51 mqttwarn.ini.sample
[20:21 mqtt01 dvl /usr/local/etc/py311-mqttwarn] % sudo rm mqttwarn.ini
[20:21 mqtt01 dvl /usr/local/etc/py311-mqttwarn] % sudo ln -s ../mqttwarn/mqttwarn.ini .

The restart worked, ignore the check PID warning, that’s because I started it from the command line.

[20:22 mqtt01 dvl /usr/local/etc/py311-mqttwarn] % sudo service mqttwarn restart             
mqttwarn not running? (check /var/run/mqttwarn/mqttwarn.pid).
Starting mqttwarn.
[20:22 mqtt01 dvl /usr/local/etc/py311-mqttwarn] % sudo ps auwwx  | grep warn                      
mqttwarn    62059  4.6  0.0    55208 35888  -  SJ   20:22    0:00.30 /usr/local/bin/python3.11 /usr/local/bin/mqttwarn
mqttwarn    62058  0.2  0.0    13856  2376  -  SsJ  20:22    0:00.00 daemon: mqttwarn[62059] (daemon)
dvl         62086  0.0  0.0    13836  2400  1  S+J  20:22    0:00.00 grep warn

What I still don’t know: why is ETCDIR borked?

Website Pin Facebook Twitter Myspace Friendfeed Technorati del.icio.us Digg Google StumbleUpon Premium Responsive

Leave a Comment

Scroll to Top