CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/scripts/push
Views: 791
#!/usr/bin/env bash
# This script is used to sync out files from one compute node to all the others
# it is used to sync sage, anaconda, etc.
# Copyright: SageMath, Inc.
# License: GPLv3+
set -v
set -e

if [[ $# -eq 0 ]] ; then
    echo 'Error: first argument must be the directory to push or "."'
    exit 1
fi

[[ `whoami` == salvus || `whoami` == root ]] || (echo "You need to be salvus or root!"; exit 1)

WHAT=`readlink -m "$1"`

echo "Syncing out $WHAT in parallel"

#chmod -R a+r $WHAT
#find $WHAT -perm /u+x -execdir chmod a+x {} \;

function do_push() {
   TARGET=$1
   WHAT=$2
   [[ $TARGET = `hostname` ]] && return
   # trailing / is important; ionice: best effort / low priority
   nice ionice -c 2 -n 7 rsync -axH -e 'ssh -o StrictHostKeyChecking=no' --delete $WHAT/ $TARGET:$WHAT/
}

# local functions need to be exported for gnu parallel
export -f do_push

# max 4 jobs to avoid memory blowups
# there are also no closures, that's why "$WHAT" is injected as a second argument
parallel --no-notice --eta --joblog - -j4 do_push {} "$WHAT" ::: compute{0..8}-us