Commit e25f67cc authored by Chris Hines's avatar Chris Hines
Browse files

Merge branch 'otherenvs' into 'master'

Otherenvs

See merge request !3
parents e92053df ebcffa08
#!/bin/bash
if [ $# -eq 2 ]
then
INSTALLDIR=$1
ENVNAME=$2
else
echo "please try add-strudel2-conda-env INSTALLDIR ENVNAME"
echo "where ISNTALLDIR is a path to miniconda that can be activated"
echo "and ENVNAME is the name of an environment"
fi
SCRIPT=$(readlink -f $0) # Get the base directory
# The section below sets up the paths to executable files and templates
JQ=`dirname $SCRIPT`/jq
TEMPLATE=`dirname $SCRIPT`/conda-env-jupyter.sh.template
WORKINGDIR=$INSTALLDIR
APPSJSON=/home/$USER/.strudel2/apps.json
APPSJSONTEMPFILE=/home/$USER/.strudel2/apps.json.temp
APPSJSONNEW=/home/$USER/.strudel2/apps.json.new
APPSJSONTEMPLATE=`dirname $SCRIPT`/conda-env-jupyter-apps.json.template
mkdir -p ~/.strudel2/
cp -rf $TEMPLATE ~/.strudel2/conda-env-jupyter.sh
chmod +x ~/.strudel2/conda-env-jupyter.sh
# Configure Custom Name for apps.json
WORKINGDIRSUBS=`echo "${INSTALLDIR//\//.}"` # Need this to remove the / from the template since it breaks Slurm
sed -e "s|LOCATION|${WORKINGDIRSUBS}|g" $APPSJSONTEMPLATE > $APPSJSONTEMPFILE
sed -i -e "s|INSTALLDIR|${INSTALLDIR}|g" $APPSJSONTEMPFILE
sed -i -e "s|ENVNAME|${ENVNAME}|g" $APPSJSONTEMPFILE
# This will check whether the apps.json already exists
# If it does, use the jq binary to append the template into existing file
# Else, just copy the template file over.
if [ -f $APPSJSON ]
then
$JQ -s '.[0] + .[1]' $APPSJSON $APPSJSONTEMPFILE > $APPSJSONNEW
rm $APPSJSON
mv $APPSJSONNEW $APPSJSON
else
mv $APPSJSONTEMPFILE $APPSJSON
fi
rm -rf $APPSJSONTEMPFILE
# Configure Jupyter Notebook for Strudel2
echo $INSTALLDIR >> ~/.jupyterenv
mkdir -p ~/.strudel2/
sed -e "s|LOCATION|${WORKINGDIR}|g" $TEMPLATE > ~/.strudel2/jupyter.sh
chmod +x ~/.strudel2/jupyter.sh
echo "Strudel2 is not configured to use your conda environment"
[
{
"url": null,
"name": "Jupyter Lab from ENVNAME LOCATION",
"startscript": "#!/bin/bash\n[ -f $HOME/.strudel2/conda-env-jupyter.sh ] && $HOME/.strudel2/conda-env-jupyter.sh INSTALLDIR ENVNAME || /usr/local/sv2/jupyter/jupyter_custom.sh\n",
"instactions": [
{
"name": "Connect",
"paramscmd": "/usr/local/sv2/dev/jupyter/jupyter_params.py {jobid}",
"client": {"cmd": null, "redir": "?token={token}"},
"states": ["RUNNING"]
},
{
"name": "View log",
"paramscmd": "/usr/local/strudel2_cluster/latest/bin/wstool cat \"~/.strudel2*-{jobid}.out\"",
"client": {"cmd": null, "redir": "?token={token}" },
"states": ["RUNNING","Finished"]
},
{
"name": "View Usage",
"paramscmd": "/usr/local/strudel2_cluster/latest/bin/wstool sacct --format \"JobId,Account,AllocCPUS,State,ReqMem,MaxVMSize\" -j {jobid}",
"client": {"cmd": null, "redir": "?token={token}" },
"states": ["Finished"]
},
{
"name": "Remove log",
"paramscmd": "rm ~/.strudel2-*{jobid}.out ; echo []",
"client": null,
"notunnel": true,
"states": ["Finished"]
}
],
"desc": "To run your own installation of jupyter you must first <ul> <li> Install Jupyter </li> <li> Create a file called <code>~/.strudel2/jupyter.sh</code> containg the command to start jupyter. This may include activating a conda env.</li></ul>",
"localbind": true,
"applist": null
}
]
#!/bin/bash
if [ ! -d $1 ]
then
echo "Directory $1 DOES NOT exists."
exit 1
fi
CONDADIR=$1
ENVNAME=$2
source $CONDADIR/bin/activate
conda activate $ENVNAME
module load cuda/11.0
jupyter lab --no-browser --NotebookApp.notebook_dir=/home/$USER --ContentsManager.allow_hidden=True
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment