def install_indexer(): """ Install Cozy Data Indexer. Use supervisord to daemonize it. """ home = "/usr/local/cozy-indexer" indexer_dir = "%s/cozy-data-indexer" % home indexer_env_dir = "%s/virtualenv" % indexer_dir python_exe = indexer_dir + "/virtualenv/bin/python" indexer_exe = "server.py" process_name = "cozy-indexer" require.files.directory(home, use_sudo=True) with cd(home): delete_if_exists("cozy-data-indexer") sudo('git clone git://github.com/mycozycloud/cozy-data-indexer.git') require.python.virtualenv(indexer_env_dir, use_sudo=True) with python.virtualenv(indexer_env_dir): sudo("pip install --use-mirrors -r %s/requirements/common.txt" % \ indexer_dir) sudo("chown -R cozy:cozy %s" % home) require.supervisor.process(process_name, command='%s %s' % (python_exe, indexer_exe), directory=indexer_dir, user="******") supervisor.restart_process(process_name) result = run('curl -X GET http://127.0.0.1:9102/') installedController = result.find("Cozy Data Indexer") if installedController == -1: print_failed("cozy-data-indexer") print(green("Data Indexer successfully started"))
def install_indexer(): """ Install Cozy Data Indexer. Use supervisord to daemonize it. """ home = "/usr/local/cozy-indexer" indexer_dir = "%s/cozy-data-indexer" % home indexer_env_dir = "%s/virtualenv" % indexer_dir python_exe = indexer_dir + "/virtualenv/bin/python" indexer_exe = "server.py" process_name = "cozy-indexer" require.files.directory(home, use_sudo=True) with cd(home): delete_if_exists("cozy-data-indexer") sudo('git clone git://github.com/mycozycloud/cozy-data-indexer.git') require.python.virtualenv(indexer_env_dir, use_sudo=True) with python.virtualenv(indexer_env_dir): sudo("pip install --use-mirrors -r %s/requirements/common.txt" % \ indexer_dir) sudo("chown -R cozy:cozy %s" % home) require.supervisor.process(process_name, command='%s %s' % (python_exe, indexer_exe), directory=indexer_dir, user="******" ) supervisor.restart_process(process_name) result = run('curl -X GET http://127.0.0.1:9102/') installedController = result.find("Cozy Data Indexer") if installedController == -1: print_failed("cozy-data-indexer") print(green("Data Indexer successfully started"))
def install_indexer(): """ Deploy Cozy Data Indexer. Use supervisord to daemonize it. """ indexer_dir = "%s/cozy-data-indexer" % cozy_home indexer_env_dir = "%s/virtualenv" % indexer_dir python_exe = indexer_dir + "/virtualenv/bin/python" indexer_exe = "server.py" process_name = "cozy-indexer" with cd(cozy_home): delete_if_exists("cozy-data-indexer") cozydo('git clone git://github.com/mycozycloud/cozy-data-indexer.git') require.python.virtualenv(indexer_env_dir, use_sudo=True, user="******") with python.virtualenv(indexer_env_dir): cozydo("pip install --use-mirrors -r %s/requirements/common.txt" % \ indexer_dir) require.supervisor.process(process_name, command='%s %s' % (python_exe, indexer_exe), directory=indexer_dir, user=cozy_user ) supervisor.restart_process(process_name) print(green("Data Indexer successfully started"))
def set_supervisord_config(): """Configure Newebe runner for supervisord""" require.supervisor.process(newebe_process, command='%s %s' % (python_exe, newebe_exe), directory=newebe_dir, user=newebe_user ) supervisor.restart_process(newebe_process)
def deploy(): info('[deploy] Starting Deploy: %s -> %s' % (env.app, env.host_string)) git_push() with cd(env.app_path), shell_env(**env.shell_envs_dict): ensure_packages() one_offs() supervisor.update_config() supervisor.restart_process('all') ft_service.restart('nginx') success('[deploy] Finished Deploy: %s -> %s' % (env.app, env.host_string))
def setup(): sudo('apt-get update') sudo('apt-get install -y git') sudo('apt-get install -y postgresql postgresql-contrib libpq-dev') sudo('apt-get install -y nginx') sudo('apt-get install -y nodejs') sudo('ln -s /usr/bin/nodejs /usr/bin/node') sudo('apt-get install -y npm') sudo('npm install -g bower') sudo('apt-get install -y python-pip') sudo('apt-get install -y python-dev') sudo('pip install virtualenv') sudo('pip install virtualenvwrapper') sudo('pip install supervisor') postgres_user = '******' postgres_database = 'office_database' postgres_password = '******' sudo('psql -c "CREATE USER {} WITH PASSWORD \'{}\'"' .format(postgres_user, postgres_password), user='******') sudo('psql -c "CREATE DATABASE {} WITH OWNER {}"' .format(postgres_database, postgres_user), user='******') sudo('mkvirtualenv office') sudo('chown -R zhorzh:developers /srv') sudo('chmod -R 775 /srv') run('git clone https://github.com/zhorzh/office /srv/office') with cd('/srv/office/server'): sudo('workon office && pip install -r requirements.txt') with cd('/srv/office/client'): run('bower install') require.supervisor.process( name='office', command='/home/zhorzh/.virtualenvs/office/bin/python \ /home/zhorzh/.virtualenvs/office/bin/gunicorn \ -b 0.0.0.0:5000 core:app', directory='/srv/office/server', stdout_logfile='/srv/office_supervisor.log', user='******') supervisor.restart_process('office') require.nginx.site( server_name='office', template_source='/srv/office/fabfile/nginx.template', port=5000, service_folder='office') require.nginx.disable('default') require.nginx.enable('office') sudo('service nginx restart')
def update_indexer(): """ Update Cozy indexer module. """ home = "/usr/local/cozy-indexer" indexer_dir = "%s/cozy-data-indexer" % home indexer_env_dir = "%s/virtualenv" % indexer_dir with cd(indexer_dir): sudo("git pull origin master") with python.virtualenv(indexer_env_dir): sudo("pip install --use-mirrors --upgrade -r " "%s/requirements/common.txt" % indexer_dir) supervisor.restart_process("cozy-indexer")
def install_indexer(): ''' Install Cozy Data Indexer. Use supervisord to daemonize it. ''' home = '/usr/local/cozy-indexer' indexer_dir = '%s/cozy-data-indexer' % home indexer_env_dir = '%s/virtualenv' % indexer_dir python_exe = indexer_dir + '/virtualenv/bin/python' indexer_exe = 'server.py' process_name = 'cozy-indexer' # Check if indexer is already installed, . with settings(warn_only=True): result = run('curl -X GET http://127.0.0.1:9102/') is_installed = result.find("Cozy Data Indexer") if is_installed != -1: print(green("Data Indexer already installed")) return True require.files.directory(home, use_sudo=True) with cd(home): if files.exists('cozy-data-indexer'): su_delete('cozy-data-indexer') sudo('git clone https://github.com/cozy/cozy-data-indexer.git') require.python.virtualenv(indexer_env_dir, use_sudo=True) with python.virtualenv(indexer_env_dir): python.install_requirements( indexer_dir + '/requirements/common.txt', use_sudo=True) sudo('chown -R cozy:cozy %s' % home) require.supervisor.process( process_name, command='%s %s' % (python_exe, indexer_exe), directory=indexer_dir, user='******' ) supervisor.restart_process(process_name) time.sleep(10) result = run('curl -X GET http://127.0.0.1:9102/') is_installed = result.find("Cozy Data Indexer") if is_installed == -1: print_failed("cozy-data-indexer") print(green("Data Indexer successfully started"))
def update_stack(): ''' Update applications ''' nodejs.update_package('cozy-controller') nodejs.update_package('cozy-monitor') if is_pi(): sudo('/etc/init.d/cozy-controller restart') else: supervisor.restart_process('cozy-controller') sudo('cozy-monitor update data-system') sudo('cozy-monitor update home') sudo('cozy-monitor update proxy') update_indexer() print(green('Stack updated successfully.'))
def update_indexer(): ''' Update Cozy indexer module. ''' home = '/usr/local/cozy-indexer' indexer_dir = '%s/cozy-data-indexer' % home indexer_env_dir = '%s/virtualenv' % indexer_dir with cd(indexer_dir): sudo('git pull origin master') with python.virtualenv(indexer_env_dir): python.install_requirements(indexer_dir + '/requirements/common.txt', upgrade=True, use_sudo=True) supervisor.restart_process('cozy-indexer')
def supervisor_setup(): upload_template( filename='conf/supervisor.conf', destination='%(deploy_path)s/supervisor_%(project_name)s.conf' % env, context={ 'project_name': env.project_name, 'deploy_path': env.deploy_path, 'log_path': env.log_path, }, use_jinja=True ) sudo('ln -s -f %(deploy_path)s/supervisor_%(project_name)s.conf ' '/etc/supervisor/conf.d/%(project_name)s.conf' % env) supervisor.update_config() supervisor.restart_process('all')
def update(): """ Update project. """ with cd(env.project_path): run('git pull') with virtualenv(env.venv_path): require.python.requirements(os.path.join(env.project_path, 'requirements.txt')) sudo('chmod ogu+x %(manage_path)s/manage.py' % env) manage('syncdb') manage('migrate') manage('collectstatic --noinput') supervisor.restart_process('all')
def update_indexer(): ''' Update Cozy indexer module. ''' home = '/usr/local/cozy-indexer' indexer_dir = '%s/cozy-data-indexer' % home indexer_env_dir = '%s/virtualenv' % indexer_dir with cd(indexer_dir): sudo('git pull origin master') with python.virtualenv(indexer_env_dir): sudo( 'pip install --use-mirrors --upgrade -r %s/requirements/common.txt' % indexer_dir) supervisor.restart_process('cozy-indexer')
def install_controller_dev(): """ Install Cozy Controller Application Manager. Daemonize with supervisor. """ require.nodejs.package('cozy-controller') require.supervisor.process('cozy-controller', command="cozy-controller -c -u --per 755", environment='NODE_ENV="development"', user='******') supervisor.restart_process('cozy-controller') import time time.sleep(5) with hide('running', 'stdout'): result = run('curl -X GET http://127.0.0.1:9002/') if result != '{"message":"No drones specified"}': print_failed("cozy-controller") print(green("Cozy Controller successfully started"))
def install_controller_dev(): """ Install Cozy Controller Application Manager. Daemonize with supervisor. """ sudo("npm install -g git+https://github.com/roblabla/cozy-controller.git") require.supervisor.process( "cozy-controller", command="cozy-controller -c -u --per 755", environment='NODE_ENV="development"', user="******" ) supervisor.restart_process("cozy-controller") import time time.sleep(5) with hide("running", "stdout"): result = run("curl -X GET http://127.0.0.1:9002/") if result != '{"message":"No drones specified"}': print_failed("cozy-controller") print(green("Cozy Controller successfully started"))
def install_controller_dev(): """ Install Cozy Controller Application Manager. Daemonize with supervisor. """ require.nodejs.package('cozy-controller') require.supervisor.process('cozy-controller', command="cozy-controller -c -u --per 755", environment='NODE_ENV="development"', user='******' ) supervisor.restart_process('cozy-controller') import time time.sleep(5) with hide('running', 'stdout'): result = run('curl -X GET http://127.0.0.1:9002/') if result != '{"message":"No drones specified"}': print_failed("cozy-controller") print(green("Cozy Controller successfully started"))
def install_controller_dev(): ''' Install Cozy Controller Application Manager. Daemonize with supervisor. ''' sudo('npm install -g cozy-controller') require.supervisor.process('cozy-controller', command='cozy-controller', environment='NODE_ENV="development"', user='******') supervisor.restart_process('cozy-controller') time.sleep(5) with hide('running', 'stdout'): result = run('curl -X GET http://127.0.0.1:9002/') if result != '{"message":"No drones specified"}': print_failed("cozy-controller") print(green('Cozy Controller successfully started'))
def install_indexer(): ''' Install Cozy Data Indexer. Use supervisord to daemonize it. ''' home = '/usr/local/cozy-indexer' indexer_dir = '%s/cozy-data-indexer' % home indexer_env_dir = '%s/virtualenv' % indexer_dir python_exe = indexer_dir + '/virtualenv/bin/python' indexer_exe = 'server.py' process_name = 'cozy-indexer' require.files.directory(home, use_sudo=True) with cd(home): if files.exists('cozy-data-indexer'): su_delete('cozy-data-indexer') sudo('git clone https://github.com/mycozycloud/cozy-data-indexer.git') require.python.virtualenv(indexer_env_dir, use_sudo=True) with python.virtualenv(indexer_env_dir): sudo( 'pip install --use-mirrors -r %s/requirements/common.txt' % indexer_dir) sudo('chown -R cozy:cozy %s' % home) require.supervisor.process( process_name, command='%s %s' % (python_exe, indexer_exe), directory=indexer_dir, user='******' ) supervisor.restart_process(process_name) if is_arm(): time.sleep(10) else: time.sleep(1) result = run('curl -X GET http://127.0.0.1:9102/') is_installed = result.find("Cozy Data Indexer") if is_installed == -1: print_failed("cozy-data-indexer") print(green("Data Indexer successfully started"))
def install_controller_dev(): ''' Install Cozy Controller Application Manager. Daemonize with supervisor. ''' sudo('npm install -g cozy-controller') require.supervisor.process( 'cozy-controller', command='cozy-controller', environment='NODE_ENV="development"', user='******' ) supervisor.restart_process('cozy-controller') time.sleep(5) with hide('running', 'stdout'): result = run('curl -X GET http://127.0.0.1:9002/') if result != '{"message":"No drones specified"}': print_failed("cozy-controller") print(green('Cozy Controller successfully started'))
def install_indexer(): ''' Install Cozy Data Indexer. Use supervisord to daemonize it. ''' home = '/usr/local/cozy-indexer' indexer_dir = '%s/cozy-data-indexer' % home indexer_env_dir = '%s/virtualenv' % indexer_dir python_exe = indexer_dir + '/virtualenv/bin/python' indexer_exe = 'server.py' process_name = 'cozy-indexer' require.files.directory(home, use_sudo=True) with cd(home): if files.exists('cozy-data-indexer'): su_delete('cozy-data-indexer') sudo('git clone https://github.com/mycozycloud/cozy-data-indexer.git') require.python.virtualenv(indexer_env_dir, use_sudo=True) with python.virtualenv(indexer_env_dir): sudo('pip install --use-mirrors -r %s/requirements/common.txt' % indexer_dir) sudo('chown -R cozy:cozy %s' % home) require.supervisor.process(process_name, command='%s %s' % (python_exe, indexer_exe), directory=indexer_dir, user='******') supervisor.restart_process(process_name) if is_arm(): time.sleep(10) else: time.sleep(1) result = run('curl -X GET http://127.0.0.1:9102/') is_installed = result.find("Cozy Data Indexer") if is_installed == -1: print_failed("cozy-data-indexer") print(green("Data Indexer successfully started"))
def install_indexer(): """ Install Cozy Data Indexer. Use supervisord to daemonize it. """ home = "/usr/local/cozy-indexer" indexer_dir = "%s/cozy-data-indexer" % home indexer_env_dir = "%s/virtualenv" % indexer_dir python_exe = indexer_dir + "/virtualenv/bin/python" indexer_exe = "server.py" process_name = "cozy-indexer" require.files.directory(home, use_sudo=True) with cd(home): if files.exists("cozy-data-indexer"): su_delete("cozy-data-indexer") sudo("git clone https://github.com/mycozycloud/cozy-data-indexer.git") require.python.virtualenv( indexer_env_dir, use_sudo=True, python_cmd="python2", pip_cmd="pip2", venv_python="python2" ) with python.virtualenv(indexer_env_dir): sudo("pip install --use-mirrors -r %s/requirements/common.txt" % indexer_dir) sudo("chown -R cozy:cozy %s" % home) require.supervisor.process( process_name, command="%s %s" % (python_exe, indexer_exe), directory=indexer_dir, user="******" ) supervisor.restart_process(process_name) time.sleep(10) result = run("curl -X GET http://127.0.0.1:9102/") is_installed = result.find("Cozy Data Indexer") if is_installed == -1: print_failed("cozy-data-indexer") print(green("Data Indexer successfully started"))
def restart(process_name): """restarts supervisor process """ supervisor.restart_process(process_name)
def restart_geotaxi(): supervisor.update_config() supervisor.restart_process('geotaxi')
def provision(): project_path = '/srv/www/savings_champion/savings_champion' virtualenv_path = '/home/savingschampion/.virtualenv/savings_champion' require.files.directory('/srv/www/', use_sudo=True, owner='savingschampion', group='savingschampion') deb.update_index() require.postgres.server() require.deb.packages([ 'libpq-dev', 'memcached', 'libtiff4-dev', 'libjpeg8-dev', 'zlib1g-dev', 'libfreetype6-dev', 'liblcms1-dev', 'libwebp-dev' ]) require.postgres.user('savings_champion', 'r8Y@Mge#aTtW', createdb=True) require.postgres.database('savings_champion', 'savings_champion') require.python.virtualenv(virtualenv_path) require.python.packages(['uwsgi', 'flower'], use_sudo=True) require.files.directory('/var/log/uwsgi/', use_sudo=True) require.files.directory('/var/log/celeryd/', use_sudo=True) require.files.directory('/var/log/flower/', use_sudo=True) require.nodejs.installed_from_source() require.nodejs.package('yuglify') require.postfix.server('5.9.87.167') with virtualenv(virtualenv_path): python.install_requirements("/".join( [project_path, 'requirements.txt']), upgrade=True, quiet=False) with cd('%s' % project_path): if not exists('settings.py'): run('ln -s settings_production.py settings.py') run('python manage.py collectstatic --noinput') run('python manage.py syncdb --noinput') run('python manage.py migrate') require.deb.package('rabbitmq-server') sudo('rabbitmqctl add_vhost guest') sudo('rabbitmqctl set_permissions -p guest guest ".*" ".*" ".*"') uwsgi_path = '/tmp/uwsgi.sock' with cd('%s' % project_path): require.supervisor.process( 'uwsgi', command= "uwsgi --socket %s --master --workers 4 --home %s --chdir %s --file django.wsgi --harakiri=60 --reaper" % (uwsgi_path, virtualenv_path, project_path), directory=project_path, user='******', stdout_logfile='/var/log/uwsgi/savingschampion.log', stopsignal='QUIT') supervisor.restart_process('uwsgi') require.file('celerybeat-schedule.db', use_sudo=True, owner='www-data', group='www-data') for celery_pool in xrange(1, stop=3): require.supervisor.process( 'celery-%s' % celery_pool, command= "%s/bin/celery worker -E -A celeryapp --concurrency=10 -n worker%s.localhost" % (virtualenv_path, celery_pool), directory=project_path, user='******', stdout_logfile='/var/log/celeryd/savingschampion.log', redirect_stderr=True, environment='DJANGO_SETTINGS_MODULE=settings') supervisor.restart_process('celery') require.nginx.server() require.nginx.disable('default') require.nginx.site('savings_champion', template_contents=NGINX_NOSSL_CONFIG, enabled=True, check_config=True, port=80) require.nginx.site('savings_champion_ssl', template_contents=NGINX_SSL_PRODUCTION_CONFIG, enabled=True, check_config=True, port=443, server_alias='savingschampion.co.uk', doc_root=project_path, proxy_url=uwsgi_path, static_path='/'.join([project_path, '..', 'static']), media_path='/'.join([project_path, 'assets']), ssl_certificate='www_savingschampion_co_uk.cert', ssl_key='www_savingschampion_co_uk.key') require.supervisor.process( 'flower', command= "flower --broker=amqp://guest@localhost:5672// --address=0.0.0.0 --basic_auth=savingschampion:Over9000!", stdout_logfile='/var/log/flower/savingschampion.log', redirect_stderr=True, user="******")
def restart(config): app_name = _get_app_name(config['GIT_URL']) supervisor.restart_process(app_name) time.sleep(1) print(app_name, 'status:', supervisor.process_status(app_name))
def restart_newebe(): """Restart newebe surpervisord process""" supervisor.restart_process(newebe_process)
def provision(): project_path = '/srv/www/savings_champion/savings_champion' virtualenv_path = '/home/savingschampion/.virtualenv/savings_champion' require.files.directory('/srv/www/', use_sudo=True, owner='savingschampion', group='savingschampion') deb.update_index() require.postgres.server() require.deb.packages(['libpq-dev', 'memcached', 'libtiff4-dev', 'libjpeg8-dev', 'zlib1g-dev', 'libfreetype6-dev', 'liblcms1-dev', 'libwebp-dev']) require.postgres.user('savings_champion', 'r8Y@Mge#aTtW', createdb=True) require.postgres.database('savings_champion', 'savings_champion') require.python.virtualenv(virtualenv_path) require.python.packages(['uwsgi', 'flower'], use_sudo=True) require.files.directory('/var/log/uwsgi/', use_sudo=True) require.files.directory('/var/log/celeryd/', use_sudo=True) require.files.directory('/var/log/flower/', use_sudo=True) require.nodejs.installed_from_source() require.nodejs.package('yuglify') require.postfix.server('5.9.87.167') with virtualenv(virtualenv_path): python.install_requirements("/".join([project_path, 'requirements.txt']), upgrade=True, quiet=False) with cd('%s' % project_path): if not exists('settings.py'): run('ln -s settings_production.py settings.py') run('python manage.py collectstatic --noinput') run('python manage.py syncdb --noinput') run('python manage.py migrate') require.deb.package('rabbitmq-server') sudo('rabbitmqctl add_vhost guest') sudo('rabbitmqctl set_permissions -p guest guest ".*" ".*" ".*"') uwsgi_path = '/tmp/uwsgi.sock' with cd('%s' % project_path): require.supervisor.process('uwsgi', command="uwsgi --socket %s --master --workers 4 --home %s --chdir %s --file django.wsgi --harakiri=60 --reaper" % ( uwsgi_path, virtualenv_path, project_path), directory=project_path, user='******', stdout_logfile='/var/log/uwsgi/savingschampion.log', stopsignal='QUIT') supervisor.restart_process('uwsgi') require.file('celerybeat-schedule.db', use_sudo=True, owner='www-data', group='www-data') for celery_pool in xrange(1, stop=3): require.supervisor.process('celery-%s' % celery_pool, command="%s/bin/celery worker -E -A celeryapp --concurrency=10 -n worker%s.localhost" % (virtualenv_path, celery_pool), directory=project_path, user='******', stdout_logfile='/var/log/celeryd/savingschampion.log', redirect_stderr=True, environment='DJANGO_SETTINGS_MODULE=settings') supervisor.restart_process('celery') require.nginx.server() require.nginx.disable('default') require.nginx.site('savings_champion', template_contents=NGINX_NOSSL_CONFIG, enabled=True, check_config=True, port=80) require.nginx.site('savings_champion_ssl', template_contents=NGINX_SSL_PRODUCTION_CONFIG, enabled=True, check_config=True, port=443, server_alias='savingschampion.co.uk', doc_root=project_path, proxy_url=uwsgi_path, static_path='/'.join([project_path, '..', 'static']), media_path='/'.join([project_path, 'assets']), ssl_certificate='www_savingschampion_co_uk.cert', ssl_key='www_savingschampion_co_uk.key') require.supervisor.process('flower', command="flower --broker=amqp://guest@localhost:5672// --address=0.0.0.0 --basic_auth=savingschampion:Over9000!", stdout_logfile='/var/log/flower/savingschampion.log', redirect_stderr=True, user="******")
def uwsgi(): supervisor.restart_process('uwsgi')
def celery(): supervisor.restart_process('celery') supervisor.restart_process('celery-1') supervisor.restart_process('celery-2') supervisor.restart_process('celery-3')
def restart_supervisor(app_name=None): """Restart the supervisor process.""" supervisor.restart_process(app_name or env.app_name)
def restart_supervisor(): require('environment') supervisor.restart_process('seattle2015')
def restart_supervisor(): print(green("Restating Supervisor")) supervisor.update_config() supervisor.restart_process(settings.PROJECT_NAME)
def restart_supervisor(): require('environment') supervisor.restart_process('gunicorn')
def restart(component): update_config() supervisor.restart_process(component)