forked from NodeOS-Legacy/nodeos-mount-rootfs
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathserver.js
executable file
·67 lines (52 loc) · 1.59 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env node
const readFile = require('fs').readFile
const basicEnvironment = require('nodeos-boot-singleUser')
const linuxCmdline = require('linux-cmdline')
const mountUsersFS = require('nodeos-boot-singleUserMount')
const rimraf = require('rimraf').sync
const startRepl = require('nodeos-mount-utils').startRepl
const prepareSessions = require('.')
const MOUNTPOINT = '/tmp'
/**
* This error handler traces the error and starts a Node.js REPL
*
* @param {Error} error The error that gets traced
*/
function onerror(error)
{
console.trace(error)
startRepl('NodeOS-boot-multiuser')
}
basicEnvironment(function(error)
{
if(error) return onerror(error)
// Get Linux kernel command line arguments
readFile('/proc/cmdline', 'utf8', function(error, data)
{
if(error) return onerror(error)
var cmdline = linuxCmdline(data)
// Mount users filesystem
mountUsersFS(MOUNTPOINT, cmdline, function(error)
{
if(error) return onerror(error)
prepareSessions(MOUNTPOINT, cmdline.single, function(error)
{
if(error) return onerror(error)
// Remove from initramfs the files only needed on boot to free memory
try
{
rimraf('/bin/nodeos-boot-multiuser')
rimraf('/init')
rimraf('/lib/node_modules/nodeos-boot-multiuser')
rimraf('/sbin')
}
catch(error)
{
// If `rootfs` is read-only (like in `vagga`), ignore the error
if(error.code !== 'EROFS') return callback(error)
}
// KTHXBYE >^.^<
})
})
})
})