def handle(self, *args, **options):
        aggressive = options['aggressive']

        if options['makeitso']:
            if options['no_input']:
                do_kill = True
            else:
                check_kill = raw_input(
                    """You sure you want to slay these gunicorn processes???

                    Note, you should only do this when you know supervisorctl is in a stuck state.
                    So, in short, I hope you know what you're doing.

                    Proceed with the slaying? (yes/no) """)
                do_kill = check_kill == "yes"

            if do_kill:
                if not aggressive:
                    print "\tShutting down django via supervisor:"
                    self.supervisor("stop")
                print "\tProceeding to kill gunicorn processes."
                self.check_unicorns()
                pk = Popen(['pkill', '-9', '-f', GUNICORN_CMD],
                           stdout=PIPE,
                           stderr=PIPE)
                print pk.stdout.read()

                if not aggressive:
                    print "\tRestarting django via supervisor:"
                    self.supervisor("start")
                AuditEvent.audit_command()
            else:
                print "\tNo slaying...for now"
Esempio n. 2
0
    def handle(self, *args, **options):
        aggressive = options['aggressive']

        if options['makeitso']:
            if options['no_input']:
                do_kill = True
            else:
                check_kill = raw_input(
                    """You sure you want to slay these gunicorn processes???

                    Note, you should only do this when you know supervisorctl is in a stuck state.
                    So, in short, I hope you know what you're doing.

                    Proceed with the slaying? (yes/no) """)
                do_kill = check_kill == "yes"

            if do_kill:
                if not aggressive:
                    print "\tShutting down django via supervisor:"
                    self.supervisor("stop")
                print "\tProceeding to kill gunicorn processes."
                self.check_unicorns()
                pk = Popen(['pkill', '-9', '-f', GUNICORN_CMD], stdout=PIPE, stderr=PIPE)
                print pk.stdout.read()

                if not aggressive:
                    print "\tRestarting django via supervisor:"
                    self.supervisor("start")
                AuditEvent.audit_command()
            else:
                print "\tNo slaying...for now"
    def handle(self, *args, **options):
        self.source_uri = getattr(settings, 'PRODUCTION_COUCHDB_URI', None)
        self.target_uri = XFormInstance.get_db().uri
        if self.source_uri is None:
            print "\n\tNo production URI to replicate from, we're done here.\n"
            print "\n\tNo settings.PRODUCTION_COUCHDB_URI has been set\n"
            sys.exit()

        self.domain_list = getattr(settings, 'STAGING_DOMAINS', [])
        if len(self.domain_list) == 0:
            print "\n\tUh, there aren't any domains, so this'll replicate everything, " \
                  "\n\tI don't think you want to do this." \
                  "\n\tPlease set a list of domains in localsettings.STAGING_DOMAINS " \
                  "\n\n\tgoodbye."
            sys.exit()

        if 'cancel' in args:
            self.cancel = True
        else:
            self.cancel = False

        self.repl_domains()
        self.repl_docs()
        self.repl_docs_of_type('CommCareBuild')
        self.repl_docs_of_type('CommCareBuildConfig')
        self.repl_docs_of_type('Organization')
        AuditEvent.audit_command()
Esempio n. 4
0
    def handle(self, *args, **options):
        source_uri = getattr(settings, 'PRODUCTION_COUCHDB_URI', None)
        target_uri = XFormInstance.get_db().uri
        if source_uri is None:
            print "\n\tNo production URI to replicate from, we're done here.\n"
            print "\n\tNo settings.PRODUCTION_COUCHDB_URI has been set\n"
            sys.exit()

        input_query = options['query_string']

        if not input_query:
            print "\tRunning default query for user.is_superuser"
            query_string = BASE_QUERY

        else:
            query_string = input_query

        print "\n\tRunning user query: %s" % query_string

        user_pillow = UserPillow()
        user_es = user_pillow.get_es()

        doc_ids = [
            res['_id'] for res in get_query_results(user_es, query_string)
        ]

        do_replicate = options['makeitso']
        repl_params = {'doc_ids': doc_ids}

        if 'cancel' in args:
            repl_params['cancel'] = True
            print "\n\tSending a replication cancel notification to server"
        else:
            print "\n\tStarting staging replication from prod"

        if do_replicate:
            server = CommCareUser.get_db().server
            server.replicate(source_uri, target_uri, **repl_params)
            AuditEvent.audit_command()
        else:
            print "\n\tReplication dry run with params: %s" % repl_params
    def handle(self, *args, **options):
        source_uri = getattr(settings, 'PRODUCTION_COUCHDB_URI', None)
        target_uri = XFormInstance.get_db().uri
        if source_uri is None:
            print "\n\tNo production URI to replicate from, we're done here.\n"
            print "\n\tNo settings.PRODUCTION_COUCHDB_URI has been set\n"
            sys.exit()

        input_query = options['query_string']

        if not input_query:
            print "\tRunning default query for user.is_superuser"
            query_string = BASE_QUERY

        else:
            query_string = input_query

        print "\n\tRunning user query: %s" % query_string

        user_pillow = UserPillow()
        user_es = user_pillow.get_es()

        doc_ids = [res['_id'] for res in get_query_results(user_es, query_string)]

        do_replicate = options['makeitso']
        repl_params = {
            'doc_ids': doc_ids
        }

        if 'cancel' in args:
            repl_params['cancel'] = True
            print "\n\tSending a replication cancel notification to server"
        else:
            print "\n\tStarting staging replication from prod"

        if do_replicate:
            server = CommCareUser.get_db().server
            server.replicate(source_uri, target_uri, **repl_params)
            AuditEvent.audit_command()
        else:
            print "\n\tReplication dry run with params: %s" % repl_params