AstroJS/botan-start.py

58 lines
1.2 KiB
Python
Raw Normal View History

2015-08-14 10:12:10 +00:00
#!/usr/bin/env python3
import os, pwd, grp
2016-05-27 16:20:58 +00:00
from botanjs.config import Config as config, DEBUG
2015-08-14 10:12:10 +00:00
2016-05-27 16:20:58 +00:00
import shutil
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 16:20:58 +00:00
config["Paths"]["SiteRoot"] = SiteRoot;
2015-08-14 10:12:10 +00:00
# Create the lock folder for celery
2016-05-27 16:20:58 +00:00
lockDir = 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
import sys
from subprocess import Popen
sys.path.append( os.path.abspath( "." ) )
from botanjs.service.webapi import WebAPI
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"
, "--pidfile=" + lockDir + jwork + ".pid"
, "--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"]
)