diff --git a/cryosparc_install.sh b/cryosparc_install.sh index 274fd9c..4df88d7 100755 --- a/cryosparc_install.sh +++ b/cryosparc_install.sh @@ -1,157 +1,197 @@ #!/bin/bash set -euo pipefail # Script made from the page # https://docs.ycrc.yale.edu/clusters-at-yale/guides/cryosparc/ license_id= install_path="$HOME"/cryosparc cryosparc_passwd=Password123 # set up some more paths db_path=${install_path}/database worker_path=${install_path}/cryosparc2_worker # Usage usage () { echo "Usage:" echo " -l license_id : License ID" echo " -p install path : prefix for installation [${install_path}] " + echo " -P password : password for initial user" echo " -v : be verbose" echo " -h : print this notice" echo "" } VERBOSE=false +password= # Parse options -while getopts ":l:p:vh" opt; do +while getopts ":l:P:p:vh" opt; do case $opt in l) license_id="${OPTARG}" ;; p) install_path="${OPTARG}" ;; + P) + password="${OPTARG}" + ;; v) VERBOSE=true ;; h) usage OPTIND=1 exit 0 ;; \?) echo "Invalid option: -$OPTARG" >&2 usage OPTIND=1 exit 1 ;; :) echo "Option -$OPTARG requires an argument." >&2 usage OPTIND=1 exit 1 ;; esac done # Reset OPTIND to allow the next invocation to work OPTIND=1 message() { if $VERBOSE then echo "${1}" fi } if [ "x${license_id}" == "x" ]; then echo "[Error] No license id was provided" >&2 usage exit 2 fi message "[Info] Preparing the install path and dowloading cryosparc_master and cryosparc_worker" # go get the installers mkdir -p $install_path cd $install_path # Download master curl -sL -C - -\# https://get.cryosparc.com/download/master-latest/$license_id -o cryosparc2_master.tar.gz # Download worker curl -sL -C - -\# https://get.cryosparc.com/download/worker-latest/$license_id -o cryosparc2_worker.tar.gz message "[Info] Expanding tarballs" tar -xf cryosparc2_master.tar.gz tar -xf cryosparc2_worker.tar.gz module load gcc cuda/11.0.2 python message "[Info] Installing master" cd ${install_path}/cryosparc_master ./install.sh --license $license_id --hostname $(hostname) --dbpath $db_path --yes set +u source ~/.bashrc set -u message "[Info] Installing worker" cd ${install_path}/cryosparc_worker -./install.sh --license $license_id --cudapath $CUDA_HOME --yes +./install.sh --license $license_id --cudapath $CUDA_HOME --ssdpath /tmp --yes set +u source ~/.bashrc set -u message "[Info] Creating worker configs" cryosparc_master_path=${install_path}/cryosparc_master if [ $(grep -c "export PATH" ${cryosparc_master_path}/config.sh) -eq 0 ]; then echo "export PATH=${cryosparc_master_path}/bin:\$PATH" >> ${cryosparc_master_path}/config.sh fi -if [ $(grep -q "export CRYOSPARC_HOSTNAME_CHECK" ${cryosparc_master_path}/config.sh) -eq 0 ]; then - echo "export CRYOSPARC_HOSTNAME_CHECK=${master_host}" >> ${cryosparc_master_path}/config.sh +if [ $(grep -c "export CRYOSPARC_HOSTNAME_CHECK" ${cryosparc_master_path}/config.sh) -eq 0 ]; then + echo "export CRYOSPARC_HOSTNAME_CHECK=${HOSTNAME}" >> ${cryosparc_master_path}/config.sh fi cryosparc_worker_path=${install_path}/cryosparc_worker if [ $(grep -c "export PATH" ${cryosparc_worker_path}/config.sh) -eq 0 ]; then echo "export PATH=${cryosparc_worker_path}/bin:\$PATH" >> ${cryosparc_worker_path}/config.sh fi +cp cryosparcm.sh ${install_path}/cryosparc_master/bin + +if [ $(${install_path}/cryosparc_master/bin/cryosparcm.sh status | grep -c "CryoSPARC is not running") -eq 1 ]; then + ${install_path}/cryosparc_master/bin/cryosparcm.sh start +fi + +user_name=$(whoami) + +mail=$(ldapsearch -x -LLL -h scoldap.epfl.ch -b "o=epfl,c=ch" uid=${user_name} mail | grep mail | awk '{ print $2 }') +firstname=$(ldapsearch -x -LLL -h scoldap.epfl.ch -b "o=epfl,c=ch" uid=${user_name} givenName | grep givenName | awk '{ print $2 }') +lastname=$(ldapsearch -x -LLL -h scoldap.epfl.ch -b "o=epfl,c=ch" uid=${user_name} sn | grep sn | awk '{ print $2 }') +if [ "x$password" != "x" ]; then + ${install_path}/cryosparc_master/bin/cryosparcm.sh createuser --email "${mail}" --firstname "${firstname}" --lastname "${lastname}" --password "${password}" +fi + +user_accounts=$(sacctmgr show assoc where user=${user_name} format=Account%100 -P | grep -v Account) mkdir -p ${install_path}/site_configs && cd ${install_path}/site_configs -cat << EOF > cluster_info.json +for _account in $user_accounts; do + if [ $(sacctmgr show assoc where account=${_account} format=ParentName%100 -P | grep -v "Par Name" | grep -c courses) -eq 0 ]; then + _worker_name=${HOSTNAME}-${_account} + mkdir -p ${install_path}/site_configs/${_worker_name} && cd ${install_path}/site_configs/${_worker_name} + cat << EOF > cluster_info.json { - "name" : "${hostname}", - "worker_bin_path" : "${install_path}/cryosparc_worker/bin/cryosparcw", - "cache_path" : "/tmp/{{ cryosparc_username }}/cryosparc_cache", - "send_cmd_tpl" : "{{ command }}", - "qsub_cmd_tpl" : "sbatch {{ script_path_abs }}", - "qstat_cmd_tpl" : "squeue -j {{ cluster_job_id }}", - "qdel_cmd_tpl" : "scancel {{ cluster_job_id }}", - "qinfo_cmd_tpl" : "sinfo" + "name": "${_worker_name}", + "worker_bin_path": "${install_path}/cryosparc_worker/bin/cryosparcw", + "cache_path": "/tmp/{{ cryosparc_username }}/cryosparc_cache", + "send_cmd_tpl": "{{ command }}", + "qsub_cmd_tpl": "sbatch {{ script_path_abs }}", + "qstat_cmd_tpl": "squeue -j {{ cluster_job_id }}", + "qdel_cmd_tpl": "scancel {{ cluster_job_id }}", + "qinfo_cmd_tpl": "sinfo" } EOF -cat << EOF > cluster_script.sh + cat << EOF > cluster_script.sh #!/bin/bash -l #SBATCH --job-name cryosparc_{{ project_uid }}_{{ job_uid }} #SBATCH -n {{ num_cpu }} -#SBATCH --gres:gpu={{ num_gpu }} -#SBATCH --mem={{ ram_gb|int }}GB -#SBATCH --time=48:0:0 -#SBATCH -o {{ job_dir_abs }} -#SBATCH -e {{ job_dir_abs }} +#SBATCH --gres gpu:{{ num_gpu }} +#SBATCH --mem {{ ram_gb|int }}GB +#SBATCH --time 48:0:0 +#SBATCH -o {{ job_dir_abs }}/slurm.out +#SBATCH -e {{ job_dir_abs }}/slurm.err +#SBATCH -A ${_account} module load gcc cuda/11.0.2 python ln -sf \${TMPDIR} /tmp/${USER}/cryosparc2_cache {{ run_cmd }} EOF -${install_path}/cryosparc_master/bin/cryosparcm cluster connect + ${install_path}/cryosparc_master/bin/cryosparcm cluster connect + fi +done + +if [ "x$password" = "x" ]; then + echo "" + echo "================================================================================" + echo "================================================================================" + echo " No password was given the initial account cannot be created" + echo " Create one using the following command:" + echo " ${install_path}/cryosparc_master/bin/cryosparcm.sh createuser --email \"${mail}\" --firstname \"${firstname}\" --lastname \"${lastname}\" --password \"\"" + echo "================================================================================" + echo "================================================================================" + echo "" +fi