|
|
@ -2,28 +2,43 @@ import { getgid, getuid, setgid, setuid } from 'process'; |
|
|
|
|
|
|
|
|
|
|
|
import { PGID, PUID, PORT, ECODE_DROP_PRIVILEGES } from './lib/consts'; |
|
|
|
import { PGID, PUID, PORT, ECODE_DROP_PRIVILEGES } from './lib/consts'; |
|
|
|
|
|
|
|
|
|
|
|
import app from './app'; |
|
|
|
import { access } from './lib/accessModule'; |
|
|
|
import { proxyServerVncUpgrade } from './middlewares'; |
|
|
|
|
|
|
|
import { stderr, stdout } from './lib/shell'; |
|
|
|
import { stderr, stdout } from './lib/shell'; |
|
|
|
|
|
|
|
|
|
|
|
(async () => { |
|
|
|
/** |
|
|
|
stdout(`Starting main process with ownership ${getuid()}:${getgid()}`); |
|
|
|
* Wait until the anvil-access-module daemon finishes its setup before doing |
|
|
|
|
|
|
|
* anything else. |
|
|
|
const server = (await app).listen(PORT, () => { |
|
|
|
* |
|
|
|
try { |
|
|
|
* Notes: |
|
|
|
// Group must be set before user to avoid permission error.
|
|
|
|
* * The webpackMode directive tells webpack to include the dynamic module into
|
|
|
|
setgid(PGID); |
|
|
|
* the main bundle. Webpack defaults to put such modules in separate files to |
|
|
|
setuid(PUID); |
|
|
|
* reduce the amount of loading. |
|
|
|
|
|
|
|
*/ |
|
|
|
stdout(`Main process ownership changed to ${getuid()}:${getgid()}.`); |
|
|
|
access.once('active', async () => { |
|
|
|
} catch (error) { |
|
|
|
const { default: app } = await import(/* webpackMode: "eager" */ './app'); |
|
|
|
stderr(`Failed to change main process ownership; CAUSE: ${error}`); |
|
|
|
const { proxyServerVncUpgrade } = await import( |
|
|
|
|
|
|
|
/* webpackMode: "eager" */ './middlewares' |
|
|
|
process.exit(ECODE_DROP_PRIVILEGES); |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
(async () => { |
|
|
|
stdout(`Listening on localhost:${PORT}.`); |
|
|
|
stdout(`Starting main process with ownership ${getuid()}:${getgid()}`); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const server = (await app).listen(PORT, () => { |
|
|
|
server.on('upgrade', proxyServerVncUpgrade); |
|
|
|
try { |
|
|
|
})(); |
|
|
|
// Group must be set before user to avoid permission error.
|
|
|
|
|
|
|
|
setgid(PGID); |
|
|
|
|
|
|
|
setuid(PUID); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stdout(`Main process ownership changed to ${getuid()}:${getgid()}.`); |
|
|
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
|
|
stderr(`Failed to change main process ownership; CAUSE: ${error}`); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
process.exit(ECODE_DROP_PRIVILEGES); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stdout(`Listening on localhost:${PORT}.`); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server.on('upgrade', proxyServerVncUpgrade); |
|
|
|
|
|
|
|
})(); |
|
|
|
|
|
|
|
}); |
|
|
|