Remote Commands Execution
I have just published the code for a Mesos module to enable operators to execute remotely arbitrary commands on Apache Mesos Agent/Master nodes, out-of-band from the normal task execution framework.
This is a Mesos anonymous module which can be loaded using the enclosed modules.json
descriptor; this module will add HTTP endpoints such that:
- we can monitor the status (active/inactive) of this module;
- we can remotely execute arbitrary (shell) commands, with optional arguments;
- we can retrieve the outcome of the command;
- we can terminate previously launched processes.
This is not meant to offer full remote shell functionality, however.
License & Allowed Use
The code is not released under an Open Source license and is (c) 2015 AlertAvert.com.
It is solely meant for training and learning purposes: the code is meant to be used by developers of Mesos Modules to learn how to create their own module.
See the Licensing
section of the README file in the repository.
API
The full API is detailed in the README file; here is a brief summary:
Obtain the status of the module: GET /remote/status 200 OK { "result": "OK", "status": "active" } Execute a command on the Agent: POST /remote/execute { "command": "ls", "shell": false, "arguments": ["-la", "/tmp"], "timeout": 10 } 200 OK { "result": "OK", "pid": 6880 } Retrieve the outcome of the command: POST /remote/task { "pid": 6880 } 200 OK { "exitCode": 0, "signaled": false, "stderr": "", "stdout": "total 1972\ndrwxr-xr-x 4 marco marco 4096 Dec 20 14:28 agent ...\ndrwxrwxrwt 2 root root 4096 Dec 17 16:06 .X11-unix\n" } Get the list of currently running and executed processes: GET /remote/task 200 OK { "pids": [12141, 12454, ... 12144] }
Build
You obviously need Apache Mesos to build this
project: in particular, you will need both the includes (mesos
, stout
and libprocess
) and the shared libmesos.so
library.
Apache Mesos makes extensive use of Protocol Buffers
and this project uses them too (see the proto/execute.proto
file).
See the README for full instructions.
CMake
This module uses cmake to build the module and the tests:
mkdir build && cd build cmake -DLOCAL_INSTALL_DIR=/path/to/usr/local .. make
where LOCAL_INSTALL_DIR
is the directory where the Mesos headers and libraries are located (typically, the same you specified using --prefix
when running ../configure
while building Apache Mesos).
Usage
To run a Mesos Agent with this module loaded, use the --modules
flag,
pointing it to the generated JSON gen/modules.json
file:
$ ${MESOS_ROOT}/build/bin/mesos-slave.sh --work_dir=/tmp/agent \ --modules=/path/to/execute-module/gen/modules.json \ --master=zk://zk1.cluster.prod.com:2181
See the Apache Mesos documentation pages for more details on the various flags.
Also, my zk_mesos github project provides an example Vagrant configuration showing how to deploy and run Mesos from the Mesosphere binary distributions.
Tests
Run the execmod_test
binary in the build/
directory:
cd build && ./execmod_test
See the full code and detailed documentation in the github repository.
Leave a Reply