Commits

sodas tsai committed 832c8f9

Activate/Deactivate an app

Comments (0)

Files changed (3)

beanstalk/__init__.py

 
 # Pacakge information
 #-----------------------------------------------------------------------------------------------------------------------
-__version__ = '0.1.76'
+__version__ = '0.1.80'
 VERSION = tuple(map(lambda x: int(x), __version__.split('.')))
 BEANSTALK_ROOT_PATH = os.path.abspath(os.path.dirname(__file__))
 

beanstalk/tasks/app.py

         name=project_name, verbose=beanstalk_settings['VERBOSE']))
 
     print separator(' . ')
+
+
+@task
+@beanstalk_role('app')
+def activate(settings_path=None, **settings_patches):
+    """Activate apps in the remote
+    """
+    beanstalk_settings = load_role_settings(additional_settings_path=settings_path, **settings_patches)
+    set_verbose_level()
+    load_web_servers()
+
+    project_name = beanstalk_settings['PROJECT_NAME']
+
+    @roles('web_servers')
+    def core():
+        run('bsjack server.activate_app:{project_name}'.format(project_name=project_name))
+    execute(core)
+
+
+@task
+@beanstalk_role('app')
+def deactivate(settings_path=None, **settings_patches):
+    """Deactivate apps in the remote
+    """
+    beanstalk_settings = load_role_settings(additional_settings_path=settings_path, **settings_patches)
+    set_verbose_level()
+    load_web_servers()
+
+    project_name = beanstalk_settings['PROJECT_NAME']
+
+    @roles('web_servers')
+    def core():
+        run('bsjack server.deactivate_app:{project_name}'.format(project_name=project_name))
+    execute(core)

beanstalk/tasks/server.py

             local('git add .gitignore')
             local('git commit -m "Init commit"')
 
-    print section_title('Add to apache httpd')
-    with open(apache_conf_path(), 'r') as f:
-        apache_conf = f.read()
-    if not '# %s' % project_name in apache_conf:
-        commands = [
-            '# %s' % project_name,
-            '#' + '-' * 20,
-            '<Location /%s>' % project_name,
-            '    SetHandler uwsgi-handler',
-            '    uWSGISocket %s' % os.path.join(project_run, 'uwsgi.sock'),
-            '</Location>',
-            '#' + '-' * 20,
-            ' ',
-        ]
-        sed_command = '\\n'.join(commands)
-        local(sed('$ a\\{command}'.format(command=sed_command), apache_conf_path()))
-        local('sudo /usr/sbin/httpd_reload')
+    execute(activate_app, project_name, settings_path=settings_path, **settings_patches)
 
     # Post-create actions
     run_hooked_actions('POST_CREATE_ACTIONS')
     # delete
     if remove:
         print section_title('Remove app @ %s' % project_base)
+        execute(deactivate_app, project_name, settings_path=settings_path, **settings_patches)
         local('rm -rf %s' % project_base)
-        local(sed('/# {name}/,+7d'.format(name=project_name), apache_conf_path()))
-        local('sudo /usr/sbin/httpd_reload')
 
 
 @task
 
 @task
 @beanstalk_role('server')
+def commit_app(project_name, settings_path=None, **settings_patches):
+    """Commit app
+    """
+    settings_patches = eval_kwargs(settings_patches)
+    load_role_settings(additional_settings_path=settings_path, **settings_patches)
+    env.project_name = project_name
+    set_verbose_level()
+
+    run_hooked_actions('PRE_COMMIT_ACTION')
+
+    project_base = project_base_path(project_name)
+    with settings(lcd(project_base), hide('warnings'), warning=True):
+        local('git add -A && git commit -m "state at %s"' % datetime.datetime.now().strftime('%s'))
+
+    run_hooked_actions('POST_COMMIT_ACTION')
+
+
+@task
+@beanstalk_role('server')
+def activate_app(project_name, settings_path=None, **settings_patches):
+    """Add app to apache httpd
+    """
+    print section_title('Add to apache httpd')
+
+    load_role_settings(additional_settings_path=settings_path, **settings_patches)
+    set_verbose_level()
+    project_run = project_run_path(project_name)
+
+    with open(apache_conf_path(), 'r') as f:
+        apache_conf = f.read()
+    if not '# %s' % project_name in apache_conf:
+        commands = [
+            '# %s' % project_name,
+            '#' + '-' * 20,
+            '<Location /%s>' % project_name,
+            '    SetHandler uwsgi-handler',
+            '    uWSGISocket %s' % os.path.join(project_run, 'uwsgi.sock'),
+            '</Location>',
+            '#' + '-' * 20,
+            ' ',
+        ]
+        sed_command = '\\n'.join(commands)
+        local(sed('$ a\\{command}'.format(command=sed_command), apache_conf_path()))
+        local('sudo /usr/sbin/httpd_reload')
+
+
+@task
+@beanstalk_role('server')
+def deactivate_app(project_name, settings_path=None, **settings_patches):
+    """Remove app from apache httpd
+    """
+    load_role_settings(additional_settings_path=settings_path, **settings_patches)
+    set_verbose_level()
+    local(sed('/# {name}/,+7d'.format(name=project_name), apache_conf_path()))
+    local('sudo /usr/sbin/httpd_reload')
+
+
+@task
+@beanstalk_role('server')
 def build_venv(project_name, settings_path=None, **settings_patches):
     """Build virtual env of target app.
     """
 
 @task
 @beanstalk_role('server')
-def commit_app(project_name, settings_path=None, **settings_patches):
-    """Commit app
-    """
-    settings_patches = eval_kwargs(settings_patches)
-    load_role_settings(additional_settings_path=settings_path, **settings_patches)
-    env.project_name = project_name
-    set_verbose_level()
-
-    run_hooked_actions('PRE_COMMIT_ACTION')
-
-    project_base = project_base_path(project_name)
-    with settings(lcd(project_base), hide('warnings'), warning=True):
-        local('git add -A && git commit -m "state at %s"' % datetime.datetime.now().strftime('%s'))
-
-    run_hooked_actions('POST_COMMIT_ACTION')
-
-
-@task
-@beanstalk_role('server')
 def add_user(tmp_key_path, clean_tmp_key=False):
     """Add a user's SSH public key to beanstalk
     """