I can’t wait… The goal is to open the right random port so I used netstat to find out, which ports are open for madsonic:
[root@server ~]# netstat -tlpn | grep 4040 tcp6 0 0 :::4040 :::* LISTEN 5267/java [root@server ~]# netstat -tlpn | grep 5267 tcp6 0 0 :::4040 :::* LISTEN 5267/java tcp6 0 0 192.168.1.11:39277 :::* LISTEN 5267/java tcp6 0 0 :::37153 :::* LISTEN 5267/java tcp6 0 0 :::9412 :::* LISTEN 5267/java
The port 39277, the only one which is bound to an IP is the needed one, but the problem is:
So I tried to script it. The following commands worked on 2 of my Nethservers:
config set madsonic service MaxMemory 512 Name madsonic TCPPorts 4040,$(echo $(netstat -tlpn | grep $(netstat -tlpn | grep 4040 | cut -c 80-84 | awk '{$1=$1};1') | cut -d "." -f 4 | cut -d ":" -f 2)) UDPPort 1900 access green status enabled webaccess private signal-event firewall-adjust
My thoughts:
Madsonic is a java process, there may be more, so I get the correct madsonic PID out of netstat when searching for 4040.
With the PID I grep the lines, to have the open madsonic ports and echo puts them in one line.
Then I cut the 4th field with point as delimiter, which is the last number of the ip inclusive “:” and port. So just cut it with “:” and the second field is the port to open…
If it fails just run the next 2 lines to get back to the default settings for madsonic service:
config set madsonic service MaxMemory 512 Name madsonic TCPPort 4040 access green status enabled webaccess private signal-event firewall-adjust
When you start/restart madsonic your have to wait about 10 seconds, until madsonic fully comes up before you can run the command.
Worked with my LG TV and with VLC on Android…