-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·73 lines (55 loc) · 1.43 KB
/
index.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
68
69
70
71
72
73
#!/usr/bin/env node
var fs = require('fs')
var spawn = require('child_process').spawn
var utils = require('nodeos-mount-utils');
var mount = require('nodeos-mount');
function startRepl(error)
{
console.warn(error)
utils.startRepl('NodeOS-usersfs')
}
exports.startRepl = startRepl;
function exec(command, args)
{
spawn(command, args || [],
{
stdio: 'inherit',
detached: true
})
.on('error', startRepl)
.unref();
}
// Mount users filesystem
var envDev = 'USERS'
var path = '/home';
var type = process.env.ROOTFSTYPE || 'auto';
var flags = utils.flags.MS_NODEV | utils.flags.MS_NOSUID;
utils.mountfs(envDev, path, type, flags, function(error)
{
// Error mounting the users filesystem, enable REPL
if(error) return startRepl(error)
// // Re-mount / as read-only
// var rootfspath = '/';
// var flags = mount.flags.MS_REMOUNT | mount.flags.MS_RDONLY;
//
// var res = mount.mount('', rootfspath, flags);
// if(res == -1) console.error('Error re-mounting '+rootfspath+' as read-only')
// Start global system services
exec('forever-starter');
// Start users services
exec('forever', ['start', '-m', '1', 'bin/users-services', path]);
// Start command given as parameter
if(process.argv.length > 2)
{
try
{
fs.statSync('/.dockerinit')
}
catch(error)
{
if(error.code != 'ENOENT') throw error
return
}
exec(process.argv[2], process.argv.splice(3));
}
})