Apache Mesos Anonymous Module Example

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.


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]


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.


This module uses cmake to build the module and the tests:

mkdir build && cd build
cmake -DLOCAL_INSTALL_DIR=/path/to/usr/local ..

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).


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 \

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.


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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s