QMD (prounounced "command") is a service for executing arbitrary shell scripts over HTTP. We use it to compile javascript assets and upload them to s3.
Note: Exposing shell scripts over HTTP might be very dangerous, so be careful! QMD is intended to be used as an internal service, running in a non-privileged Docker container.
sudo docker run qmd -config /etc/qmd.conf
qmd.conf
see example filescripts
directory where QMD looks for shell scripts to run, see examples
POST /scripts/:filename
Request params (JSON):
callback_url
: (optional) execute the script in the background and send the output to the callback_url when the script finishesargs
: array of command line arguments to pass to the script upon executionfiles
: JSON object containing filename : filedata pairs which are saved in $QMD_TMP for the script to use
Response (JSON):
id
: unique job IDscript
: the filename in the scripts directoryargs
: the user given arguments if anyfiles
: the user given files if anycallback_url
: an endpoint to send the outputoutput
: the $QMD_OUT outputexec_log
: the piped STDOUT and STDERR script execution logstatus
: the exit status of the script; either OK or ERRstart_time
: the time (in local system time) the script began to executeend_time
: the time (in local system time) the script finished executingduration
: the amount of time taken to run the script in seconds as a string
Example: Enqueue a script to execute in the background and send output to a callback URL
POST /scripts/bench.sh
{
"callback_url": "http://...",
"args": ["1", "20"],
}
{
"id": 1,
"script": "bench.sh",
"args": [
"1",
"20"
],
"callback_url": "http://..."
}
...the job then runs in the background.. and when finishes it will send the following
response to callback_url
:
{
"id": 1,
"script": "bench.sh",
"args": [
"1",
"20"
],
"callback_url": "http://...",
"output": "",
"exec_log": "Running under PID #16231\nMaking file in tmp dir at /home/vagrant/test/tmp/883\n/home/vagrant/test/scripts/bench.sh: line 10: Test #$PID: command not found\nMaking file in store dir at /home/vagrant/test/store\n/home/vagrant/test/scripts/bench.sh: line 13: Test #$PID: command not found\nRandomly selected 2\nzzzzzzzzzzzzzzzzz\nzzzzzz..I'M AWAKE\nRandomly selected 12\nzzzzzzzzzzzzzzzzz\nzzzzzz..I'M AWAKE\nRandomly selected 3\nzzzzzzzzzzzzzzzzz\nzzzzzz..I'M AWAKE\nRandomly selected 20\nAbandon ship! Abandon ship! Everyone for themselves!\n\nsignal: hangup",
"status": "ERR",
"start_time": "2014-06-24T17:26:39.643458173Z",
"end_time": "2014-06-24T17:26:56.666502567Z",
"duration": "17.023044394"
}
GET /jobs/
- Scripts will have access to the following environment variables
QMD_TMP
: the directory where your script is being run. All files here will be deleted unlesskeepTemp
is set totrue
in your config. Located atworkingDir/tmp/:id
.QMD_STORE
: the directory set in your config asstoreDir
. All files written here will be left alone.QMD_OUT
: the output file for your script. Everything written here will be persisted to the response/log under theoutput
key. Located atQMD_TMP/qmd.out
.
sudo docker run -d --name redis -v /data/redis:/data --restart=always -p 6379:6379 redis:latest redis-server --appendonly yes
sudo docker run -d --name disque -v /data/disque:/data --restart=always -p 7711:7711 richnorth/disque:latest disque-server --appendonly yes
Licensed under the MIT License.