playbooks/roles/ood-applications/files/bc_jupyter/template/before.sh.erb (38 lines of code) (raw):

# Export the module function if it exists THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" [[ $(type -t module) == "function" ]] && export -f module # Find available port to run server on port=$(find_port ${host}) # Generate SHA1 encrypted password (requires OpenSSL installed) SALT="$(create_passwd 16)" password="$(create_passwd 16)" PASSWORD_SHA1="$(echo -n "${password}${SALT}" | openssl dgst -sha1 | awk '{print $NF}')" # The `$CONFIG_FILE` environment variable is exported as it is used in the main # `script.sh.erb` file when launching the Jupyter server. export CONFIG_FILE="${PWD}/config.py" JUPYTER_API=lab export JUPYTERLAB_WORKSPACES_DIR=$PWD export jupyter_api="$JUPYTER_API" # Notebook root directory export NOTEBOOK_ROOT="${NOTEBOOK_ROOT:-${HOME}}" # Generate Jupyter configuration file with secure file permissions ( umask 077 cat > "${CONFIG_FILE}" << EOL c.KernelSpecManager.ensure_native_kernel = False c.NotebookApp.ip = '*' c.NotebookApp.port = ${port} c.NotebookApp.base_url = '/node/${host}/${port}/' c.NotebookApp.port_retries = 0 c.NotebookApp.password = u'sha1:${SALT}:${PASSWORD_SHA1}' c.NotebookApp.open_browser = False c.NotebookApp.allow_origin = '*' c.NotebookApp.notebook_dir = '${NOTEBOOK_ROOT}' c.NotebookApp.disable_check_xsrf = True EOL ) <%- if OodAppkit.clusters[context.cluster].job_config[:adapter] == 'pbspro' -%> # TODO : Use the job ID for the container name export CONTAINER_NAME=jupyter.$PBS_JOBID $THIS_DIR/get_container.sh <%=context.container_image%> $CONTAINER_NAME <%- end -%>