Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 39539
1
2
3
# Deprecated -- tons of work, but really Kubernetes is the way to go...
4
5
###########################
6
# Command line interface for VM manager
7
###########################
8
9
{join} = require('path')
10
11
winston = require('winston')
12
winston.remove(winston.transports.Console)
13
winston.add(winston.transports.Console, {level: 'debug', timestamp:true, colorize:true})
14
15
async = require('async')
16
misc_node = require('smc-util-node/misc_node')
17
program = require('commander')
18
19
LOGS = join(process.env.HOME, 'logs')
20
program.usage('[start/stop/restart/status] [options]')
21
.option('--pidfile [string]', 'store pid in this file', String, "#{LOGS}/smc-vm-manager.pid")
22
.option('--logfile [string]', 'write log to this file', String, "#{LOGS}/smc-vm-manager.log")
23
.option('--db [string]', 'comma separated database servers', String, process.env.SMC_DB_HOSTS ? 'db0')
24
.option('-e') # gets passed by coffee -e
25
.parse(process.argv)
26
27
db_hosts = program.db.split(',')
28
29
start_server = () ->
30
require('smc-hub/rethink').rethinkdb
31
hosts : db_hosts
32
pool : 1
33
cb : (err, db) =>
34
g = require('smc-hub/smc_gcloud.coffee').gcloud(db:db)
35
vms = g.vm_manager()
36
37
main = () ->
38
winston.debug("running as a deamon")
39
# run as a server/daemon (otherwise, is being imported as a library)
40
process.addListener "uncaughtException", (err) ->
41
winston.debug("BUG ****************************************************************************")
42
winston.debug("Uncaught exception: " + err)
43
winston.debug(err.stack)
44
winston.debug("BUG ****************************************************************************")
45
46
async.series([
47
(cb) ->
48
misc_node.ensure_containing_directory_exists(program.pidfile, cb)
49
(cb) ->
50
misc_node.ensure_containing_directory_exists(program.logfile, cb)
51
(cb) ->
52
daemon = require("start-stop-daemon") # don't import unless in a script; otherwise breaks in node v6+
53
daemon({max:9999, pidFile:program.pidfile, outFile:program.logfile, errFile:program.logfile, logFile:'/dev/null'}, start_server)
54
])
55
56
if program._name.split('.')[0] == 'smc-vm-manager'
57
main()
58
59