Beispiel #1
0
    def _start_gunicorn(self, spec, build_name):
        # create the command and write a new supervisor config for this build.
        # (this creates a [program:<build_name>] config section for supervisor).
        cmd, port = self._build_gunicorn_cmd(spec.get('gunicorn', {}), build_name)
        log_root = self._log_root(build_name)
        supervisord.write_program_config(build_name, cmd, ctx().builds_root(), log_root)

        # start it and wait until supervisor thinks its up and running, then test the
        # service by sending it the specified HTTP request.
        supervisord.start(build_name)
        if not supervisord.wait_until_running(build_name) or not self._http_test(spec, port):
            # cleanup and fail.
            supervisord.stop_and_remove(build_name)
            raise HaltError('Failed to start local server at: "{0}"'.format(self._gunicorn_bind(port)))

        message('Successfully started local server.')
        return port
Beispiel #2
0
    def deactivate(self):
        info = BuildInfo().load()
        if not info.active:
            return

        start_msg('Deactivating instance in role: "{0}":'.format(self._role.name))
        try:
            nginx.delete_server_config(info.active)
            nginx.reload_config()
        except:
            failed_msg('Error stopping Nginx; ignoring.')
            pass

        try:
            supervisord.stop_and_remove(info.active)
        except:
            failed_msg('Error stopping supervisor; ignoring.')
            pass
        succeed_msg('Finished deactivating instance in role: "{0}".'.format(self._role.name))
Beispiel #3
0
    def execute(self, force=False):
        spec = self._role.get('activate', None)
        if not spec:
            return None, None

        start_msg('Begin activation for instance in role: "{0}":'.format(self._role.name))
        info = BuildInfo().load()
        if not force and info.last == info.active and info.active is not None:
            succeed_msg('The last know good build is already active.')
            return None, None

        # the old build is what's currently active; last good build is being activated.
        old_build_name = info.active
        new_build_name = info.last
        message('Last build: {0}; New build: {1}'.format(old_build_name, new_build_name))

        # start gunicorn and Nginx for the new build.
        port = self._start_gunicorn(spec, new_build_name)
        try:
            self._nginx_switch(spec.get('nginx', {}), old_build_name, new_build_name, port)
        except:
            supervisord.stop_and_remove(new_build_name)
            failed_msg('Activation failed for instance in role: "{0}"'.format(self._role.name))
            raise

        # delete the supervisor config for the old build, if any.
        if old_build_name:
            supervisord.stop_and_remove(old_build_name)

        # update the build information on this instance.
        info.active = new_build_name
        info.active_port = port
        info.save()

        succeed_msg('Successfully activated build: "{0}"'.format(new_build_name))
        return new_build_name, port