saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Install Salt from the Salt package repositories here:
https://docs.saltproject.io/salt/install-guide/en/latest/
Apache License 2.0
14.18k stars 5.48k forks source link

ERROR: Specified cwd '28830"' either not absolute or does not exist #55799

Open carolcoral opened 4 years ago

carolcoral commented 4 years ago

Description of Issue

When i want to kill the PID,but the command return this message for me "ERROR: Specified cwd '28830"' either not absolute or does not exist" And, i had checked this PID exists and absolute.

String command = "salt Centos76-247-45 cmd.run \"kill 28830\"";
Process process = Runtime.getRuntime().exec(command);
process.waitFor();

The Linux return:

Centos76-247-45:
    ERROR: Specified cwd '28830"' either not absolute or does not exist

Could you tell me how to reolve it,please.

# salt-run manage.versions  
Master:
    2017.7.4
waynew commented 4 years ago

cwd is a directory, not a PID.

I'm not sure why the command makes that into a CWD, but I expect it has something to do with the way the quotes are working for you.

carolcoral commented 4 years ago

cwd is a directory, not a PID.

I'm not sure why the command makes that into a CWD, but I expect it has something to do with the way the quotes are working for you.

I have tested in Python and Shell,but none of them is wrong.Only when i used it in Java by useing Runtime.getRunTime.exe() had this problem. Now, i had create a Flask service to receive Command and execute it in my Salt-mater.

waynew commented 4 years ago

Try this: create a python script, call it funtimes.py or whatever - it's not very important. The contents:

import sys
import json
with open('/tmp/args.json') as f:  # Or, whatever file you want to use
    json.dump(sys.argv, f, indent=2)

Then launch it with:

String command = "python funtimes.py Centos76-247-45 cmd.run \"kill 28830\"";
Process process = Runtime.getRuntime().exec(command);
process.waitFor();

Then inspect /tmp/args.json or whatever file you used. I suspect that you will not see

["Centos76-247-45",
  "cmd.run",
  "kill 28830"
]

But something else.

Note that there is a ps module that could do what you're after.

Try String command = "salt Centos76-247-45 ps.kill_pid 28830"; instead

carolcoral commented 4 years ago

Try this: create a python script, call it funtimes.py or whatever - it's not very important. The contents:

import sys
import json
with open('/tmp/args.json') as f:  # Or, whatever file you want to use
    json.dump(sys.argv, f, indent=2)

Then launch it with:

String command = "python funtimes.py Centos76-247-45 cmd.run \"kill 28830\"";
Process process = Runtime.getRuntime().exec(command);
process.waitFor();

Then inspect /tmp/args.json or whatever file you used. I suspect that you will not see

["Centos76-247-45",
  "cmd.run",
  "kill 28830"
]

But something else.

Note that there is a ps module that could do what you're after.

Try String command = "salt Centos76-247-45 ps.kill_pid 28830"; instead

I had try Python script and Shell ,None of all can be wordked.Only when i used flask what is WebService of Python can be worked.

stale[bot] commented 4 years ago

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] commented 4 years ago

Thank you for updating this issue. It is no longer marked as stale.

sagetherage commented 4 years ago

@waynew can you please take a look at these comments?

waynew commented 4 years ago

@carolcoral what result did you get from my above experiment?

dhs-rec commented 4 years ago

I also see this after updating from 2018.3.4 to 2019.2.3 (and even 3000) with this code (on Windows):

dotnet:
  module.run:
    - pkg.install:
      - name: dotnet
      - version: {{ dotnet.inst_ver }}
      - saltenv: {{ saltenv }}
      - refresh: True

and this package description:

dotnet:
  {% for version, inst_ver, pkg in [
    ('4.5.2', '4.5.51209', 'NDP452-KB2901907'),
    ('4.6.2', '4.6.01590', 'NDP462-KB3151800'),
    ('4.7', '4.7.02053', 'NDP47-KB3186497'),
    ('4.7.2', '4.7.03062', 'NDP472-KB4054530'),
  ] %}
  {% set installer = salt['pillar.get']('DEPLOYMENT_PATH') ~ '/store/' ~ pkg ~ '-x86-x64-AllOS-ENU.exe' %}
  '{{ inst_ver }}':
    full_name: 'Microsoft .NET Framework {{ version }}'
    installer: {{ installer }}
    install_flags: '/q /norestart'
    uninstaller: 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\SetupCache\v{{ inst_ver }}\Setup.exe'
    uninstall_flags: '/uninstall /x86 /x64 /q /norestart'
    msiexec: False
    locale: en_US
    reboot: False
  {% endfor %}

[Note that installing .Net using pkg.installed generally doesn't work, at least up to Salt 2018.3.4.] I also tried changing it to use pkg.installed in 2019.2.3 to see if the problem installing .Net this way still exists there, but it still throws the same error about the cwd:

Specified cwd '\store' either not absolute or does not exist

In the module.run case, I even get a complete stacktrace:

----------
          ID: dotnet
    Function: module.run
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "c:\salt\bin\lib\site-packages\salt-3000-py3.5.egg\salt\state.py", line 1981, in call
                  **cdata['kwargs'])
                File "c:\salt\bin\lib\site-packages\salt-3000-py3.5.egg\salt\loader.py", line 1977, in wrapper
                  return f(*args, **kwargs)
                File "c:\salt\bin\lib\site-packages\salt-3000-py3.5.egg\salt\utils\decorators\__init__.py", line 650, in _decorate
                  return self._call_function(kwargs)
                File "c:\salt\bin\lib\site-packages\salt-3000-py3.5.egg\salt\utils\decorators\__init__.py", line 353, in _call_function
                  six.reraise(*sys.exc_info())
                File "c:\salt\bin\lib\site-packages\salt-3000-py3.5.egg\salt\ext\six.py", line 693, in reraise
                  raise value
                File "c:\salt\bin\lib\site-packages\salt-3000-py3.5.egg\salt\utils\decorators\__init__.py", line 340, in _call_function
                  return self._function(*args, **kwargs)
                File "c:\salt\bin\lib\site-packages\salt-3000-py3.5.egg\salt\states\module.py", line 421, in run
                  func_args=kwargs.get(func))
                File "c:\salt\bin\lib\site-packages\salt-3000-py3.5.egg\salt\states\module.py", line 450, in _call_function
                  mret = salt.utils.functools.call_function(__salt__[name], *func_args)
                File "c:\salt\bin\lib\site-packages\salt-3000-py3.5.egg\salt\utils\functools.py", line 142, in call_function
                  return salt_function(*function_args, **function_kwargs)
                File "c:\salt\bin\lib\site-packages\salt-3000-py3.5.egg\salt\modules\win_pkg.py", line 1696, in install
                  redirect_stderr=True)
                File "c:\salt\bin\lib\site-packages\salt-3000-py3.5.egg\salt\modules\cmdmod.py", line 2081, in run_all
                  **kwargs)
                File "c:\salt\bin\lib\site-packages\salt-3000-py3.5.egg\salt\modules\cmdmod.py", line 648, in _run
                  .format(cwd)
              salt.exceptions.CommandExecutionError: Specified cwd '\store' either not absolute or does not exist
     Started: 07:47:13.624594
    Duration: 10515.6 ms
     Changes:

(This is from 3000, but it's the same for 2019.2.3)

dhs-rec commented 4 years ago

This one, #56119 and #56199 currently block us from updating to anything newer than 2018.3.4 because they all break existing, working code.

stale[bot] commented 4 years ago

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.

dhs-rec commented 4 years ago

Aaaaargh, this stale bot thing is STILL going rampage (#55829)!!!

stale[bot] commented 4 years ago

Thank you for updating this issue. It is no longer marked as stale.

dhs-rec commented 4 years ago

Is there any news on this? I still see this in 3000.3 and it's still preventing us from updating to that version.

carolcoral commented 4 years ago

@waynew i am sorry it too late to answer you.Your example can be worked in the same mathin,but i need to execute it from another mathin as a client. It always work in the same mathin by Java or python and shell. So, i have to make a Flask service as a client to receive 'command' to execute it. For example like this:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import Flask, request
import json
import subprocess
import traceback

app = Flask(__name__)

@app.route('/salt/command', methods=['POST'])
def salt():
    try:
        data = request.data
        if data is not None:
            print(data)
            data_json = json.loads(data)
            salt_key = data_json["saltKey"]
            command = data_json["command"]
            salt_command = "salt " + salt_key + " cmd.run " + "\"" + command + "\""
            res = subprocess.check_output(salt_command, shell=True)
            return res
    except Exception as e:
        traceback.print_exc()
    return ""

if __name__ == '__main__':
    app.run(host="0.0.0.0", port="18085")
waynew commented 4 years ago

@carolcoral I'm not sure what mathin is supposed to mean.

You also didn't provide the output at all - it's very difficult to help when you don't provide enough information to go on.

@dhs-rec that's definitely an odd one - it seems like it may be related. I'll come back to this tomorrow to see if I can repro your sample.

carolcoral commented 4 years ago

@waynew i am sorry for this wrong word - "machine". I have to execute 'CMD' in A machine but from B machine.But it didn`t worked in my Java program. So, i had make a Flask Server to receive "CMD" to execute. The output is same as you execute it in the base machine but the command from another machine.

waynew commented 4 years ago

@carolcoral did you try my experiment?

What was the result?