mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-03-21 19:45:19 +00:00
Enable spawning a tty.js tunnel.
This commit is contained in:
parent
aab2a3b3d3
commit
1b0e364322
1
bin/enter.sh
Normal file
1
bin/enter.sh
Normal file
@ -0,0 +1 @@
|
||||
nsenter --target $(docker inspect --format '{{.State.Pid}}' $1) --mount --uts --ipc --net --pid bash
|
2
deps.sh
2
deps.sh
@ -11,4 +11,4 @@ fi
|
||||
|
||||
# System dependencies
|
||||
apt-get -q update
|
||||
apt-get install -qqy openvpn libsqlite3-dev
|
||||
apt-get install -qqy openvpn libsqlite3-dev socat
|
||||
|
@ -4,6 +4,7 @@
|
||||
"scripts": {
|
||||
"preinstall": "bash deps.sh",
|
||||
"postinstall": "bash postinstall.sh",
|
||||
"prestart": "cp bin/enter.sh /data/enter.sh && chmod +x /data/enter.sh",
|
||||
"start": "./entry.sh"
|
||||
},
|
||||
"dependencies": {
|
||||
@ -17,11 +18,13 @@
|
||||
"knex": "~0.5.1",
|
||||
"lodash": "~2.4.1",
|
||||
"mixpanel": "0.0.20",
|
||||
"ngrok": "~0.1.97",
|
||||
"ping": "0.1.8",
|
||||
"pubnub": "~3.6.4",
|
||||
"request": "~2.22.0",
|
||||
"resin-platform-api": "git+ssh://git@bitbucket.org:rulemotion/resin-platform-api.git#v0.2.3",
|
||||
"sqlite3": "~2.1.19"
|
||||
"sqlite3": "~2.1.19",
|
||||
"tty.js": "~0.2.13"
|
||||
},
|
||||
"engines": {
|
||||
"node": "0.10.22"
|
||||
|
@ -4,8 +4,10 @@ utils = require './utils'
|
||||
express = require 'express'
|
||||
application = require './application'
|
||||
supervisor = require './supervisor-update'
|
||||
tty = require './tty'
|
||||
|
||||
api = express()
|
||||
api.use(express.bodyParser())
|
||||
|
||||
api.post '/v1/blink', (req, res) ->
|
||||
utils.mixpanelTrack('Device blink')
|
||||
@ -25,4 +27,15 @@ api.post '/v1/update-supervisor', (req, res) ->
|
||||
supervisor.update()
|
||||
res.send(204)
|
||||
|
||||
api.post '/v1/spawn-tty', (req, res) ->
|
||||
appId = req.body.appId
|
||||
utils.mixpanelTrack('Spawn tty', appId)
|
||||
if !appId?
|
||||
res.send(400, 'Missing app id')
|
||||
tty.start(appId)
|
||||
.then (url) ->
|
||||
res.send(200, url)
|
||||
.catch (err) ->
|
||||
res.send(404, err)
|
||||
|
||||
module.exports = api
|
||||
|
11
src/enterContainer.sh
Normal file
11
src/enterContainer.sh
Normal file
@ -0,0 +1,11 @@
|
||||
SOCKET_NAME=test-${1}-${2}-${3}
|
||||
HOST_DATA_PATH=/resin-data/resin-supervisor
|
||||
HOST_SOCKET=${HOST_DATA_PATH}/${SOCKET_NAME}
|
||||
SUPERVISOR_SOCKET_PATH=/data
|
||||
|
||||
echo "
|
||||
rm -f ${HOST_SOCKET}
|
||||
socat UNIX-LISTEN:${HOST_SOCKET} EXEC:'${HOST_DATA_PATH}/enter.sh ${1}',pty,setsid,setpgid,stderr,ctty &
|
||||
exit
|
||||
" | socat UNIX:${SUPERVISOR_SOCKET_PATH}/host -
|
||||
socat UNIX:${SUPERVISOR_SOCKET_PATH}/${SOCKET_NAME} -,raw,echo=0
|
25
src/tty.coffee
Normal file
25
src/tty.coffee
Normal file
@ -0,0 +1,25 @@
|
||||
Promise = require 'bluebird'
|
||||
ngrok = Promise.promisifyAll require 'ngrok'
|
||||
tty = Promise.promisifyAll require 'tty.js'
|
||||
knex = require './db'
|
||||
|
||||
# socat UNIX:/data/host -,raw,echo=0
|
||||
|
||||
apps = {}
|
||||
nextPort = 81
|
||||
exports.start = (appId) ->
|
||||
apps[appId] ?= Promise.rejected()
|
||||
return apps[appId] = apps[appId].catch ->
|
||||
port = nextPort++
|
||||
knex('app').select().where({appId})
|
||||
.then ([app]) ->
|
||||
if !app?
|
||||
throw new Error('App not found')
|
||||
tty.createServer
|
||||
shell: './src/enterContainer.sh'
|
||||
shellArgs: do ->
|
||||
i = 0
|
||||
return (session) -> [app.containerId, session.id, i++]
|
||||
.listenAsync(port, null)
|
||||
.then ->
|
||||
ngrok.connectAsync(port)
|
Loading…
x
Reference in New Issue
Block a user