mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-23 23:42:29 +00:00
Remove the old terminal code, since it has been replaced by v2 which does not require supervisor support.
This commit is contained in:
parent
e061e855c8
commit
135365cf37
72
docs/API.md
72
docs/API.md
@ -107,78 +107,6 @@ $
|
||||
|
||||
<hr>
|
||||
|
||||
### POST /v1/spawn-tty
|
||||
|
||||
Starts a web terminal session.
|
||||
|
||||
When successful, responds with 200 and the URL of the terminal.
|
||||
|
||||
#### Request body
|
||||
Has to be a JSON object with an `appId` property, corresponding to the ID of the application the device is running.
|
||||
Example:
|
||||
```json
|
||||
{
|
||||
"appId": 2167
|
||||
}
|
||||
```
|
||||
|
||||
#### Examples:
|
||||
From the app on the device:
|
||||
```bash
|
||||
$ curl -X POST --header "Content-Type:application/json" \
|
||||
--data '{"appId": <appId>}' \
|
||||
"$RESIN_SUPERVISOR_ADDRESS/v1/spawn-tty?apikey=$RESIN_SUPERVISOR_API_KEY"
|
||||
```
|
||||
Response:
|
||||
```none
|
||||
http://124135325.ngrok.com
|
||||
```
|
||||
|
||||
Remotely via the API proxy:
|
||||
```bash
|
||||
$ curl -X POST --header "Content-Type:application/json" \
|
||||
--header "Authorization: Bearer <auth token>" \
|
||||
--data '{"deviceId": <deviceId>, "appId": <appId>, "data": {"appId": <appId>}}' \
|
||||
"https://api.resin.io/supervisor/v1/spawn-tty"
|
||||
```
|
||||
|
||||
<hr>
|
||||
|
||||
### POST /v1/despawn-tty
|
||||
|
||||
Stops a web terminal session.
|
||||
|
||||
When successful, responds with an empty 200 response.
|
||||
|
||||
#### Request body
|
||||
Has to be a JSON object with an `appId` property, corresponding to the ID of the application the device is running.
|
||||
Example:
|
||||
```json
|
||||
{
|
||||
"appId": 2167
|
||||
}
|
||||
```
|
||||
|
||||
#### Examples:
|
||||
From the app on the device:
|
||||
```bash
|
||||
$ curl -X POST --header "Content-Type:application/json" \
|
||||
--data '{"appId": <appId>}' \
|
||||
"$RESIN_SUPERVISOR_ADDRESS/v1/despawn-tty?apikey=$RESIN_SUPERVISOR_API_KEY"
|
||||
```
|
||||
|
||||
(Empty response)
|
||||
|
||||
Remotely via the API proxy:
|
||||
```bash
|
||||
$ curl -X POST --header "Content-Type:application/json" \
|
||||
--header "Authorization: Bearer <auth token>" \
|
||||
--data '{"deviceId": <deviceId>, "appId": <appId>, "data": {"appId": <appId>}}' \
|
||||
"https://api.resin.io/supervisor/v1/despawn-tty"
|
||||
```
|
||||
|
||||
<hr>
|
||||
|
||||
### POST /v1/reboot
|
||||
|
||||
Reboots the device
|
||||
|
@ -19,16 +19,13 @@
|
||||
"lodash": "^3.0.0",
|
||||
"mixpanel": "0.0.20",
|
||||
"network-checker": "~0.0.5",
|
||||
"ngrok": "~0.1.97",
|
||||
"pinejs-client": "^1.7.1",
|
||||
"pubnub": "^3.7.13",
|
||||
"request": "^2.51.0",
|
||||
"resin-register-device": "^2.0.0",
|
||||
"request-progress": "^0.3.1",
|
||||
"rwlock": "^5.0.0",
|
||||
"server-destroy": "^1.0.0",
|
||||
"sqlite3": "~3.0.4",
|
||||
"tty.js": "0.2.14-1",
|
||||
"typed-error": "~0.1.0"
|
||||
},
|
||||
"engines": {
|
||||
|
@ -1,7 +1,6 @@
|
||||
Promise = require 'bluebird'
|
||||
fs = Promise.promisifyAll require 'fs'
|
||||
utils = require './utils'
|
||||
tty = require './lib/tty'
|
||||
knex = require './db'
|
||||
express = require 'express'
|
||||
bodyParser = require 'body-parser'
|
||||
@ -37,36 +36,6 @@ module.exports = (application) ->
|
||||
application.update(req.body.force)
|
||||
res.sendStatus(204)
|
||||
|
||||
api.post '/v1/spawn-tty', (req, res) ->
|
||||
appId = req.body.appId
|
||||
utils.mixpanelTrack('Spawn tty', appId)
|
||||
if !appId?
|
||||
return res.status(400).send('Missing app id')
|
||||
knex('app').select().where({ appId })
|
||||
.then ([ app ]) ->
|
||||
if !app?
|
||||
throw new Error('App not found')
|
||||
tty.start(app)
|
||||
.then ({url}) ->
|
||||
res.status(200).send(url)
|
||||
.catch (err) ->
|
||||
res.status(503).send(err?.message or err or 'Unknown error')
|
||||
|
||||
api.post '/v1/despawn-tty', (req, res) ->
|
||||
appId = req.body.appId
|
||||
utils.mixpanelTrack('Despawn tty', appId)
|
||||
if !appId?
|
||||
return res.status(400).send('Missing app id')
|
||||
knex('app').select().where({ appId })
|
||||
.then ([ app ]) ->
|
||||
if !app?
|
||||
throw new Error('App not found')
|
||||
tty.stop(app)
|
||||
.then ->
|
||||
res.sendStatus(200)
|
||||
.catch (err) ->
|
||||
res.status(503).send(err?.message or err or 'Unknown error')
|
||||
|
||||
api.post '/v1/reboot', (req, res) ->
|
||||
utils.mixpanelTrack('Reboot')
|
||||
request.post(config.gosuperAddress + '/v1/reboot')
|
||||
|
@ -7,7 +7,6 @@ config = require './config'
|
||||
dockerUtils = require './docker-utils'
|
||||
Promise = require 'bluebird'
|
||||
utils = require './utils'
|
||||
tty = require './lib/tty'
|
||||
logger = require './lib/logger'
|
||||
{ cachedResinApi } = require './request'
|
||||
device = require './device'
|
||||
@ -100,12 +99,7 @@ application.kill = kill = (app, updateDB = true) ->
|
||||
logSystemEvent(logTypes.stopApp, app)
|
||||
device.updateState(status: 'Stopping')
|
||||
container = docker.getContainer(app.containerId)
|
||||
tty.stop(app)
|
||||
.catch (err) ->
|
||||
console.error('Error stopping tty', err)
|
||||
return # Even if stopping the tty fails we want to finish stopping the container
|
||||
.then ->
|
||||
container.stopAsync(t: 10)
|
||||
container.stopAsync(t: 10)
|
||||
.then ->
|
||||
container.removeAsync(v: true)
|
||||
# Bluebird throws OperationalError for errors resulting in the normal execution of a promisified function.
|
||||
|
@ -1,65 +0,0 @@
|
||||
html, body {
|
||||
display: block;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
body > h1 {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#help, #lights {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#open {
|
||||
position: static;
|
||||
|
||||
-ms-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-webkit-user-select: none;
|
||||
user-select: none;
|
||||
background: #75ddff;
|
||||
border: 1px solid #5cd6ff;
|
||||
-moz-border-radius: 4px;
|
||||
-webkit-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
-webkit-box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
color: white;
|
||||
cursor: pointer;
|
||||
outline: 0;
|
||||
display: inline-block;
|
||||
font-size: 15px;
|
||||
font-weight: normal;
|
||||
line-height: 21px;
|
||||
margin-bottom: 0;
|
||||
padding: 6px 12px;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
text-transform: uppercase;
|
||||
vertical-align: middle;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
#open:hover, #open:active {
|
||||
outline: 0;
|
||||
background-color: #42d0ff;
|
||||
border-color: #1ec7ff;
|
||||
color: white;
|
||||
}
|
||||
|
||||
#open:active {
|
||||
-moz-box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
|
||||
-webkit-box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
|
||||
box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
|
||||
}
|
||||
|
||||
.window {
|
||||
margin-left: 20px;
|
||||
margin-top: 20px;
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
_ = require 'lodash'
|
||||
Promise = require 'bluebird'
|
||||
TypedError = require 'typed-error'
|
||||
|
||||
# Only load ngrok/tty when they are actually needed,
|
||||
# to reduce memory in the likely case they are never used.
|
||||
ngrok = null
|
||||
tty = null
|
||||
enableDestroy = null
|
||||
init = _.once ->
|
||||
ngrok = Promise.promisifyAll require 'ngrok'
|
||||
tty = Promise.promisifyAll require 'tty.js'
|
||||
enableDestroy = require 'server-destroy'
|
||||
|
||||
class DisconnectedError extends TypedError
|
||||
|
||||
# socat UNIX:/data/host -,raw,echo=0
|
||||
|
||||
apps = {}
|
||||
nextPort = 81
|
||||
exports.start = (app) ->
|
||||
init()
|
||||
apps[app.id] ?= Promise.rejected()
|
||||
return apps[app.id] = apps[app.id].catch ->
|
||||
port = nextPort++
|
||||
server = tty.createServer
|
||||
shell: './src/enterContainer.sh'
|
||||
shellArgs: do ->
|
||||
i = 0
|
||||
return (session) -> [ app.containerId, session.id, i++ ]
|
||||
static: __dirname + '/static'
|
||||
enableDestroy(server.server)
|
||||
Promise.props
|
||||
server: server.listenAsync(port, null).return(server.server)
|
||||
url: ngrok.connectAsync(port)
|
||||
|
||||
exports.stop = (app) ->
|
||||
if !apps[app.id]?
|
||||
return Promise.resolve()
|
||||
apps[app.id] = apps[app.id].then ({server, url}) ->
|
||||
destroy = Promise.promisify(server.destroy, server)
|
||||
Promise.join(
|
||||
destroy()
|
||||
# ngrok must have been loaded already or we wouldn't have a url to disconnect from.
|
||||
ngrok.disconnectAsync(url)
|
||||
->
|
||||
# We throw an error so that `.start` will catch and restart the session.
|
||||
throw new DisconnectedError()
|
||||
)
|
||||
return apps[app.id].catch DisconnectedError, -> # All good, since we want to disconnect here!
|
Loading…
Reference in New Issue
Block a user