Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50640 views
#!/usr/bin/env python

import os, sys

if not 'SMC' in os.environ:
    os.environ['SMC'] = os.path.join(os.environ['HOME'], '.smc')

# See https://github.com/sagemathinc/cocalc/issues/973.
# If the HOME path is long, the forever monitor just spins out of
# control (using all CPU), since it truncates the path at some
# meaningless length.
if len(os.environ['SMC']) > 90:
    # Note -- this directory will leak, but it doesn't have much in it, and this
    # will only ever be used for development, so I'm not going to worry about that.
    os.environ['FOREVER_ROOT'] = '/tmp/forever-%s'%os.environ['USER']

os.chdir(os.path.split(os.path.realpath(__file__))[0] + '/..')

data = os.path.join(os.environ['SMC'], 'console_server')
if not os.path.exists(data):
    os.makedirs(data)
elif sys.argv[1] == 'start':
    for x in os.listdir(data):
        os.unlink(os.path.join(data, x))

path = os.path.split(os.path.realpath(__file__))[0] + '/..'
target = os.path.abspath(os.path.join(path, 'console_server.coffee'))

cmd = "forever %s -c coffee  -l $SMC/console_server/console_server.log --pidFile $SMC/console_server/console_server.pid -p $SMC/forever/  %s"%(sys.argv[1], target)

os.system(cmd)