diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-05-26 15:58:21 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-05-26 15:58:21 +0200 |
| commit | 96e19464f98b868bd93b76ac842ec5b32a17cfb6 (patch) | |
| tree | a232cfecd631d49fae8d1402371a284296aeec87 /app/relay | |
| parent | 28f4bd59314df8162548a1100b280bd256436eaa (diff) | |
means to run remote commands and get output
Diffstat (limited to 'app/relay')
| -rw-r--r-- | app/relay/index.js | 23 | ||||
| -rw-r--r-- | app/relay/interpreters.js | 24 | ||||
| -rw-r--r-- | app/relay/runner.js | 26 |
3 files changed, 55 insertions, 18 deletions
diff --git a/app/relay/index.js b/app/relay/index.js index d43f221..2f93644 100644 --- a/app/relay/index.js +++ b/app/relay/index.js @@ -9,10 +9,7 @@ let remote = io.connect(process.env.SOCKETIO_REMOTE) remote.on('cmd', (data) => { console.log('cmd data', data) - if (! data.cmd) { - console.log('malformed param...?') - return - } + if (! data.cmd) return console.log('malformed param...?') console.log('got', data.cmd) switch (data.cmd) { case 'set_param': @@ -43,6 +40,24 @@ remote.on('cmd', (data) => { } }) +remote.on('system', (data) => { + console.log('system:', data.cmd) + switch(data.cmd) { + case 'run_system_command': + runner.run_system_command(data.payload, (error, stdout, stderr) => { + remote.emit('system_res', { + type: 'command_output', + cmd: data.payload, + error, stdout, stderr + }) + }) + break + default: + remote.emit('system_res', { error: 'unknown system command' }) + break + } +}) + let rpc = new zerorpc.Client() rpc.connect('tcp://127.0.0.1:' + process.env.RPC_PORT) rpc.on('error', function(error) { diff --git a/app/relay/interpreters.js b/app/relay/interpreters.js index 1adb95e..c276f94 100644 --- a/app/relay/interpreters.js +++ b/app/relay/interpreters.js @@ -1,4 +1,16 @@ export default { + bash: { + cmd: process.env.BASH_BIN || '/bin/bash', + gpu: false, + }, + perl: { + cmd: process.env.PERL_BIN || '/usr/bin/perl', + gpu: false, + }, + python: { + cmd: process.env.PYTHON_BIN, + gpu: false, + }, pytorch: { cmd: process.env.PYTORCH_BIN, gpu: true, @@ -7,16 +19,4 @@ export default { cmd: process.env.TENSORFLOW_BIN, gpu: true, }, - python: { - cmd: process.env.PYTHON_BIN, - gpu: false, - }, - bash: { - cmd: process.env.BASH_BIN || '/bin/bash', - gpu: false, - } - perl: { - cmd: process.env.PERL_BIN || '/usr/bin/perl', - gpu: false, - } }
\ No newline at end of file diff --git a/app/relay/runner.js b/app/relay/runner.js index caa2ded..715be7b 100644 --- a/app/relay/runner.js +++ b/app/relay/runner.js @@ -1,7 +1,7 @@ // monitors which process is currently running // kills it if need be.... murder -import { spawn } from 'child_process' +import { execFile, spawn } from 'child_process' import interpreters from './interpreters' import modules from './modules' import { kill } from 'tree-kill' @@ -43,6 +43,21 @@ export function build_params(module, task) { } } +export function run_system_command(cmd, cb) { + console.log('running system command:', cmd) + switch(cmd) { + case 'nvidia-smi': + case 'ps': + case 'uptime': + case 'w': + execFile(cmd, cb) + break + default: + cb({ error: 'no such command' }) + break + } +} + export function run_task(module_name, task){ const module = modules['module_name'] if (! module) throw new Error("No such module") @@ -52,9 +67,16 @@ export function run_task(module_name, task){ const subprocess = spawn(activity.interpreter, params) if (activity.gpu) { state.current_gpu_task = subprocess - } else { + } + else { state.current_cpu_task = subprocess } + subprocess.stdout.on('data', data => { + console.log('stdout', subprocess.pid, data) + }) + subprocess.stderr.on('data', data => { + console.log('stderr', subprocess.pid, data) + }) subprocess.on('error', (err) => { console.log('process error', subprocess.pid, err) }) |
