[ 
https://issues.apache.org/jira/browse/KAFKA-4566?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17884103#comment-17884103
 ] 

Alex Russell edited comment on KAFKA-4566 at 9/24/24 4:21 AM:
--------------------------------------------------------------

readlink -f appears to be equivalent on both (my) MacOS and (a) RHEL9 (within 
podman). The difference -f on MacOS is it canonicalizes every component of the 
path, and -f on RHEL canonicalizes every component except the last (which 
doesn't need to exist). So could we consider readlink -f:
{code:java}
exec $(dirname "$(readlink -f "$0")")/kafka-run-class.sh 
kafka.tools.ConsoleConsumer "$@"{code}
I've tested this (on my Mac):
{code:java}
% ls -l kafka-tmp
lrwxr-xr-x  1 arussell  staff  5 23 Sep 14:32 kafka-tmp -> kafka
% ls -l kafka/tmp.sh
-rwxr-x---  1 arussell  staff  30 23 Sep 14:33 kafka/tmp.sh
% cat kafka/tmp.sh
dirname "$(readlink -f "$0")"
% sh kafka-tmp/tmp.sh
/Users/arussell/itfromblighty.ca/repositories/kafka
%
{code}
This should be sufficient to get the canonicalized path (directory) before 
appending the script we want to run.

I've tested this on RHEL(9) too (podman):
{code:java}
[root@521794cc118e /]# ls -l kafka-tmp
lrwxrwxrwx. 1 root root 5 Sep 24 04:12 kafka-tmp -> kafka
[root@521794cc118e /]# ls -l kafka/tmp.sh
-rw-r--r--. 1 root root 30 Sep 24 04:11 kafka/tmp.sh
[root@521794cc118e /]# cat kafka/tmp.sh
dirname "$(readlink -f "$0")"
[root@521794cc118e /]# sh kafka-tmp/tmp.sh
/kafka
[root@521794cc118e /]#
{code}
Could this (still) help people keep their configurations and logs separate 
(presumably still with shared binaries), or did some facility to allow for 
different configuration and logs get provided-for by some other means? Because 
I don't think it matters that the last component of the path may not exist (via 
RHEL's readlink -e) as we strip it off anyway with dirname (for basename $0 - 
this approach with -f and -e's difference/s might be a blocker)


was (Author: JIRAUSER307110):
readlink -f appears to be equivalent on both (my) MacOS and (a) RHEL9 (within 
podman). The difference -f on MacOS is it canonicalizes every component of the 
path, and -f on RHEL canonicalizes every component except the last (which 
doesn't need to exist). so could we consider:

 
{code:java}
exec $(dirname "$(readlink -f "$0")")/kafka-run-class.sh 
kafka.tools.ConsoleConsumer "$@"{code}
 

 

I've tested this (on my Mac):

 
{code:java}
% ls -l kafka-tmp
lrwxr-xr-x  1 arussell  staff  5 23 Sep 14:32 kafka-tmp -> kafka
% ls -l kafka/tmp.sh
-rwxr-x---  1 arussell  staff  30 23 Sep 14:33 kafka/tmp.sh
% cat kafka/tmp.sh
dirname "$(readlink -f "$0")"
% sh kafka-tmp/tmp.sh
/Users/arussell/itfromblighty.ca/repositories/kafka
%
{code}
 

This should be sufficient to get the canonicalized path (directory) before 
appending the script we want to run.

I've tested this on RHEL(9) too (podman):

 
{code:java}
[root@521794cc118e /]# ls -l kafka-tmp
lrwxrwxrwx. 1 root root 5 Sep 24 04:12 kafka-tmp -> kafka
[root@521794cc118e /]# ls -l kafka/tmp.sh
-rw-r--r--. 1 root root 30 Sep 24 04:11 kafka/tmp.sh
[root@521794cc118e /]# cat kafka/tmp.sh
dirname "$(readlink -f "$0")"
[root@521794cc118e /]# sh kafka-tmp/tmp.sh
/kafka
[root@521794cc118e /]#
{code}
 

Could this (still) help people keep their configurations and logs separate 
(presumably still with shared binaries), or did some facility to allow for 
different configuration and logs get provided-for by some other means? Because 
I don't think it matters that the last component of the path may not exist (via 
RHEL's readlink -e) as we strip it off anyway with dirname (for basename $0 - 
this approach with -f and -e's difference/s might be a blocker)

> Can't Symlink to Kafka bins
> ---------------------------
>
>                 Key: KAFKA-4566
>                 URL: https://issues.apache.org/jira/browse/KAFKA-4566
>             Project: Kafka
>          Issue Type: Bug
>          Components: tools
>    Affects Versions: 0.10.1.1
>            Reporter: Stephane Maarek
>            Assignee: Akhilesh Naidu
>            Priority: Major
>              Labels: newbie
>
> in the kafka consumer for example, the last line is :
> https://github.com/apache/kafka/blob/trunk/bin/kafka-console-consumer.sh#L21
> {code}
> exec $(dirname $0)/kafka-run-class.sh kafka.tools.ConsoleConsumer "$@"
> {code}
> if I create a symlink using 
> {code}
> ln -s
> {code}
> it doesn't resolve the right directory name because of $(dirname $0) 
> I believe the right way is to do:
> {code}
> "$(dirname "$(readlink -e "$0")")"
> {code}
>  
> Any thoughts on that before I do a PR?



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to