Running shell commands

You can run shell commands to administer Hue programmatically. For example, to reset the superuser password or to assign an LDAP user superuser permissions.

To run Hue shell commands:

  1. Set HUE_CONF_DIR to the latest Hue process directory:
    export HUE_CONF_DIR="/var/run/cloudera-scm-agent/process/`ls -alrt /var/run/cloudera-scm-agent/process | grep HUE_SERVER | tail -1 | awk '{print $9}'`"
    echo $HUE_CONF_DIR
              
  2. Set environment variables used to run the Hue webserver:
    • CentOS/RHEL:

      
      for line in `strings /proc/$(lsof -i :8888|grep -m1 python|awk '{ print $2 }')/environ|egrep -v "^HOME=|^TERM=|^PWD="`;do export $line;done
                    
    • Ubuntu:

      
      for line in `strings /proc/$(lsof -i :8888|grep -m1 hue|awk '{ print $2 }')/environ|egrep -v "^HOME=|^TERM=|^PWD="`;do export $line;done
                    
  3. Run shell subcommands

    When true, HUE_IGNORE_PASSWORD_SCRIPT_ERRORS runs the Hue shell even if hue.ini contains passwords generated by Cloudera Manager (such as bind_password and ssl_password).

    For CDH parcel deployments:

    • Run the interactive Hue Python shell (Ctrl+D to quit)
      HUE_IGNORE_PASSWORD_SCRIPT_ERRORS=1 /opt/cloudera/parcels/CDH/lib/hue/build/env/bin/hue shell

      Or with the database password:

      HUE_IGNORE_PASSWORD_SCRIPT_ERRORS=1 HUE_DATABASE_PASSWORD=<your db password> /opt/cloudera/parcels/CDH/lib/hue/build/env/bin/hue shell
    • Change a user password
      HUE_IGNORE_PASSWORD_SCRIPT_ERRORS=1 /opt/cloudera/parcels/CDH/lib/hue/build/env/bin/hue changepassword admin
    • Promote Hue user to superuser
      HUE_IGNORE_PASSWORD_SCRIPT_ERRORS=1 /opt/cloudera/parcels/CDH/lib/hue/build/env/bin/hue shell
      
      from django.contrib.auth.models import User
      a = User.objects.get(username='gwen')
      a.is_superuser = True
      a.save()
    • Count all of the documents of a certain user:

      
      from django.contrib.auth.models import User
      from desktop.models import Document2
      
      user=User.objects.get(username='demo')
      Document2.objects.documents(user=user).count()
      
      Out[X]: 1167
                    
    • List available subcommands
      HUE_IGNORE_PASSWORD_SCRIPT_ERRORS=1 /opt/cloudera/parcels/CDH/lib/hue/build/env/bin/hue

    For CDH package deployments:

    • HUE_IGNORE_PASSWORD_SCRIPT_ERRORS=1 /usr/lib/hue/build/env/bin/hue shell