salt icon indicating copy to clipboard operation
salt copied to clipboard

saltutil.kill_job doesn't behave as expected

Open weinix opened this issue 11 years ago • 12 comments

I am still still seeing this issue on version 2015.5.0-1, which have #10006. On Master:

[root@master ~]# salt --async --subset=10 * cmd.run 'sleep 20m; echo hello'
Executed command with job ID: 20150819121240993912

On minion:

[root@minion1 proc]# pstree -p
systemd(1)-+-agetty(725)
::::::::::::
|-salt-minion(3342)---salt-minion(3345)-+-{salt-minion}(3346)
| |-{salt-minion}(3375)
| |-{salt-minion}(3376)
| |-{salt-minion}(3396)
| `-{salt-minion}(3397)
|-salt-minion(4446)---sh(4447)---sleep(4448)

Kill from master:

[root@master ~]# salt * saltutil.kill_job 20150819121240993912
perfdash.eng.riftio.com:
Signal 9 sent to job 20150819121240993912 at pid 3926
bvc.novalocal:
Signal 9 sent to job 20150819121240993912 at pid 4446

After kill command check on minion:

systemd(1)-+-agetty(725)
:::::::::::::
|-salt-minion(3342)---salt-minion(3345)-+-{salt-minion}(3346)
| |-{salt-minion}(3375)
| |-{salt-minion}(3376)
| |-{salt-minion}(3396)
| `-{salt-minion}(3397)
|-sh(4447)---sleep(4448)

If I understand it correctly, file /var/cache/salt/minion/proc/20150819121240993912 should have the child process ids of job 20150819121240993912, however it appears doesn't have them:

[root@minion1 proc]# cat /var/cache/salt/minion/proc/20150819121240993912
��tgt_type�glob�jid�20150819121240993912�tgt�*�pid^�ret��user�root�arg��sleep 20m; echo hello�fun�cmd.run

Please reference to old bug: https://github.com/saltstack/salt/issues/9855

weinix avatar Aug 19 '15 20:08 weinix

@weiwangblog - what version of salt are you running? salt --versions-report

ssgward avatar Aug 19 '15 20:08 ssgward

Thanks for reporting this, we'll investigate.

basepi avatar Aug 19 '15 20:08 basepi

[root@master ~]# salt --versions-report Salt: 2015.5.0 Python: 2.7.5 (default, Apr 10 2015, 08:09:05) Jinja2: 2.7.3 M2Crypto: 0.21.1 msgpack-python: 0.4.2 msgpack-pure: Not Installed pycrypto: 2.6.1 libnacl: Not Installed PyYAML: 3.10 ioflo: Not Installed PyZMQ: 13.0.2 RAET: Not Installed ZMQ: 3.2.4 Mako: Not Installed

weinix avatar Aug 19 '15 23:08 weinix

Just for completeness, can you also run salt '*' test.versions_report and give us the minion information? Minion side is actually what will affect saltutil.kill_job

basepi avatar Aug 20 '15 16:08 basepi

Here you go:

[root@master ~]# salt '*' test.versions_report minion1: Salt: 2015.5.0 Python: 2.7.5 (default, Apr 10 2015, 08:09:05) Jinja2: 2.7.3 M2Crypto: 0.21.1 msgpack-python: 0.4.2 msgpack-pure: Not Installed pycrypto: 2.6.1 libnacl: Not Installed PyYAML: 3.10 ioflo: Not Installed PyZMQ: 13.0.2 RAET: Not Installed ZMQ: 3.2.4 Mako: Not Installed minion2: Salt: 2015.5.0 Python: 2.7.5 (default, Jul 10 2014, 17:25:32) Jinja2: 2.7.1 M2Crypto: 0.21.1 msgpack-python: 0.1.13 msgpack-pure: Not Installed pycrypto: 2.6.1 libnacl: Not Installed PyYAML: 3.10 ioflo: Not Installed PyZMQ: 13.0.2 RAET: Not Installed ZMQ: 3.2.4 Mako: Not Installed

weinix avatar Aug 20 '15 16:08 weinix

Perfect, thanks! We'll investigate this.

basepi avatar Aug 20 '15 16:08 basepi

Thank you, @basepi

weinix avatar Aug 20 '15 16:08 weinix

@basepi, no pressure but just like to know if there is any progress?

weinix avatar Sep 10 '15 16:09 weinix

Unfortunately no, we haven't had a chance to investigate this yet.

basepi avatar Sep 15 '15 22:09 basepi

Ran into the same issue. It seems that term_job is also subject to the same condition.

As a workaround, I'm launching commands using the following wrapper which terminates the child process when the parent (minion process) dies. It does not give great control and does not allow differentiation between kill/term but is sufficient for the time being.

#!/bin/bash

ppid=$PPID

echo "Parent process $ppid monitor wrapping: $@"
"$@"&
pid=$!

# Kill the child process when this monitor process exits
trap "echo Terminating child process: $pid; kill -s SIGTERM $pid" EXIT

# Exit when we detect the parent process has exited
while true; do
  kill -0 $ppid 2>/dev/null
  if [ $? -ne 0 ]; then
    echo "Parent process died. Exiting."
    exit 1
  fi

  sleep .5
done

ajcormier avatar Sep 17 '15 19:09 ajcormier

This is still a problem with vanilla Salt as of v2016.11.1, but it can be worked around if psutil is installed on the minion.

https://github.com/saltstack/salt/blob/v2016.11.1/salt/modules/saltutil.py#L877

johndistasio avatar Dec 22 '16 02:12 johndistasio

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

stale[bot] avatar Aug 10 '18 20:08 stale[bot]