mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-04-24 04:55:42 +00:00
Separate vpn connecting.
This commit is contained in:
parent
a7f5689873
commit
c5506d4566
@ -3,7 +3,6 @@ fs = Promise.promisifyAll(require('fs'))
|
||||
os = require 'os'
|
||||
knex = require './db'
|
||||
utils = require './utils'
|
||||
{spawn} = require 'child_process'
|
||||
bootstrap = require './bootstrap'
|
||||
config = require './config'
|
||||
|
||||
@ -32,19 +31,10 @@ knex('config').select('value').where(key: 'uuid').then ([ uuid ]) ->
|
||||
api = require './api'
|
||||
application = require './application'
|
||||
supervisor = require './supervisor-update'
|
||||
vpn = require './lib/vpn'
|
||||
|
||||
console.log('Starting OpenVPN..')
|
||||
openvpn = spawn('openvpn', [ 'client.conf' ], cwd: '/data')
|
||||
|
||||
# Prefix and log all OpenVPN output
|
||||
openvpn.stdout.on 'data', (data) ->
|
||||
prefix = 'OPENVPN: '
|
||||
console.log((prefix + data).trim().replace(/\n/gm, "\n#{prefix}"))
|
||||
|
||||
# Prefix and log all OpenVPN output
|
||||
openvpn.stderr.on 'data', (data) ->
|
||||
prefix = 'OPENVPN: '
|
||||
console.log((prefix + data).trim().replace(/\n/gm, "\n#{prefix}"))
|
||||
setImmediate(vpn.connect)
|
||||
|
||||
console.log('Starting API server..')
|
||||
api.listen(80)
|
||||
|
@ -1,8 +1,10 @@
|
||||
Promise = require 'bluebird'
|
||||
_ = require 'lodash'
|
||||
csrgen = Promise.promisify require 'csr-gen'
|
||||
fs = Promise.promisifyAll require 'fs'
|
||||
request = Promise.promisifyAll require 'request'
|
||||
url = require 'url'
|
||||
{spawn} = require 'child_process'
|
||||
|
||||
exports.generate = (apiEndpoint, userConfig) ->
|
||||
# Generate SSL certificate
|
||||
@ -49,4 +51,17 @@ exports.generate = (apiEndpoint, userConfig) ->
|
||||
fs.writeFileAsync('/data/ca.crt', body.ca)
|
||||
fs.writeFileAsync('/data/client.crt', body.cert)
|
||||
vpnConf
|
||||
])
|
||||
])
|
||||
|
||||
exports.connect = ->
|
||||
openvpn = spawn('openvpn', [ 'client.conf' ], cwd: '/data')
|
||||
|
||||
# Prefix and log all OpenVPN output
|
||||
openvpn.stdout.on 'data', (data) ->
|
||||
prefix = 'OPENVPN: '
|
||||
console.log((prefix + data).trim().replace(/\n/gm, "\n#{prefix}"))
|
||||
|
||||
# Prefix and log all OpenVPN output
|
||||
openvpn.stderr.on 'data', (data) ->
|
||||
prefix = 'OPENVPN: '
|
||||
console.log((prefix + data).trim().replace(/\n/gm, "\n#{prefix}"))
|
||||
|
Loading…
x
Reference in New Issue
Block a user