modbus-proxy icon indicating copy to clipboard operation
modbus-proxy copied to clipboard

Systemd service does not work as described

Open winfriedp opened this issue 2 years ago • 9 comments

  • ModBus TCP proxy version: 0.6.8
  • Python version: 3.9
  • Operating System: Raspberry Pi OS Bullseye v11.5

Description

The service configuration does not work when installing modbus-proxy according to the instructions. I get an ModuleNotFoundError: No module named 'modbus_proxy'. The reason is that modbus-proxy is installed in a local user directory, but the service is run by the user root and root does not know the local directory. I am not a python expert and I have not found a solution to adjust the environment variables so that root can handle them.

What I Did

I solved the problem by installing modbus-proxy as user root as follows: sudo su pip3 install modbus-proxy

Then the package will be installed in /usr/local/bin/ and /usr/local/lib/python3.9/dist-packages Now the service can be started without error. This workaround is OK for me, but maybe there are other suggestions from python experts to make this service work.

winfriedp avatar Dec 15 '22 13:12 winfriedp

I cannot start the service. First I did as stated in the documentation, status failed. Then I saw your report and uninstalled modbus-proxy as a user and reinstalled as root. I also tried to use absolute paths, but no success. When I run from bash, everything is fine.

● mproxy.service loaded failed failed Modbus-Proxy

My mproxy.service (in etc/system/systemd) looks like this:

[Unit]
Description=Modbus-Proxy
After=network.target

[Service]
Type=simple
Restart=always
ExecStart = /usr/local/bin/modbus-proxy -c /usr/lib/mproxy-conf.yaml

[Install]
WantedBy=multi-user.target

Any ideas?

requiemmg avatar Jan 14 '23 14:01 requiemmg

The only difference to my service definition is the ExecStart command. Try ExecStart = modbus-proxy -c ./usr/lib/mproxy-conf.yaml I guess it's only the missing dot before the slash.

winfriedp avatar Jan 14 '23 22:01 winfriedp

Did so, still failing and I dont know why as it runs smoothly from the command line.

requiemmg avatar Jan 15 '23 09:01 requiemmg

Could you send the systemctl log:

journalctl -u mproxy > /tmp/mproxy-log.txt

tiagocoutinho avatar Jan 15 '23 20:01 tiagocoutinho

Sure, no problem. I have it working now with a modbus-proxy fork for Home Assistant.

mproxy.log.txt

requiemmg avatar Jan 15 '23 20:01 requiemmg

looks like you installed modbus-proxy on root without yaml support. Maybe you did something like: sudo pip install modbus-proxy

You need to do instead: sudo pip install modbus-proxy[yaml]

tiagocoutinho avatar Jan 15 '23 20:01 tiagocoutinho

Thanks for the clarification!

requiemmg avatar Jan 15 '23 20:01 requiemmg

I had also issues but with the help of this thread I was able to solve them. Anyway it might be better do enhance the README File

thaichho avatar Jan 16 '24 21:01 thaichho

@tiagocoutinho why don't you do that with a PR on this repo and more information? :-)

Richigeht avatar Feb 12 '24 21:02 Richigeht