Skip to content

pman command: run

Rudolph Pienaar edited this page Oct 16, 2017 · 22 revisions

pman command: run

Abstract

This page describes the run command to pman. It is used to spawn a process on the underlying shell/OS.

Preconditions

  • export an env variable, HOST_IP containing the IP of the host running the pman service. This var will be used in the examples on this page.
export HOST_IP=$(ip route | grep -v docker | awk '{if(NF==11) print $9}')
  • Make sure that pman has been started (see here for more info):
rm -fr /tmp/pman ; pman --rawmode 1 --http  --port 5010 --listeners 12

msg summary

The msg payload of the REST interaction with pman is:

{  "action": "run",
        "meta": {
                "cmd":      "cal 7 1970",
                "auid":     "rudolphpienaar",
                "jid":      "cal-job-1234",
                "threaded": true
        }
}

run

pfurl calling syntax

The real purpose of pman is to manage processes. Let's send it a simple job, the UNIX calendar command to simply print a month in a given year. In this case, the command we wish to run is cal 7 1970.

pfurl --verb POST --raw --http ${HOST_IP}:5010/api/v1/cmd --jsonwrapper 'payload' --msg \
'{  "action": "run",
        "meta": {
                "cmd":      "cal 7 1970",
                "auid":     "rudolphpienaar",
                "jid":      "cal-job-1234",
                "threaded": true
        }
}' --quiet --jsonpprintindent 4

return payload

The above call returns the JSON string:

{
    "path": "/api/v1/cmd",
    "receivedByServer": [
        "POST /api/v1/cmd HTTP/1.1\r",
        "Host: 10.17.24.163:5010\r",
        "User-Agent: PycURL/7.43.0 libcurl/7.52.1 OpenSSL/1.0.2g zlib/1.2.11 libidn2/0.16 libpsl/0.17.0 (+libidn2/0.16) librtmp/2.3\r",
        "Accept: */*\r",
        "Content-Length: 128\r",
        "Content-Type: application/x-www-form-urlencoded\r",
        "Via: 1.1 lofnetsg1\r",
        "Connection: Keep-Alive\r",
        "X-BlueCoat-Via: 92f6bd6899b3e493\r",
        "\r",
        "{\"payload\": {\"meta\": {\"cmd\": \"cal 7 1970\", \"threaded\": true, \"auid\": \"rudolphpienaar\", \"jid\": \"cal-job-1234\"}, \"action\": \"run\"}}"
    ],
    "status": true,
    "payloadsize": 128,
    "jobRootDir": "20171016101909.349574_9b2aeb46-d87f-4a90-895a-de0d2a4cd9f2",
    "meta": {
        "cmd": "cal 7 1970",
        "threaded": true,
        "auid": "rudolphpienaar",
        "jid": "cal-job-1234"
    },
    "action": "run",
    "RESTverb": "POST",
    "client_json_len": 128,
    "RESTheader": "POST /api/v1/cmd HTTP/1.1\r",
    "client_json_payload": "{\"payload\": {\"meta\": {\"cmd\": \"cal 7 1970\", \"threaded\": true, \"auid\": \"rudolphpienaar\", \"jid\": \"cal-job-1234\"}, \"action\": \"run\"}}"
}

--30--