JSON-RPC経由でシェルコマンドを実行したい事があって、以下のようなRubyスクリプトを書きました。
以下のようなリクエストに対して、
{
    "jsonrpc":"2.0",
    "id": "1",
    "method":"shell",
    "params": [
        { "command": "ls -a" },
        { "command": "pwd" }
    ]
}
次のようなレスポンスを返します。
{
  "jsonrpc": "2.0",
  "result": [
    {
      "command": "ls -a",
      "stdout.json": null,
      "stdout": ".\n..\n.git\n.gitignore\n.ruby-version\nDockerfile\nGemfile\nGemfile.lock\nREADME.md\napp.rb\n",
      "stderr": "",
      "status": {
        "exitstatus": 0,
        "pid": 73595
      }
    },
    {
      "command": "pwd",
      "stdout.json": null,
      "stdout": "/Users/tumf/work/shell-jsonrpc\n",
      "stderr": "",
      "status": {
        "exitstatus": 0,
        "pid": 73596
      }
    }
  ],
  "id": "1"
}
スクリプトは以下のような感じです
 |  | 
ソース一式はgithub: https://github.com/tumf/shell-jsonrpc
DockerイメージはDockerHubに公開してあります。
$ docker push tumf/shell-jsonrpc
起動
$ ruby app.rb
デフォルトで8999番ポートをListenするので、curlで試すなら以下のようにしてください。
$ curl http://0.0.0.0:8999 -d '{"jsonrpc":"2.0", "id": "1", "method":"shell", "params": [{ "command": "ls -a" }, {"command": "pwd"}] }' |jq .