def sysinitstart_RASVAMT_and_check_status(): """ Starts the APP daemon process and checks that the server is up and running then it shuts down the server """ # We sleep 2 here as it was found on Mac deployment to docker container # that the shell would exit before the APPDaemon could detach, thus # resulting in no startup self. # # Please replace following line with something meaningful # virtualenv('ngamsDaemon start -cfg {0} && sleep 2'.format(tgt_cfg)) env.APP_INSTALL_DIR = os.path.abspath(os.path.join(home(), APP_INSTALL_DIR_NAME)) env.APP_ROOT_DIR = os.path.abspath(os.path.join(home(), APP_ROOT_DIR_NAME)) env.APP_SRC_DIR = os.path.abspath(os.path.join(home(), APP_SRC_DIR_NAME)) info('Start {0} and check'.format(APP)) start_unicorn() with settings(user=env.AWS_SUDO_USER): sudo('service nginx start') try: u = urllib2.urlopen('http://{0}/static/html/index.html'. format(env.host_string)) except urllib2.URLError: red("RASVAMT NOT running!") return r = u.read() u.close() assert r.find('rasvamt-s-user-documentation') > -1, red("RASVAMT NOT running")
def APP_build_cmd(): # The installation of the bsddb package (needed by ngamsCore) is in # particular difficult because it requires some flags to be passed on # (particularly if using MacOSX's port # >>>> NOTE: This function potentially needs heavy customisation <<<<<< build_cmd = ['cd {0}; pip install -e .'.format(APP_SRC_DIR_NAME)] # linux_flavor = get_linux_flavor() env.APP_INSTALL_DIR = os.path.abspath( os.path.join(home(), APP_INSTALL_DIR_NAME)) env.APP_ROOT_DIR = os.path.abspath(os.path.join(home(), APP_ROOT_DIR_NAME)) env.APP_SRC_DIR = os.path.abspath(os.path.join(home(), APP_SRC_DIR_NAME)) return ' '.join(build_cmd)
def start_unicorn(): """ Starts the gunicorn daemon which in turn will be called by nginx. """ HOME = home() env.APP_INSTALL_DIR = os.path.abspath(os.path.join(HOME, APP_INSTALL_DIR_NAME)) env.APP_ROOT_DIR = os.path.abspath(os.path.join(HOME, APP_ROOT_DIR_NAME)) env.APP_SRC_DIR = os.path.abspath(os.path.join(HOME, APP_SRC_DIR_NAME)) NAME = "RASVAMT" FLASKDIR = env.APP_INSTALL_DIR+'/src' SOCKFILE = env.APP_INSTALL_DIR+'/sock' PIDFILE = env.APP_INSTALL_DIR+'/gunicorn.pid' USER = env.APP_USER GROUP = env.APP_USER NUM_WORKERS = '3' with settings(user=env.APP_USER): with cd(FLASKDIR): run('{0}/bin/gunicorn main:app -b 127.0.0.1:5000 -D '.format(env.APP_INSTALL_DIR) +\ ' --name {0}'.format(NAME) + \ ' --user={0} --group={1}'.format(USER, GROUP) +\ ' --bind=unix:{0}'.format(SOCKFILE) +\ ' --workers={0}'.format(NUM_WORKERS) +\ ' --log-level=debug --pythonpath={0}'.format(FLASKDIR) +\ ' -p {0}'.format(PIDFILE) )
def APP_build_cmd(): env.APP_INSTALL_DIR = os.path.abspath(os.path.join(home(), APP_INSTALL_DIR_NAME)) env.APP_ROOT_DIR = os.path.abspath(os.path.join(home(), APP_ROOT_DIR_NAME)) env.APP_SRC_DIR = os.path.abspath(os.path.join(home(), APP_SRC_DIR_NAME)) build_cmd = [] # create RASVAMT directories and chown to correct user and group run('mkdir -p {0}'.format(env.APP_INSTALL_DIR)) # This not working for some reason # sudo('chown -R {0}:{1} {2}'.format(env.USERS[0], GROUP, APP_INSTALL_DIR)) run('ln -s {0}/src {1}/src'.format(env.APP_SRC_DIR, env.APP_INSTALL_DIR)) return ' '.join(build_cmd)
def virtualenv_setup(): """ Creates a new virtualenv that will hold the APP installation """ APPInstallDir = APP_install_dir() if check_dir(APPInstallDir): overwrite = APP_overwrite_installation() if not overwrite: msg = ("%s exists already. Specify APP_OVERWRITE_INSTALLATION " "to overwrite, or a different APP_INSTALL_DIR location") abort(msg % (APPInstallDir,)) run("rm -rf %s" % (APPInstallDir,)) # Check which python will be bound to the virtualenv ppath = check_python() if not ppath: ppath = python_setup(os.path.join(home(), 'python')) # Use our create_venv.sh script to create the virtualenv # It already handles the download automatically if no virtualenv command is # found in the system, and also allows to specify a python executable path script_path = os.path.dirname(os.path.realpath(__file__))+'/create_venv.sh' put(script_path, APP_source_dir()+'/create_venv.sh') with cd(APP_source_dir()): run("/bin/bash create_venv.sh -p {0} {1}".format(ppath, APPInstallDir)) # Download this particular certifcate; otherwise pip complains # in some platforms if APP_use_custom_pip_cert(): if not(check_dir('~/.pip')): run('mkdir ~/.pip') with cd('~/.pip'): download('http://curl.haxx.se/ca/cacert.pem') run('echo "[global]" > ~/.pip/pip.conf; echo ' '"cert = {0}/.pip/cacert.pem" >> ~/.pip/pip.conf;'.format(home())) # Update pip and install wheel; this way we can install binary wheels from # PyPI if available (like astropy) # TODO: setuptools and python-daemon are here only because # python-daemon 2.1.2 is having a problem to install via setuptools # but not via pip (see https://pagure.io/python-daemon/issue/2 and # https://pagure.io/python-daemon/issue/3). # When this problem is fixed we'll fix our dependency on python-daemo # to avoid this issue entirely virtualenv('pip install -U pip wheel setuptools python-daemon') success("Virtualenv setup completed")
def APP_build_cmd(): # The installation of the bsddb package (needed by ngamsCore) is in # particular difficult because it requires some flags to be passed on # (particularly if using MacOSX's port # >>>> NOTE: This function potentially needs heavy customisation <<<<<< build_cmd = [] # linux_flavor = get_linux_flavor() env.APP_INSTALL_DIR = os.path.abspath(os.path.join(home(), APP_INSTALL_DIR_NAME)) env.APP_ROOT_DIR = os.path.abspath(os.path.join(home(), APP_ROOT_DIR_NAME)) env.APP_SRC_DIR = os.path.abspath(os.path.join(home(), APP_SRC_DIR_NAME)) build_cmd.append('cd {0} ;'.format(APP_source_dir())) build_cmd.append( 'curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash ;') build_cmd.append('source ~/.nvm/nvm.sh') build_cmd.append('nvm install node') # build_cmd.append('npm install typescript') build_cmd.append('pip install . ;') return ' '.join(build_cmd)
def APP_source_dir(): key = 'APP_SRC_DIR' if key not in env: env[key] = os.path.abspath(os.path.join(home(), env.APP_SRC_DIR_NAME)) return env[key]
def APP_root_dir(): key = 'APP_ROOT_DIR' if key not in env: env[key] = os.path.abspath(os.path.join(home(), env.APP_ROOT_DIR_NAME)) return env[key]
def APP_install_dir(): key = 'APP_INSTALL_DIR_NAME' default_if_empty(env, key, APP_name().lower()+'_rt') if env[key].find('/') != 0: # make sure this is an absolute path env[key] = os.path.abspath(os.path.join(home(), env.APP_INSTALL_DIR_NAME)) return env[key]