[
https://issues.apache.org/jira/browse/SOLR-10390?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15948284#comment-15948284
]
Robert Muir commented on SOLR-10390:
------------------------------------
I usually prefer to poll ports with 'nc -z', but netcat is not always
available, or sometimes the nmap ncat imposter (e.g. centos linux)
The script already depends on bash though. Using just bash you can redirect to
ports (see
https://www.gnu.org/software/bash/manual/html_node/Redirections.html) and test
the exit code.
I tend to use loops such as the following to test/wait for services:
{noformat}
# await port availability (but only so long)
for i in {1..5}; do
if (timeout 1 bash -c "echo > /dev/tcp/localhost/1234") then
break
fi
sleep 1
done
# ensure we made it
timeout 1 bash -c "echo > /dev/tcp/localhost/1234"
{noformat}
> lsof has too many kernel dependencies
> -------------------------------------
>
> Key: SOLR-10390
> URL: https://issues.apache.org/jira/browse/SOLR-10390
> Project: Solr
> Issue Type: Bug
> Security Level: Public(Default Security Level. Issues are Public)
> Reporter: Felipe Gasper
>
> lsof seems a very "heavy" solution for just checking whether a socket is
> open. In Linux in particular it's problematic because there are kernel
> options that will break lsof, e.g. CloudLinux's *kernel.user_ptrace* and
> *kernel.user_ptrace_self* options.
> If all that's needed here is a simple connect() to the socket, what about
> shipping something simple like this:
> {code}
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <sys/types.h>
> #include <sys/socket.h>
> #include <netinet/in.h>
> #include <netdb.h>
> void _fail() {
> exit(EXIT_FAILURE);
> }
> void error(const char *msg) {
> perror(msg);
> _fail();
> }
> int main(int argc, char *argv[]) {
> int sockfd, portno, n;
> struct sockaddr_in serv_addr;
> struct hostent *server;
> char buffer[256];
> if (argc < 3) {
> fprintf(stderr,"usage %s hostname port\n", argv[0]);
> _fail();
> }
> portno = atoi(argv[2]);
> sockfd = socket(AF_INET, SOCK_STREAM, 0);
> if (sockfd < 0) {
> error("ERROR opening socket");
> }
> server = gethostbyname(argv[1]);
> if (server == NULL) {
> fprintf(stderr,"ERROR: no such host\n");
> _fail();
> }
> bzero((char *) &serv_addr, sizeof(serv_addr));
> serv_addr.sin_family = AF_INET;
> bcopy((char *)server->h_addr,
> (char *)&serv_addr.sin_addr.s_addr,
> server->h_length);
> serv_addr.sin_port = htons(portno);
> if (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0)
> {
> error("ERROR connecting");
> }
> fprintf(stdout, "OK\n");
> return EXIT_SUCCESS;
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]