Wrapper script to check hostname

At our institute, users are allowed to run cryosparc on our cluster’s login nodes. One problem is that people forget which of the several login nodes they use for cryosparc’s master process. If you try to start cryosparc on the wrong node it can lead to hanging processes, database problems, and strange error messages. To avoid this, I created the following wrapper script:

#!/bin/bash
#
# Wrapper script to call cryosparcm safely.
#
# Instead of adding cryosparc2_master/bin to your PATH in ~/.bashrc, add the following lines:
#
#     export CRYOSPARC_HOME=/path/to/cryosparc
#     alias cryosparcm=/data/project/bio/software/cryoSPARC/v2/scripts/cryosparcm.sh
#
# The main advantage is that it will warn you if you try to start cryosparc from the wrong host.
#
# Author: Spencer Bliven
# Version: 1.0.0 (2020-03-27)
# License: Public domain (https://unlicense.org/)


# Default CRYOSPARC_HOME, if it isn't set by the user
CRYOSPARC_HOME="${CRYOSPARC_HOME:-$HOME/cryosparc}"

# Auto-detect master hostname
if [[ -f "$CRYOSPARC_HOME/cryosparc2_master/config.sh" ]]; then
        source "$CRYOSPARC_HOME/cryosparc2_master/config.sh"
else
        echo "$CRYOSPARC_HOME/cryosparc2_master/config.sh not found. Set the CRYOSPARC_HOME variable."
        exit 1
fi
if [[ -z ${CRYOSPARC_MASTER_HOSTNAME} ]]; then
        echo "Unabler to determine cryosparc master. Make sure CRYOSPARC_HOME is correct (currently ${CRYOSPARC_HOME:-unset})" >&2
        exit 1
fi

# Check for correct host
if [[ "$(hostname -f)" != "${CRYOSPARC_MASTER_HOSTNAME}" ]]; then
        echo "Run cryosparcm from ${CRYOSPARC_MASTER_HOSTNAME}" >&2
        exit 1
fi

exec "$CRYOSPARC_HOME/cryosparc2_master/bin/cryosparcm" "$@"

I thought I’d share in case anyone else finds it useful.

1 Like

Hey @sbliven,

Thanks for making this! I’m going to link this post to a section in our new cryoSPARC Reference documentation, which is coming soon!

1 Like

Great, glad to share!

Can we do same for worker node as well on cluster?