def _reload_supervisor(target): app_info, uuid = target app_name = app_info['app_name'] virtualenv = app_info.get('virtualenv', settings.DEFAULT_VIRTUALENV_NAME) virtualenv_home = '%s/%s' % (settings.RETINUE_WORKON_HOME, virtualenv) retinue_home = settings.RETINUE_HOME last_reload_request = cache.get('%s_supervisor_last_reload_request' % app_name) now = time.mktime(timezone.now().timetuple()) if not last_reload_request or now - last_reload_request >= 30: virtualenvcommand(""" workon %(virtualenv)s cd %(virtualenv_home)s if [ -e %(retinue_home)s/var/run/%(app_name)s_supervisord.pid ] then supervisorctl -c etc/%(app_name)s.conf shutdown while true do if [ -e %(retinue_home)s/var/run/%(app_name)s_supervisord.sock ] then sleep 1 else break fi done fi supervisord -c etc/%(app_name)s.conf """ % locals())
def syncdb_and_migrate(target): app_info, uuid = target app_name = app_info['app_name'] virtualenv = app_info.get('virtualenv', settings.DEFAULT_VIRTUALENV_NAME) project_home = '%s/%s' % (settings.RETINUE_APP_HOME, app_name) virtualenvcommand(""" workon %(virtualenv)s cd %(project_home)s python manage.py syncdb --noinput python manage.py migrate --noinput python manage.py createcachetable django_cache > /dev/null 2>&1 || echo """ % locals()) return target
def provide_virtualenv(target): app_info, uuid = target app_name = app_info['app_name'] virtualenv = app_info.get('virtualenv', settings.DEFAULT_VIRTUALENV_NAME) # mkvirtualenv if not exist if virtualenv not in virtualenvcommand('lsvirtualenv -b').splitlines(): virtualenvcommand('mkvirtualenv %s' % virtualenv) project_home = '%s/%s' % (settings.RETINUE_APP_HOME, app_name) # mkdir project_home if not exist if not os.path.exists(project_home): os.makedirs(project_home) if virtualenv == app_name: virtualenvcommand('workon %s && cd %s && setvirtualenvproject $VIRTUAL_ENV `pwd`' % (virtualenv, project_home)) return target
def install_requirements(target): app_info, uuid = target app_name = app_info['app_name'] virtualenv = app_info.get('virtualenv', settings.DEFAULT_VIRTUALENV_NAME) if virtualenv == app_name: requirements = app_info.get('requirements', 'requirements.txt') project_home = '%s/%s' % (settings.RETINUE_APP_HOME, app_name) virtualenvcommand(""" workon %(virtualenv)s cd %(project_home)s if [ -f %(requirements)s ] then pip install --upgrade -r %(requirements)s fi """ % locals()) return target