You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@ambari.apache.org by Dmitro Lisnichenko <dl...@hortonworks.com> on 2017/02/08 14:50:57 UTC

Re: Review Request 56059: Broken kill_process_with_children shell single liner

-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/56059/
-----------------------------------------------------------

(Updated Feb. 8, 2017, 4:50 p.m.)


Review request for Ambari, Alejandro Fernandez, Andrew Onischuk, Dmytro Grinenko, Jonathan Hurley, and Nate Cole.


Changes
-------

Removed yum&rpm staff, left only python implementation


Summary (updated)
-----------------

Broken kill_process_with_children shell single liner


Bugs: AMBARI-19768
    https://issues.apache.org/jira/browse/AMBARI-19768


Repository: ambari


Description (updated)
-------

This single liner does not work correctly in some cases
{code}    CMD = """ps xf | awk -v PID=""" + str(pid) + \
          """ ' $1 == PID { P = $1; next } P && /_/ { P = P " " $1;""" + \
          """K=P } P && !/_/ { P="" }  END { print "kill -""" \
          + str(signal) + """ "K }' | sh """
{code}
          
*Example*
{code}((sleep 3141592) & ((sleep 3141592) & (sleep 3141592))

ps xf

 3231 ?        Ss     0:01  \_ sshd: root@pts/0 
 3233 pts/0    Ss     0:00  |   \_ -bash
17984 pts/0    S+     0:00  |       \_ -bash
17985 pts/0    S+     0:00  |           \_ sleep 3141592
17986 pts/0    S+     0:00  |           \_ -bash
17987 pts/0    S+     0:00  |               \_ sleep 3141592
17988 pts/0    S+     0:00  |               \_ sleep 3141592
17738 ?        Ss     0:00  \_ sshd: root@pts/1 
17740 pts/1    Ss     0:00      \_ -bash
17989 pts/1    R+     0:00          \_ ps xf

ps xf | awk -v PID=17987 ' $1 == PID { P = $1; next } P && /_/ { P = P " " $1;K=P } P && !/_/ { P="" }  END { print "kill "K }'

(PID=17987)
result : "kill 17987 17988 17738 17740 18083 18084"
but right will only "kill 17987"

(PID=17985)
result : "kill 17985 17986 17987 17988 17738 17740 18697 18698"
right : "kill 17985"

(PID=17986)
result : "kill 17986 17987 17988 17738 17740 18980 18981"
right : "kill 17986 17987 17988"
{code}


Diffs (updated)
-----

  ambari-agent/src/test/python/ambari_agent/TestProcessUtils.py PRE-CREATION 
  ambari-agent/src/test/python/ambari_agent/TestShell.py 8d375e3 
  ambari-common/src/main/python/ambari_commons/process_utils.py PRE-CREATION 
  ambari-common/src/main/python/ambari_commons/shell.py 8d26599 

Diff: https://reviews.apache.org/r/56059/diff/


Testing
-------

mvn clean test


Thanks,

Dmitro Lisnichenko


Re: Review Request 56059: Broken kill_process_with_children shell single liner

Posted by Andrew Onischuk <ao...@hortonworks.com>.
-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/56059/#review165112
-----------------------------------------------------------


Ship it!




Ship It!

- Andrew Onischuk


On Feb. 10, 2017, 10:13 a.m., Dmitro Lisnichenko wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/56059/
> -----------------------------------------------------------
> 
> (Updated Feb. 10, 2017, 10:13 a.m.)
> 
> 
> Review request for Ambari, Alejandro Fernandez, Andrew Onischuk, Dmytro Grinenko, Jonathan Hurley, and Nate Cole.
> 
> 
> Bugs: AMBARI-19768
>     https://issues.apache.org/jira/browse/AMBARI-19768
> 
> 
> Repository: ambari
> 
> 
> Description
> -------
> 
> This single liner does not work correctly in some cases
> {code}    CMD = """ps xf | awk -v PID=""" + str(pid) + \
>           """ ' $1 == PID { P = $1; next } P && /_/ { P = P " " $1;""" + \
>           """K=P } P && !/_/ { P="" }  END { print "kill -""" \
>           + str(signal) + """ "K }' | sh """
> {code}
>           
> *Example*
> {code}((sleep 3141592) & ((sleep 3141592) & (sleep 3141592))
> 
> ps xf
> 
>  3231 ?        Ss     0:01  \_ sshd: root@pts/0 
>  3233 pts/0    Ss     0:00  |   \_ -bash
> 17984 pts/0    S+     0:00  |       \_ -bash
> 17985 pts/0    S+     0:00  |           \_ sleep 3141592
> 17986 pts/0    S+     0:00  |           \_ -bash
> 17987 pts/0    S+     0:00  |               \_ sleep 3141592
> 17988 pts/0    S+     0:00  |               \_ sleep 3141592
> 17738 ?        Ss     0:00  \_ sshd: root@pts/1 
> 17740 pts/1    Ss     0:00      \_ -bash
> 17989 pts/1    R+     0:00          \_ ps xf
> 
> ps xf | awk -v PID=17987 ' $1 == PID { P = $1; next } P && /_/ { P = P " " $1;K=P } P && !/_/ { P="" }  END { print "kill "K }'
> 
> (PID=17987)
> result : "kill 17987 17988 17738 17740 18083 18084"
> but right will only "kill 17987"
> 
> (PID=17985)
> result : "kill 17985 17986 17987 17988 17738 17740 18697 18698"
> right : "kill 17985"
> 
> (PID=17986)
> result : "kill 17986 17987 17988 17738 17740 18980 18981"
> right : "kill 17986 17987 17988"
> {code}
> 
> 
> Diffs
> -----
> 
>   ambari-agent/src/test/python/ambari_agent/TestProcessUtils.py PRE-CREATION 
>   ambari-agent/src/test/python/ambari_agent/TestShell.py 8d375e3915 
>   ambari-common/src/main/python/ambari_commons/process_utils.py PRE-CREATION 
>   ambari-common/src/main/python/ambari_commons/shell.py 8d26599df8 
> 
> Diff: https://reviews.apache.org/r/56059/diff/
> 
> 
> Testing
> -------
> 
> mvn clean test
> 
> 
> Thanks,
> 
> Dmitro Lisnichenko
> 
>


Re: Review Request 56059: Broken kill_process_with_children shell single liner

Posted by Dmitro Lisnichenko <dl...@hortonworks.com>.
-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/56059/
-----------------------------------------------------------

(Updated Feb. 10, 2017, 3:15 p.m.)


Review request for Ambari, Alejandro Fernandez, Andrew Onischuk, Dmytro Grinenko, Jonathan Hurley, and Nate Cole.


Bugs: AMBARI-19768
    https://issues.apache.org/jira/browse/AMBARI-19768


Repository: ambari


Description
-------

This single liner does not work correctly in some cases
{code}    CMD = """ps xf | awk -v PID=""" + str(pid) + \
          """ ' $1 == PID { P = $1; next } P && /_/ { P = P " " $1;""" + \
          """K=P } P && !/_/ { P="" }  END { print "kill -""" \
          + str(signal) + """ "K }' | sh """
{code}
          
*Example*
{code}((sleep 3141592) & ((sleep 3141592) & (sleep 3141592))

ps xf

 3231 ?        Ss     0:01  \_ sshd: root@pts/0 
 3233 pts/0    Ss     0:00  |   \_ -bash
17984 pts/0    S+     0:00  |       \_ -bash
17985 pts/0    S+     0:00  |           \_ sleep 3141592
17986 pts/0    S+     0:00  |           \_ -bash
17987 pts/0    S+     0:00  |               \_ sleep 3141592
17988 pts/0    S+     0:00  |               \_ sleep 3141592
17738 ?        Ss     0:00  \_ sshd: root@pts/1 
17740 pts/1    Ss     0:00      \_ -bash
17989 pts/1    R+     0:00          \_ ps xf

ps xf | awk -v PID=17987 ' $1 == PID { P = $1; next } P && /_/ { P = P " " $1;K=P } P && !/_/ { P="" }  END { print "kill "K }'

(PID=17987)
result : "kill 17987 17988 17738 17740 18083 18084"
but right will only "kill 17987"

(PID=17985)
result : "kill 17985 17986 17987 17988 17738 17740 18697 18698"
right : "kill 17985"

(PID=17986)
result : "kill 17986 17987 17988 17738 17740 18980 18981"
right : "kill 17986 17987 17988"
{code}


Diffs
-----

  ambari-agent/src/test/python/ambari_agent/TestProcessUtils.py PRE-CREATION 
  ambari-agent/src/test/python/ambari_agent/TestShell.py 8d375e3915 
  ambari-common/src/main/python/ambari_commons/process_utils.py PRE-CREATION 
  ambari-common/src/main/python/ambari_commons/shell.py 8d26599df8 

Diff: https://reviews.apache.org/r/56059/diff/


Testing
-------

mvn clean test


Thanks,

Dmitro Lisnichenko


Re: Review Request 56059: Broken kill_process_with_children shell single liner

Posted by Dmitro Lisnichenko <dl...@hortonworks.com>.
-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/56059/
-----------------------------------------------------------

(Updated Feb. 10, 2017, 12:13 p.m.)


Review request for Ambari, Alejandro Fernandez, Andrew Onischuk, Dmytro Grinenko, Jonathan Hurley, and Nate Cole.


Changes
-------

Fixes


Bugs: AMBARI-19768
    https://issues.apache.org/jira/browse/AMBARI-19768


Repository: ambari


Description
-------

This single liner does not work correctly in some cases
{code}    CMD = """ps xf | awk -v PID=""" + str(pid) + \
          """ ' $1 == PID { P = $1; next } P && /_/ { P = P " " $1;""" + \
          """K=P } P && !/_/ { P="" }  END { print "kill -""" \
          + str(signal) + """ "K }' | sh """
{code}
          
*Example*
{code}((sleep 3141592) & ((sleep 3141592) & (sleep 3141592))

ps xf

 3231 ?        Ss     0:01  \_ sshd: root@pts/0 
 3233 pts/0    Ss     0:00  |   \_ -bash
17984 pts/0    S+     0:00  |       \_ -bash
17985 pts/0    S+     0:00  |           \_ sleep 3141592
17986 pts/0    S+     0:00  |           \_ -bash
17987 pts/0    S+     0:00  |               \_ sleep 3141592
17988 pts/0    S+     0:00  |               \_ sleep 3141592
17738 ?        Ss     0:00  \_ sshd: root@pts/1 
17740 pts/1    Ss     0:00      \_ -bash
17989 pts/1    R+     0:00          \_ ps xf

ps xf | awk -v PID=17987 ' $1 == PID { P = $1; next } P && /_/ { P = P " " $1;K=P } P && !/_/ { P="" }  END { print "kill "K }'

(PID=17987)
result : "kill 17987 17988 17738 17740 18083 18084"
but right will only "kill 17987"

(PID=17985)
result : "kill 17985 17986 17987 17988 17738 17740 18697 18698"
right : "kill 17985"

(PID=17986)
result : "kill 17986 17987 17988 17738 17740 18980 18981"
right : "kill 17986 17987 17988"
{code}


Diffs (updated)
-----

  ambari-agent/src/test/python/ambari_agent/TestProcessUtils.py PRE-CREATION 
  ambari-agent/src/test/python/ambari_agent/TestShell.py 8d375e3915 
  ambari-common/src/main/python/ambari_commons/process_utils.py PRE-CREATION 
  ambari-common/src/main/python/ambari_commons/shell.py 8d26599df8 

Diff: https://reviews.apache.org/r/56059/diff/


Testing
-------

mvn clean test


Thanks,

Dmitro Lisnichenko


Re: Review Request 56059: Broken kill_process_with_children shell single liner

Posted by Dmitro Lisnichenko <dl...@hortonworks.com>.

> On Feb. 8, 2017, 4:57 p.m., Andrew Onischuk wrote:
> > ambari-common/src/main/python/ambari_commons/process_utils.py, line 48
> > <https://reviews.apache.org/r/56059/diff/5/?file=1627633#file1627633line48>
> >
> >     Was this tested in non-root?
> >     Should we maybe call it with ambari-sudo.sh to be able to kill sub-processes started as service users hdfs etc. when running in non-root
> 
> Nate Cole wrote:
>     +1 on this

yes


- Dmitro


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/56059/#review164687
-----------------------------------------------------------


On Feb. 10, 2017, 12:13 p.m., Dmitro Lisnichenko wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/56059/
> -----------------------------------------------------------
> 
> (Updated Feb. 10, 2017, 12:13 p.m.)
> 
> 
> Review request for Ambari, Alejandro Fernandez, Andrew Onischuk, Dmytro Grinenko, Jonathan Hurley, and Nate Cole.
> 
> 
> Bugs: AMBARI-19768
>     https://issues.apache.org/jira/browse/AMBARI-19768
> 
> 
> Repository: ambari
> 
> 
> Description
> -------
> 
> This single liner does not work correctly in some cases
> {code}    CMD = """ps xf | awk -v PID=""" + str(pid) + \
>           """ ' $1 == PID { P = $1; next } P && /_/ { P = P " " $1;""" + \
>           """K=P } P && !/_/ { P="" }  END { print "kill -""" \
>           + str(signal) + """ "K }' | sh """
> {code}
>           
> *Example*
> {code}((sleep 3141592) & ((sleep 3141592) & (sleep 3141592))
> 
> ps xf
> 
>  3231 ?        Ss     0:01  \_ sshd: root@pts/0 
>  3233 pts/0    Ss     0:00  |   \_ -bash
> 17984 pts/0    S+     0:00  |       \_ -bash
> 17985 pts/0    S+     0:00  |           \_ sleep 3141592
> 17986 pts/0    S+     0:00  |           \_ -bash
> 17987 pts/0    S+     0:00  |               \_ sleep 3141592
> 17988 pts/0    S+     0:00  |               \_ sleep 3141592
> 17738 ?        Ss     0:00  \_ sshd: root@pts/1 
> 17740 pts/1    Ss     0:00      \_ -bash
> 17989 pts/1    R+     0:00          \_ ps xf
> 
> ps xf | awk -v PID=17987 ' $1 == PID { P = $1; next } P && /_/ { P = P " " $1;K=P } P && !/_/ { P="" }  END { print "kill "K }'
> 
> (PID=17987)
> result : "kill 17987 17988 17738 17740 18083 18084"
> but right will only "kill 17987"
> 
> (PID=17985)
> result : "kill 17985 17986 17987 17988 17738 17740 18697 18698"
> right : "kill 17985"
> 
> (PID=17986)
> result : "kill 17986 17987 17988 17738 17740 18980 18981"
> right : "kill 17986 17987 17988"
> {code}
> 
> 
> Diffs
> -----
> 
>   ambari-agent/src/test/python/ambari_agent/TestProcessUtils.py PRE-CREATION 
>   ambari-agent/src/test/python/ambari_agent/TestShell.py 8d375e3915 
>   ambari-common/src/main/python/ambari_commons/process_utils.py PRE-CREATION 
>   ambari-common/src/main/python/ambari_commons/shell.py 8d26599df8 
> 
> Diff: https://reviews.apache.org/r/56059/diff/
> 
> 
> Testing
> -------
> 
> mvn clean test
> 
> 
> Thanks,
> 
> Dmitro Lisnichenko
> 
>


Re: Review Request 56059: Broken kill_process_with_children shell single liner

Posted by Nate Cole <nc...@hortonworks.com>.

> On Feb. 8, 2017, 9:57 a.m., Andrew Onischuk wrote:
> > ambari-common/src/main/python/ambari_commons/process_utils.py, line 48
> > <https://reviews.apache.org/r/56059/diff/5/?file=1627633#file1627633line48>
> >
> >     Was this tested in non-root?
> >     Should we maybe call it with ambari-sudo.sh to be able to kill sub-processes started as service users hdfs etc. when running in non-root

+1 on this


> On Feb. 8, 2017, 9:57 a.m., Andrew Onischuk wrote:
> > ambari-common/src/main/python/ambari_commons/process_utils.py, line 30
> > <https://reviews.apache.org/r/56059/diff/5/?file=1627633#file1627633line30>
> >
> >     Can we check the return code of every command which we run here. And give an informative exception in case it is non-zero. 
> >     Saying which command failed with which output and which return code.

+1 for this as long as we don't fill the logs (we shouldn't be, but you never know)


- Nate


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/56059/#review164687
-----------------------------------------------------------


On Feb. 8, 2017, 9:50 a.m., Dmitro Lisnichenko wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/56059/
> -----------------------------------------------------------
> 
> (Updated Feb. 8, 2017, 9:50 a.m.)
> 
> 
> Review request for Ambari, Alejandro Fernandez, Andrew Onischuk, Dmytro Grinenko, Jonathan Hurley, and Nate Cole.
> 
> 
> Bugs: AMBARI-19768
>     https://issues.apache.org/jira/browse/AMBARI-19768
> 
> 
> Repository: ambari
> 
> 
> Description
> -------
> 
> This single liner does not work correctly in some cases
> {code}    CMD = """ps xf | awk -v PID=""" + str(pid) + \
>           """ ' $1 == PID { P = $1; next } P && /_/ { P = P " " $1;""" + \
>           """K=P } P && !/_/ { P="" }  END { print "kill -""" \
>           + str(signal) + """ "K }' | sh """
> {code}
>           
> *Example*
> {code}((sleep 3141592) & ((sleep 3141592) & (sleep 3141592))
> 
> ps xf
> 
>  3231 ?        Ss     0:01  \_ sshd: root@pts/0 
>  3233 pts/0    Ss     0:00  |   \_ -bash
> 17984 pts/0    S+     0:00  |       \_ -bash
> 17985 pts/0    S+     0:00  |           \_ sleep 3141592
> 17986 pts/0    S+     0:00  |           \_ -bash
> 17987 pts/0    S+     0:00  |               \_ sleep 3141592
> 17988 pts/0    S+     0:00  |               \_ sleep 3141592
> 17738 ?        Ss     0:00  \_ sshd: root@pts/1 
> 17740 pts/1    Ss     0:00      \_ -bash
> 17989 pts/1    R+     0:00          \_ ps xf
> 
> ps xf | awk -v PID=17987 ' $1 == PID { P = $1; next } P && /_/ { P = P " " $1;K=P } P && !/_/ { P="" }  END { print "kill "K }'
> 
> (PID=17987)
> result : "kill 17987 17988 17738 17740 18083 18084"
> but right will only "kill 17987"
> 
> (PID=17985)
> result : "kill 17985 17986 17987 17988 17738 17740 18697 18698"
> right : "kill 17985"
> 
> (PID=17986)
> result : "kill 17986 17987 17988 17738 17740 18980 18981"
> right : "kill 17986 17987 17988"
> {code}
> 
> 
> Diffs
> -----
> 
>   ambari-agent/src/test/python/ambari_agent/TestProcessUtils.py PRE-CREATION 
>   ambari-agent/src/test/python/ambari_agent/TestShell.py 8d375e3 
>   ambari-common/src/main/python/ambari_commons/process_utils.py PRE-CREATION 
>   ambari-common/src/main/python/ambari_commons/shell.py 8d26599 
> 
> Diff: https://reviews.apache.org/r/56059/diff/
> 
> 
> Testing
> -------
> 
> mvn clean test
> 
> 
> Thanks,
> 
> Dmitro Lisnichenko
> 
>


Re: Review Request 56059: Broken kill_process_with_children shell single liner

Posted by Andrew Onischuk <ao...@hortonworks.com>.
-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/56059/#review164687
-----------------------------------------------------------




ambari-common/src/main/python/ambari_commons/process_utils.py (line 30)
<https://reviews.apache.org/r/56059/#comment236456>

    Can we check the return code of every command which we run here. And give an informative exception in case it is non-zero. 
    Saying which command failed with which output and which return code.



ambari-common/src/main/python/ambari_commons/process_utils.py (line 48)
<https://reviews.apache.org/r/56059/#comment236455>

    Was this tested in non-root?
    Should we maybe call it with ambari-sudo.sh to be able to kill sub-processes started as service users hdfs etc. when running in non-root


- Andrew Onischuk


On Feb. 8, 2017, 2:50 p.m., Dmitro Lisnichenko wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/56059/
> -----------------------------------------------------------
> 
> (Updated Feb. 8, 2017, 2:50 p.m.)
> 
> 
> Review request for Ambari, Alejandro Fernandez, Andrew Onischuk, Dmytro Grinenko, Jonathan Hurley, and Nate Cole.
> 
> 
> Bugs: AMBARI-19768
>     https://issues.apache.org/jira/browse/AMBARI-19768
> 
> 
> Repository: ambari
> 
> 
> Description
> -------
> 
> This single liner does not work correctly in some cases
> {code}    CMD = """ps xf | awk -v PID=""" + str(pid) + \
>           """ ' $1 == PID { P = $1; next } P && /_/ { P = P " " $1;""" + \
>           """K=P } P && !/_/ { P="" }  END { print "kill -""" \
>           + str(signal) + """ "K }' | sh """
> {code}
>           
> *Example*
> {code}((sleep 3141592) & ((sleep 3141592) & (sleep 3141592))
> 
> ps xf
> 
>  3231 ?        Ss     0:01  \_ sshd: root@pts/0 
>  3233 pts/0    Ss     0:00  |   \_ -bash
> 17984 pts/0    S+     0:00  |       \_ -bash
> 17985 pts/0    S+     0:00  |           \_ sleep 3141592
> 17986 pts/0    S+     0:00  |           \_ -bash
> 17987 pts/0    S+     0:00  |               \_ sleep 3141592
> 17988 pts/0    S+     0:00  |               \_ sleep 3141592
> 17738 ?        Ss     0:00  \_ sshd: root@pts/1 
> 17740 pts/1    Ss     0:00      \_ -bash
> 17989 pts/1    R+     0:00          \_ ps xf
> 
> ps xf | awk -v PID=17987 ' $1 == PID { P = $1; next } P && /_/ { P = P " " $1;K=P } P && !/_/ { P="" }  END { print "kill "K }'
> 
> (PID=17987)
> result : "kill 17987 17988 17738 17740 18083 18084"
> but right will only "kill 17987"
> 
> (PID=17985)
> result : "kill 17985 17986 17987 17988 17738 17740 18697 18698"
> right : "kill 17985"
> 
> (PID=17986)
> result : "kill 17986 17987 17988 17738 17740 18980 18981"
> right : "kill 17986 17987 17988"
> {code}
> 
> 
> Diffs
> -----
> 
>   ambari-agent/src/test/python/ambari_agent/TestProcessUtils.py PRE-CREATION 
>   ambari-agent/src/test/python/ambari_agent/TestShell.py 8d375e3 
>   ambari-common/src/main/python/ambari_commons/process_utils.py PRE-CREATION 
>   ambari-common/src/main/python/ambari_commons/shell.py 8d26599 
> 
> Diff: https://reviews.apache.org/r/56059/diff/
> 
> 
> Testing
> -------
> 
> mvn clean test
> 
> 
> Thanks,
> 
> Dmitro Lisnichenko
> 
>