1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-11 05:17:41 +03:00

F #3951: FireEdge server adjustments (#809)

Co-authored-by: Jorge Lobo <jlobo@opennebula.systems>
This commit is contained in:
Jorge Miguel Lobo Escalona 2021-02-15 16:05:52 +01:00 committed by GitHub
parent f9c4f15704
commit 024ee70a11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 13 deletions

View File

@ -145,7 +145,7 @@ const appServer = validateServerIsSecure()
)
: unsecureServer(app)
websockets(appServer)
const sockets = websockets(appServer) || []
let config = {
color: 'red',
@ -164,3 +164,23 @@ appServer.listen(port, '0.0.0.0', err => {
})
vmrcUpgrade(appServer)
guacamole(appServer)
function handleBreak (code) {
if (appServer && appServer.close && typeof appServer.close === 'function') {
appServer.close(() => {
// this close sockets
sockets.forEach((socket) => {
if (socket && socket.close && typeof socket.close === 'function') {
socket.close()
}
})
process.exit(0)
})
}
}
const eventProcess = ['SIGINT', 'SIGTERM']
eventProcess.forEach((nameEvent = '') => {
if (nameEvent) {
process.on(nameEvent, handleBreak)
}
})

View File

@ -509,9 +509,6 @@ const createProvision = (res = {}, next = () => undefined, params = {}, userData
// This function is only executed if the command is completed
const close = (success, lastLine) => {
stream.end()
const removeConfigFile = (file) => {
removeFile(file)
}
if (success && regexp.test(lastLine)) {
const newPath = renameFolder(config.path, lastLine.match('\\d+'), 'replace', removeConfigFile)
if (newPath) {
@ -541,7 +538,7 @@ const createProvision = (res = {}, next = () => undefined, params = {}, userData
}
}
if (success === false) {
renameFolder(config.path, appendError, 'append', removeConfigFile)
renameFolder(config.path, appendError, 'append')
}
}

View File

@ -24,6 +24,7 @@ const {
// user config
const websockets = (appServer = {}) => {
const sockets = []
if (
appServer &&
appServer.constructor &&
@ -31,11 +32,12 @@ const websockets = (appServer = {}) => {
appServer.constructor.name === 'Server'
) {
const io = socketIO({ path: defaultEndpointWebsocket }).listen(appServer)
defaultFilesWebsockets.map(file => {
defaultFilesWebsockets.forEach(file => {
try {
// eslint-disable-next-line global-require
const fileInfo = require(`./${file}`)
if (fileInfo.main && typeof fileInfo.main === 'function') {
sockets.push(io)
fileInfo.main(io)
}
} catch (error) {
@ -47,6 +49,7 @@ const websockets = (appServer = {}) => {
}
})
}
return sockets
}
module.exports = {

View File

@ -18,11 +18,21 @@ const { messageTerminal } = require('server/utils/general')
const { subscriber } = require('server/routes/api/provision/functions')
const type = 'provision'
const main = (app = {}) => {
const configErrorProvision = (error = '') => {
return {
color: 'red',
type: error,
message: '%s'
}
}
try {
app
.use(authWebsocket)
.on('connection', (server = {}) => {
server.on('disconnect', () => { console.log('disconnect') })
server.on('disconnect', () => {
messageTerminal(configErrorProvision('disconnect'))
})
subscriber(
'oneprovision',
data => {
@ -31,12 +41,7 @@ const main = (app = {}) => {
)
})
} catch (error) {
const configErrorProvision = {
color: 'red',
type: error,
message: '%s'
}
messageTerminal(configErrorProvision)
messageTerminal(configErrorProvision(error))
}
}