AstroJS/botan-start.py

58 lines
1.4 KiB
Python
Raw Permalink Normal View History

2016-05-27 17:39:59 +00:00
#!env/bin/python
2015-08-14 10:12:10 +00:00
2016-05-27 17:39:59 +00:00
import os, sys
2016-05-27 16:20:58 +00:00
from botanjs.config import Config as config, DEBUG
2016-05-27 17:39:59 +00:00
from subprocess import Popen
from botanjs.service.webapi import WebAPI
2015-08-14 10:12:10 +00:00
2016-05-27 16:20:58 +00:00
SiteRoot = os.path.abspath( "." )
2015-08-14 10:12:10 +00:00
2016-05-27 17:39:59 +00:00
# Setting the SiteRoot for config
2016-05-27 16:20:58 +00:00
config["Paths"]["SiteRoot"] = SiteRoot;
2015-08-14 10:12:10 +00:00
# Create the lock folder for celery
2016-10-26 07:29:08 +00:00
lockDir = os.path.join( SiteRoot, "env", "var", "run", "celery" )
2015-08-14 10:12:10 +00:00
2016-05-27 16:20:58 +00:00
os.makedirs( lockDir, exist_ok=True )
2015-08-14 10:12:10 +00:00
sys.path.append( os.path.abspath( "." ) )
2016-05-27 17:39:59 +00:00
RUNTIME_ENV = os.path.abspath( os.path.join( "env", "bin" ) )
if RUNTIME_ENV not in os.environ[ "PATH" ]:
os.environ[ "PATH" ] = RUNTIME_ENV + os.pathsep + os.environ[ "PATH" ]
2015-08-14 10:12:10 +00:00
if __name__ == "__main__":
jwork = "botanjs.service.jwork"
nodeName = "botanNode1"
2016-05-27 16:20:58 +00:00
celOut = open( os.path.join( config["Paths"]["Log"], jwork + "-err.log" ), "a+" )
cel = Popen(
[
"celery", "multi", "restart", nodeName
, "-A", jwork, "worker"
2016-10-26 07:29:08 +00:00
, "--pidfile=" + os.path.join( lockDir, jwork + ".pid" )
2016-05-27 16:20:58 +00:00
, "--logfile=" + os.path.join( config["Paths"]["Log"], jwork + ".log" )
, "--workdir=" + config["Paths"]["Runtime"]
, "beat", "-l", "info"
]
, stdout = celOut
, stderr = celOut
2015-11-24 11:30:53 +00:00
)
2015-08-14 10:12:10 +00:00
2016-05-27 16:20:58 +00:00
celOut.close()
if not DEBUG and os.fork():
import logging
logging.basicConfig(
filename = os.path.join( config["Paths"]["Log"], "access.log" )
, level = logging.DEBUG
)
sys.exit()
2015-08-14 10:12:10 +00:00
WebAPI(
jsCache = config["Paths"]["Cache"]
, jsRoot = config["BotanJS"]["SrcDir"]
, brokerURL = config["BotanJS"]["CeleryBroker"]
)