Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 39534
1
###
2
The port_manager manages the ports for the various servers.
3
4
It reads the port from memory or from disk and returns it.
5
###
6
7
fs = require('fs')
8
misc_node = require('smc-util-node/misc_node')
9
10
SMC = process.env.SMC
11
12
exports.port_file = port_file = (type) ->
13
return "#{SMC}/#{type}_server/#{type}_server.port"
14
15
ports = {}
16
exports.get_port = (type, cb) -> # cb(err, port number)
17
if ports[type]?
18
cb(false, ports[type])
19
else
20
fs.readFile misc_node.abspath(port_file(type)), (err, content) ->
21
if err
22
cb(err)
23
else
24
try
25
ports[type] = parseInt(content)
26
cb(false, ports[type])
27
catch e
28
cb("#{type}_server port file corrupted")
29
30
exports.forget_port = (type) ->
31
if ports[type]?
32
delete ports[type]
33