#!/usr/bin/env bash

# {{ ansible_managed }}

source {{ edxapp_app_dir }}/edxapp_env
COMMAND=$1

case $COMMAND in
    start)
        {{ supervisor_venv_bin }}/supervisord --configuration {{ supervisor_cfg }}

        # Needed to run bower as root. See explanation around 'edx_django_service_user=root'
        echo '{ "allow_root": true }' > /root/.bowerrc

        # Docker requires an active foreground task. Tail the logs to appease Docker and
        # provide useful output for development.
        tail -f {{ edxapp_devstack_logs | join(" -f ") }}
        ;;
    open)
        . {{ edxapp_nodeenv_bin }}/activate
        . {{ edxapp_venv_bin }}/activate
        cd {{ edxapp_code_dir }}

        /bin/bash
        ;;
esac
