Hi,
Background: I have a home battery that needs connection to my utility meter that monitors my current energy usage from/to the grid.
The battery searches for the utility meter in the same subnet via the broadcast address.
However, the battery and utility meter are not in the same subnet.
The app for the battery does not allow manually inputting an IP.
Therefor I am using socat to relay that broadcast package to the utility meter which allows them to find each other:
socat UDP4-RECVFROM:1010,fork UDP4-SENDTO:10.10.10.111:1010 &
Problem: I want to run socat, in the background, on startup.
So far I have tried 2 things:
1. Creating an rc service as /usr/local/etc/rc.d/socat_discovery
Contents:
#!/bin/sh
# PROVIDE: socat_discovery
# REQUIRE: LOGIN DAEMON
# KEYWORD: shutdown
. /etc/rc.subr
name="socat_discovery"
rcvar="socat_discovery_enable"
command="/usr/local/bin/socat"
command_args="UDP4-RECVFROM:1010,reuseaddr,fork UDP4-SENDTO:10.10.10.111:1010 &"
pidfile="/var/run/${name}.pid"
load_rc_config ${name}
run_rc_command "$@"
I also added socat_discovery_enable="YES" into /etc/rc.conf.local
This works when running ./socat_discovery start but even though the service is mentioned in the startup log of OPNsense as "Starting socat_discovery", once I login to the terminal, socat is not actually running.
Indicated by ps -awx | grep socat and pgrep socat not returning anything and the battery not being able to find the utility meter.
I checked the permissions and no errors are printed.
I tried adding $> /var/log/socat_discovery.log to the command but even though the file was created, nothing was written in the log file.
2. Adding rc.syshook
According to this (https://docs.opnsense.org/development/backend/autorun.html) page, I can also create a syshook to autorun a script.
I added a file named "90-socat" in the start directory with the following contents:
#!/bin/sh
/usr/local/bin/socat UDP4-RECVFROM:1010,reuseaddr,fork UDP4-SENDTO:10.10.10.111:1010 &
And here as well, the script is mentioned in the start-up log of OPNsense but once I get into the terminal, it is not actually running.
No further errors here as well. I made sure to add execution permissions to the file.
When both the service and syshook are defined, a message that the port is in use is displayed in the start-up log of OPNsense.
This indicates that the scripts are ran, but somehow they are being stopped.
How can I debug this?
Thanks in advance! :)