Skip to content

Instantly share code, notes, and snippets.

@jramnai
Last active March 12, 2024 21:04
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jramnai/94e8aa05763df53795c8349dc76b431b to your computer and use it in GitHub Desktop.
Save jramnai/94e8aa05763df53795c8349dc76b431b to your computer and use it in GitHub Desktop.
Useful commands in Open edX

Useful commands in Open edX

Change access permission of pem file

sudo chmod 400 my_private_key.pem  

SSH into your server

ssh -i my_private_key.pem ubuntu@<ip_of_your_server>  

Set the OPENEDX_RELEASE variable

# For native installation  
export OPENEDX_RELEASE=open-release/maple.master  
  
# For devstack docker installation  
export OPENEDX_RELEASE=maple.master  

Check logs

  • Request logs and errors from the LMS & CMS. If you're getting a 500 error on a certain request, look here.
    sudo tail -f /edx/var/log/lms/edx.log  
    sudo tail -f /edx/var/log/cms/edx.log  
    
  • Startup error messages and debug output from the running LMS & CMS Django process. If you're getting a startup error, look here.
    sudo tail -f /edx/var/log/supervisor/lms-stderr.log  
    sudo tail -f /edx/var/log/supervisor/cms-stderr.log  
    
  • Debug output from the supervisor task manager. If you make changes to the supervisor task definitions, look here.
    sudo tail -f /edx/var/log/supervisor/supervisord.log  
    
  • Errors from Nginx proxy server that front-ends both the LMS and CMS. Mostly access or configuration-related errors. If you're getting a 4xx or 5xx error, look here
    sudo tail -f /edx/var/log/nginx/error.log  
    
  • Access logs for all requests to the server. If you want to see apache style logs for every request your server is getting, look here.
    sudo tail -f /edx/var/log/nginx/access.log  
    
  • Error from LMS workers. If you're getting worker errors, look here.
    sudo tail -f /edx/var/log/supervisor/lms_default_1-stderr.log  
    sudo tail -f /edx/var/log/supervisor/lms_high_1-stderr.log  
    sudo tail -f /edx/var/log/supervisor/lms_high_mem_1-stderr.log  
    
  • Error from CMS workers. If you're getting worker errors, look here.
    sudo tail -f /edx/var/log/supervisor/cms_default_1-stderr.log  
    sudo tail -f /edx/var/log/supervisor/cms_high_1-stderr.log  
    
  • Errors from Forum service. If you're getting any errors in Forum, look here.
    sudo tail -f /edx/var/log/supervisor/forum-stderr.log  
    
  • On devstack docker installation
    make <service_name>-logs  
    # For LMS  
    make lms-logs  
    

Running your server in debugging mode

sudo /edx/bin/supervisorctl stop lms

# For ironwood and earlier releases
sudo -u www-data /edx/bin/python.edxapp /edx/app/edxapp/edx-platform/manage.py lms runserver 8000 --settings production

# For koa and later releases
cd /edx/app/edxapp/edx-platform
source /edx/app/edxapp/edxapp_env
sudo -E -u www-data /edx/app/edxapp/venvs/edxapp/bin/python manage.py lms runserver 8000 --settings production

# Once you are done with the debugging
Ctrl + c
sudo /edx/bin/supervisorctl start lms

Check your configurations

  • Most configuration parameters for the app.
    • Feature flags
    • backend server locations
    • theme related settings
  • Authentication parameters for the app
    • API Keys
    • Database passwords
    • occasional settings that are paired with authentication
# For ironwood and earlier releases  
sudo nano /edx/app/edxapp/lms.env.json  
sudo nano /edx/app/edxapp/cms.env.json  
sudo nano /edx/app/edxapp/lms.auth.json  
sudo nano /edx/app/edxapp/cms.auth.json  

# For juniper and later releases  
sudo nano /edx/etc/lms.yml  
sudo nano /edx/etc/studio.yml  

Install nano in lms shell in devstack docker

make lms-shell  
apt-get install nano  

manage.py commands

  • List all manage.py commands
    # For Native Installation  
    sudo -H -u edxapp bash  
    source ~/edxapp_env  
    cd ~/edx-platform  
    ./manage.py lms --settings production help  
      
    # For devstack docker installation  
    make lms/studio-shell  
    ./manage.py lms --settings devstack_docker help  
    
  • Delete a course in Open edX
    ./manage.py cms delete_course course-v1:edX+DemoX+Demo_Course --settings <your_settings>  
    
  • Open Django shell (InteractiveConsole)
    ./manage.py lms shell --settings <your_settings>  
    
  • Compile SCSS files
    ./manage.py lms compile_sass --settings <your_settings>  
    
  • Collect static files
    # For LMS  
    ./manage.py lms --settings <your_settings> collectstatic --ignore "fixtures" --ignore "karma_*.js" --ignore "spec" --ignore "spec_helpers" --ignore "spec-helpers" --ignore "xmodule_js" --ignore "geoip" --ignore "sass" --noinput > /dev/null  
      
    # For CMS  
    ./manage.py cms --settings <your_settings> collectstatic --ignore "fixtures" --ignore "karma_*.js" --ignore "spec" --ignore "spec_helpers" --ignore "spec-helpers" --ignore "xmodule_js" --ignore "geoip" --ignore "sass" --noinput > /dev/null  
    
  • Copy programs data into the LMS
    ./manage.py lms cache_programs --settings <your_settings>  
    
  • Compile Translation files
    ./manage.py lms compilejsi18n --settings <your_settings>  
    ./manage.py lms compilemessages --settings <your_settings>  
    
  • Reindex courses
    # reindexes courses with provided keys
    ./manage.py cms reindex_course <course_id_1> <course_id_2> ...
    
    # reindexes all available courses
    ./manage.py cms reindex_course --all
    

Refresh course metadata in discovery

Discovery maintains metadata for program and course information. To ingest metadata into discovery from LMS, e-commerce, and the marketing site run the following commands in devstack to enter the discovery shell and refresh the metadata.

make discovery-shell  
./manage.py refresh_course_metadata  

Supervisor commands on native installation

  • Restart Supervisor service
    sudo systemctl restart supervisor  
    
  • See what services are running
    sudo /edx/bin/supervisorctl status  
    
  • Restarting services
    # LMS  
    sudo /edx/bin/supervisorctl restart lms  
      
    # Workers  
    sudo /edx/bin/supervisorctl restart edxapp_worker:  
    
  • Stop services
    # LMS  
    sudo /edx/bin/supervisorctl stop lms  
      
    # Workers  
    sudo /edx/bin/supervisorctl stop edxapp_worker:  
    

Update Assets

# To update lms and cms assets  
paver update_assets --settings <your_settings>  
  
# To update lms assets  
paver update_assets lms --settings <your_settings>  
  
# To update cms assets  
paver update_assets cms --settings <your_settings>  

MySQL Access

mysql -h <host> -u <username> -p<password>  

Create MySQL user and grant privileges

mysql -u root  
use edxapp  
CREATE USER 'edxapp001'@'%' IDENTIFIED BY 'password';  
GRANT ALL PRIVILEGES ON edxapp.* TO 'edxapp001'@'%';  
  
use edxapp_csmh  
CREATE USER 'edxapp_cmsh001'@'%' IDENTIFIED BY 'password';  
GRANT ALL PRIVILEGES ON edxapp_csmh.* TO 'edxapp_cmsh001'@'%';  
  
CREATE USER 'migrate'@'%' IDENTIFIED BY 'password';  
GRANT ALL PRIVILEGES ON edxapp.* TO 'migrate'@'%';  
GRANT ALL PRIVILEGES ON edxapp_csmh.* TO 'migrate'@'%';  
  
# if necessary  
FLUSH PRIVILEGES  

MongoDB Access

mongo --port 27017 -u admin -p password --authenticationDatabase admin  

Install requirements in edx-platform

cd ~/edx-platform  
make requirements  

Renew SSL Cert

certbot-auto --renew-by-default  

Install and use Screen commands

  • Install

    sudo apt install screen  
    
  • Start a new screen

    screen -S <screen_name>
    
  • List down available screen sessions

    screen -ls
    
  • Resume screen session

    screen -r <screen_name>
    
  • Detach from screen

    Ctrl+a d
    
  • Create a new window in running screen

    Ctrl+a c
    
  • Switch between screen windows

    Ctrl+a [0-9]
    
  • Name screen window

    Ctrl+a :title server-1
    
  • Kill a detached screen

    screen -r <screen_name>
    Ctrl+a :quit
    
  • For screen labels to properly work, you need to copy follwing file in home directory of the user from which you are going to create a screen

    $ nano screenrc
    hardstatus on
    hardstatus alwayslastline
    hardstatus string "%w%=%m/%d %c"
    

Refernces

https://openedx.atlassian.net/wiki/spaces/OpenOPS/pages/60227913/Managing+OpenEdX+Tips+and+Tricks

https://openedx.atlassian.net/wiki/spaces/LEARNER/pages/171180253/Program+Bundling+Setup#ProgramBundling-Settingupbundlingonthelocalenvironment

https://openedx.atlassian.net/wiki/spaces/OpenOPS/pages/49873839/Debugging+Edxapp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment