You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by J P <jp...@gmail.com> on 2021/11/11 16:43:27 UTC

Bug in AMQ 5.16.3 Linux start script?

Isn't there a bug in the ActiveMQ-5.16.3 Linux start-script?

bin/activemq, line 485 reads:

       local RET="`ps -o "pid,args" | grep "^\s*$activemq_pid\s.*java"`"

The problem is (from ps man page):

"By default, ps selects all processes with the same effective user
ID (euid=EUID) as the current user and associated with the same
terminal as the invoker."

Thus, the script essentially will ONLY find a running process
that has been started by the SAME LOGIN-SESSION.

I would say, that is rarely (if ever) the case in real-world scenarios.

For example, you login to your app-server and start ActiveMQ, then logout.
At a later point, you login again (new session) and try to stop ActiveMQ.
But unexpectedly, nothing happens :(

The fix was simple, in the line above, add the '-e' flag:

       local RET="`ps -eo "pid,args" | grep "^\s*$activemq_pid\s.*java"`"

ps -e means it will list ALL processes on the host.
Then it works as expected.

Re: Bug in AMQ 5.16.3 Linux start script?

Posted by JB Onofré <jb...@nanthrax.net>.
Hi

I don’t think we changed that in 5.16.3. I will check (I have Mac and Linux machines to test). 

I will keep you posted. 

Regards 
JB

> Le 11 nov. 2021 à 17:43, J P <jp...@gmail.com> a écrit :
> 
> Isn't there a bug in the ActiveMQ-5.16.3 Linux start-script?
> 
> bin/activemq, line 485 reads:
> 
>       local RET="`ps -o "pid,args" | grep "^\s*$activemq_pid\s.*java"`"
> 
> The problem is (from ps man page):
> 
> "By default, ps selects all processes with the same effective user
> ID (euid=EUID) as the current user and associated with the same
> terminal as the invoker."
> 
> Thus, the script essentially will ONLY find a running process
> that has been started by the SAME LOGIN-SESSION.
> 
> I would say, that is rarely (if ever) the case in real-world scenarios.
> 
> For example, you login to your app-server and start ActiveMQ, then logout.
> At a later point, you login again (new session) and try to stop ActiveMQ.
> But unexpectedly, nothing happens :(
> 
> The fix was simple, in the line above, add the '-e' flag:
> 
>       local RET="`ps -eo "pid,args" | grep "^\s*$activemq_pid\s.*java"`"
> 
> ps -e means it will list ALL processes on the host.
> Then it works as expected.


Re: Bug in AMQ 5.16.3 Linux start script?

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi,

FYI, I created

https://issues.apache.org/jira/browse/AMQ-8425

related to that and I will fix for 5.16.4.

Regards
JB

On 11/11/2021 17:43, J P wrote:
> Isn't there a bug in the ActiveMQ-5.16.3 Linux start-script?
> 
> bin/activemq, line 485 reads:
> 
>         local RET="`ps -o "pid,args" | grep "^\s*$activemq_pid\s.*java"`"
> 
> The problem is (from ps man page):
> 
> "By default, ps selects all processes with the same effective user
> ID (euid=EUID) as the current user and associated with the same
> terminal as the invoker."
> 
> Thus, the script essentially will ONLY find a running process
> that has been started by the SAME LOGIN-SESSION.
> 
> I would say, that is rarely (if ever) the case in real-world scenarios.
> 
> For example, you login to your app-server and start ActiveMQ, then logout.
> At a later point, you login again (new session) and try to stop ActiveMQ.
> But unexpectedly, nothing happens :(
> 
> The fix was simple, in the line above, add the '-e' flag:
> 
>         local RET="`ps -eo "pid,args" | grep "^\s*$activemq_pid\s.*java"`"
> 
> ps -e means it will list ALL processes on the host.
> Then it works as expected.
> 

Re: Bug in AMQ 5.16.3 Linux start script?

Posted by Justin Bertram <jb...@apache.org>.
According to the PR [1] (and the commit message) this change was made in
order to make the script work with busybox. However, according to the
documentation [2] the only options which ps supports on busybox is -o and
-t. In other words, it doesn't support -e (i.e. the change being suggested
here). The original PR was sent way back in 2016 and it was only merged
this year so it may be that the author doesn't even care any more about
this, but "fixing" this will break the script on busybox (again).


Justin

[1] https://github.com/apache/activemq/pull/199
[2] https://www.busybox.net/downloads/BusyBox.html

On Thu, Nov 11, 2021 at 12:31 PM JB Onofré <jb...@nanthrax.net> wrote:

> Yes I remember the change but it was ok afair. Let me check if it’s not an
> assuming option/version of ps.
>
> I will fix that for 5.16.4.
>
> Regards
> JB
>
> > Le 11 nov. 2021 à 19:02, J P <jp...@gmail.com> a écrit :
> >
> > Hi JB.
> > I checked the previous versions -- yes, you are right.
> > The change is between 5.16.1 and 5.16.2.
> >
> > In 5.16.1, the script uses:
> >   ps -p {process-id} -- that also works fine, since it doesn't care which
> > session started the process.
> >
> > In 5.16.2, the script is identical to 5.16.3.
> >   So it was 5.16.2 that introduced this issue.
> >
> > ---------------
> >
> > |   Hi
> > |   I don’t think we changed that in 5.16.3. I will check (I have Mac and
> > Linux machines to test).
> > |   I will keep you posted.
> > |   Regards
> > |   JB
>
>

Re: Bug in AMQ 5.16.3 Linux start script?

Posted by JB Onofré <jb...@nanthrax.net>.
Yes I remember the change but it was ok afair. Let me check if it’s not an assuming option/version of ps. 

I will fix that for 5.16.4. 

Regards
JB

> Le 11 nov. 2021 à 19:02, J P <jp...@gmail.com> a écrit :
> 
> Hi JB.
> I checked the previous versions -- yes, you are right.
> The change is between 5.16.1 and 5.16.2.
> 
> In 5.16.1, the script uses:
>   ps -p {process-id} -- that also works fine, since it doesn't care which
> session started the process.
> 
> In 5.16.2, the script is identical to 5.16.3.
>   So it was 5.16.2 that introduced this issue.
> 
> ---------------
> 
> |   Hi
> |   I don’t think we changed that in 5.16.3. I will check (I have Mac and
> Linux machines to test).
> |   I will keep you posted.
> |   Regards
> |   JB


Re: Bug in AMQ 5.16.3 Linux start script?

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
By the way, I will create a Jira about that.

Regards
JB

On 18/11/2021 15:08, Jean-Baptiste Onofré wrote:
> Hi,
> 
> It depends how you start activemq.
> 
> If you use your own script, or bin/activemq console, or wrapper, it works.
> 
> For instance, I rarely use bin/activemq start|stop.
> 
> Anyway, a fix is required for sure, probably testing the environment.
> 
> I will fix that for 5.16.4.
> 
> Regards
> JB
> 
> On 11/11/2021 21:04, J P wrote:
>> hmm... then at least I understand why the script is like it is :)
>>
>> Still, I am surprised if no one else has already reported this;
>> to me the script as it stands, seems quite unworkable in any
>> real-world/prod environment...
>>
>> If one can somehow detect that the environment is busybox (uname -a ,
>> perhaps?),
>> one could decide whether to include the -e flag or not.
>>
>> Otherwise, I think something like this would work as a generic fix?
>>
>> ps -e > /dev/null 2>&1
>> status=$?
>> if [[ "0" = "$status" ]]; then
>>    local RET="`ps -eo "pid,args" | grep "^\s*$activemq_pid\s.*java"`"
>> else
>>    local RET="`ps -o "pid,args"  | grep "^\s*$activemq_pid\s.*java"`"
>> fi
>>

Re: Bug in AMQ 5.16.3 Linux start script?

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi,

It depends how you start activemq.

If you use your own script, or bin/activemq console, or wrapper, it works.

For instance, I rarely use bin/activemq start|stop.

Anyway, a fix is required for sure, probably testing the environment.

I will fix that for 5.16.4.

Regards
JB

On 11/11/2021 21:04, J P wrote:
> hmm... then at least I understand why the script is like it is :)
> 
> Still, I am surprised if no one else has already reported this;
> to me the script as it stands, seems quite unworkable in any
> real-world/prod environment...
> 
> If one can somehow detect that the environment is busybox (uname -a ,
> perhaps?),
> one could decide whether to include the -e flag or not.
> 
> Otherwise, I think something like this would work as a generic fix?
> 
> ps -e > /dev/null 2>&1
> status=$?
> if [[ "0" = "$status" ]]; then
>    local RET="`ps -eo "pid,args" | grep "^\s*$activemq_pid\s.*java"`"
> else
>    local RET="`ps -o "pid,args"  | grep "^\s*$activemq_pid\s.*java"`"
> fi
> 

Re: Bug in AMQ 5.16.3 Linux start script?

Posted by J P <jp...@gmail.com>.
hmm... then at least I understand why the script is like it is :)

Still, I am surprised if no one else has already reported this;
to me the script as it stands, seems quite unworkable in any
real-world/prod environment...

If one can somehow detect that the environment is busybox (uname -a ,
perhaps?),
one could decide whether to include the -e flag or not.

Otherwise, I think something like this would work as a generic fix?

ps -e > /dev/null 2>&1
status=$?
if [[ "0" = "$status" ]]; then
  local RET="`ps -eo "pid,args" | grep "^\s*$activemq_pid\s.*java"`"
else
  local RET="`ps -o "pid,args"  | grep "^\s*$activemq_pid\s.*java"`"
fi

Re: Bug in AMQ 5.16.3 Linux start script?

Posted by Justin Bertram <jb...@apache.org>.
FWIW, here's the commit [1] that changed it.


Justin

[1]
https://github.com/apache/activemq/commit/2d78f118d059cbf3fe62d12fb344721820be0f9c

On Thu, Nov 11, 2021 at 12:02 PM J P <jp...@gmail.com> wrote:

> Hi JB.
> I checked the previous versions -- yes, you are right.
> The change is between 5.16.1 and 5.16.2.
>
> In 5.16.1, the script uses:
>    ps -p {process-id} -- that also works fine, since it doesn't care which
> session started the process.
>
> In 5.16.2, the script is identical to 5.16.3.
>    So it was 5.16.2 that introduced this issue.
>
> ---------------
>
> |   Hi
> |   I don’t think we changed that in 5.16.3. I will check (I have Mac and
> Linux machines to test).
> |   I will keep you posted.
> |   Regards
> |   JB
>

Re: Bug in AMQ 5.16.3 Linux start script?

Posted by J P <jp...@gmail.com>.
Hi JB.
I checked the previous versions -- yes, you are right.
The change is between 5.16.1 and 5.16.2.

In 5.16.1, the script uses:
   ps -p {process-id} -- that also works fine, since it doesn't care which
session started the process.

In 5.16.2, the script is identical to 5.16.3.
   So it was 5.16.2 that introduced this issue.

---------------

|   Hi
|   I don’t think we changed that in 5.16.3. I will check (I have Mac and
Linux machines to test).
|   I will keep you posted.
|   Regards
|   JB