Discourse-setup using netcat with illegal option combination?

AI-generated summary

The user steinhh encountered an issue with the Discourse setup script on CentOS 7, where the nc command failed with “nc: cannot use -p and -l” when testing ports 80 and 443. The problem arises because CentOS uses netcat-traditional, which does not support the -p and -l options together, unlike netcat-openbsd. steinhh resolved it by removing netcat-traditional and installing nmap-ncat, which provides the required functionality. pfaffman noted the inconsistency between different netcat implementations and highlighted why Ubuntu is often recommended for Discourse installations.

Using the standard discourse/docs/INSTALL-cloud.md at main · discourse/discourse · GitHub installation procedure on Centos 7, but:

The network connectivity on ports 80 & 443 is tested with nc thus:

    echo -e "HTTP/1.1 200 OK\n\n $VERIFY" | nc -w 4 -l -p $PORT >/dev/null 2>&1 &
    if curl --proto =http -s $HOST:$PORT --connect-timeout 3 | grep $VERIFY >/dev/null 2>&1; then
:

But nc fails with

nc: cannot use -p and -l

making the setup script report unavailability on those ports.

man nc says:

     -l      Listen for an incoming connection rather than initiating a connection to a remote host.  Cannot be used together with any of the options -psxz.  Additionally, any timeouts specified
             with the -w option are ignored.

It may be an nc version problem, I see NC does not say that there’s any conflict with the two. My netcat can listen, but only using

nc -w 4 -l <IP address> <port number>

Can’t get netcat to tell me its version number :confused:

Ok, so… there’s netcat-traditional and netcat-openbsd, and centos comes with the first, whereas discourse-setup needs the latter. Trying to find a way to get netcat-openbsd on centos, not a straightforward thing it appears…

Long story short:
yum remove netcat
yum install nmap-ncat

That’s part of why Ubuntu is recommended.

But how annoying is it that there are two netcats? And your default netcat seems especially hard to use.

Good working figuring that one out!