mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-11 05:17:41 +03:00
Co-authored-by: Jorge Lobo <jlobo@opennebula.systems>
This commit is contained in:
parent
f9c4f15704
commit
024ee70a11
@ -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)
|
||||
}
|
||||
})
|
||||
|
@ -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')
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 = {
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user