Skip to content

Commit

Permalink
Merge pull request #33 from catalanojuan/added-optional-supervisor-re…
Browse files Browse the repository at this point in the history
…start-to-deploy

Added support for restarting all supervisor services after deploy
  • Loading branch information
n0n0x authored Apr 13, 2017
2 parents 89d6fa9 + fdd89c7 commit f9b866e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
12 changes: 8 additions & 4 deletions deployer/fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from fabric.api import env, task
from fabric.state import output
from fabric.context_managers import shell_env, cd
from fabric.context_managers import shell_env, cd

#output.stdout = False

Expand All @@ -15,7 +15,7 @@
from deployer.tasks.git import clone_repo, deploy_code, add_remote
from deployer.tasks.requirements import install_requirements
from deployer.tasks.envfile import envconf

from .tasks.supervisor import restart_all


@task
Expand All @@ -26,19 +26,24 @@ def setup_environment():
with cd(env.app_dir):
setup_virtualenv(env.python_version, env.app_name, env.app_dir, env.repo_url)


@task
def deploy(branch='master', migrate=False):
with shell_env(HOME='/home/' + env.user, PATH="/home/" + env.user + "/.pyenv/bin:$PATH"):
with cd(env.app_dir):
deploy_code(env.repo_url, env.app_dir, env.user, branch=branch)
install_requirements(env.app_name, env.python_version)
if env.restart_after_deploy:
restart_all()


@task
def git_remote_add(remote_url, repo_name):
with shell_env(HOME='/home/' + env.user, PATH="/home/" + env.user + "/.pyenv/bin:$PATH"):
with cd(env.app_dir):
add_remote(remote_url, repo_name, env.app_dir)


@task
def config(action=None, key=None, value=None):
'''Manage project configuration via .env
Expand All @@ -51,5 +56,4 @@ def config(action=None, key=None, value=None):
with shell_env(HOME='/home/' + env.user, PATH="/home/" + env.user + "/.pyenv/bin:$PATH"):
with cd(env.app_dir):
envconf(action, key, value)
for services in env.supervisor_services:
supervisor.restart(services)
restart_all()
1 change: 1 addition & 0 deletions deployer/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@

env.supervisor_services = environ.get('SUPERVISOR_SERVICES', '').split(',')
env.upstart_services = environ.get('UPSTART_SERVICES', '').split(',')
env.restart_after_deploy = environ.get('RESTART_AFTER_DEPLOY', False)
11 changes: 11 additions & 0 deletions deployer/tasks/supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from fabtools import supervisor, files


## TODO: use upload_template to prevent hardcoded
## supervisor configuration files
@with_settings(warn_only=True)
Expand All @@ -18,18 +19,28 @@ def setup():

update_config()


def update_config():
supervisor.update_config()


def reload_config():
supervisor.reload_config()


def restart(component):
update_config()
supervisor.restart_process(component)


def restart_all():
for service in env.supervisor_services:
restart(service)


def stop(component):
supervisor.stop_process(component)


def start(component):
supervisor.start_process(component)

0 comments on commit f9b866e

Please sign in to comment.