Run commands on host machine via http request.
- Core feature is, to run a command on the host and command is submitted via a
http
request - Application records the commands its running
- Couple of APIs are implemented
/api/submitcmd
-> to submit a command viaPOST
method/api/getcmdstatus/:cmd_id
-> to get status of the command,cmd_id
would be the response of thePOST
request
- Logging/Tracing is implemented to track the command flow
- Live commands outputs are also captured, a configurable timeout setting for long running commands
- Below are the environment variables which can be set to overwrite default values
RUST_LOG
: determine log level, Default is INFO.R_CMD_TIMEOUT
: Time out value in sec, only numerics, example: 100 for 100sec timeout, Default is 50RUN_IT_PORT
: port number to listen on, Default is 48786
quick-demo.mov
- To build locally it is required to have
rust
andcargo
installed - Clone the repo and run:
cargo build -r
- This would leave a executable in
<clone_repo_loc>/target/release/run-it
path - If above environment variables are set those values are used otherwise default values are used.
- To run this on a linux environment as systemd service, please follow the steps here
-
Service has an api exposed,
/api/submitcmd
, send aPOST
request with data in json format, hence need the header'Content-Type: application/json'
- data has can have these keys
{ "cmd": string<required>, "args": string<optional>, "is_shell": bool<optional> }
-
cmd - is the command need to run, string type
-
args - if the command accepts any args, string type
-
is_shell - if the
cmd
passed is a shell likebash
orsh
and args have the actual task, then this need to be settrue
, yes its bool type -
examples:
curl http://<IP_ADDRESS>:48786/api/submitcmd -X POST -H 'Content-Type: application/json' -d '{"cmd": "whoami"}'
- this is a basic example runs cmd
whoami
on the host and request responds with a unique id which can be used to lookup the results
- this is a basic example runs cmd
curl http://<IP_ADDRESS>:48786/api/submitcmd -X POST -H 'Content-Type: application/json' -d '{"cmd": "python3", "args": "--version"}'
- this is running a pyton command and with an arg, if host doesn't have python installed command would fail and its corresponding output is available on the
/api/getcmdstatus
api
- this is running a pyton command and with an arg, if host doesn't have python installed command would fail and its corresponding output is available on the
curl http://<IP_ADDRESS>:48786/api/submitcmd -X POST -H 'Content-Type: application/json' -d '{"cmd": "bash", "args": "c=0; while true; do let c=c+1; sleep 10; echo $c; done", "is_shell": true}'
- this is a final variant, cmd is shell, and args have actual single line script, in this scenario set the
is_shell
to true. and if you notice the script is set to run forever, in these long running session cmd will timeout after the configured setting.
- this is a final variant, cmd is shell, and args have actual single line script, in this scenario set the
- Service also provides an API to get the command status, to get the status request a
GET
call on/api/getcmdstatus/<CMD_ID>
, yes path should have the command ID thatPOST
call responded with.- example:
curl http://<IP_ADDRESS>:48786/api/getcmdstatus/13995226725389956087 -X GET | jq
as the response is json it can be piped tojq
If the CMD_ID is not found an empty output is returned otherwise it will have the state and output at that point of time, i mean if the cmd is still active it would return that point in time output and state would be{ "state": "", "output": "" }
in-progress
- example:
- Valid unit tests
- Ability to upload a script and run it
- external datastore
- server/clinet arch
- server will have an UI
- server can not accept commands via api
- client may or may not an ui module