I do want to use socat for directing serial commands over ethernet to a ethernet-serial converter (static ip adress). I was wondering which would a good way of starting socat.
If I understand everything correctly systemd would allow me to make sure socat is alway running or in case of failure, tries to restart. The .service file would look like:
[Service] Type=simple Restart=always RestartSec=5 [Unit] Description=my socat test User=me Group=me ExecStart=/bin/bash -c '~/my_socat.sh' [Install] WantedBy=multi-user.target
The script would look like
#!/bin/bash socat PTY,link=/home/me/dev/valve1 TCP:192.168.11.101:5001 & socat PTY,link=/home/me/dev/valve2 TCP:192.168.11.101:5002
Would this approach do what I want ? Would socat be restarted if it dies for some reason ? And what would happen if the ethernet connection is not available when socat is started ? Running it from the shell without network connection does not work and the command fails with the error message "network is unreachable".
How would you make sure socat is running before my (python) script is executed ? Would you start socat from within python ?