Skip to content

Commit

Permalink
[misc] Configurable pool size and img file path in aliZsync+alizsw
Browse files Browse the repository at this point in the history
  • Loading branch information
teo committed Jan 29, 2021
1 parent 7723a8b commit 78426c6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
41 changes: 35 additions & 6 deletions hacking/aliZsync
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ ProgName=$(basename $0)

POOLNAME="${ALIZSYNC_POOL_NAME:-aliZsync}"
POOLSIZE="${ALIZSYNC_POOL_SIZE:-100G}"
IMG_FILE_PATH="${ALIZSYNC_IMG_FILE_PATH:-$HOME/$POOLNAME.img}"

INVENTORY_FILE="${ALIZSYNC_INVENTORY:-/etc/o2.d/aliZsync_inventory}"
TARGET_ROOT="${ALIZSYNC_TARGET_ROOT:-/opt/alizsw}"
TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S")
Expand Down Expand Up @@ -70,12 +72,16 @@ sub_help(){

sync_host(){
HOST="$1"
$SYNC_CMD "$DATASET_BINARIES" "ssh://root@$HOST:alizsw/sw/slc7_x86-64"
$SYNC_CMD --sshIdentity "/root/.ssh/id_rsa_aliZsync" "$DATASET_BINARIES" "ssh://root@$HOST:alizsw/sw/slc7_x86-64"
echo -e "\t\t$HOST\tbinaries synchronized"
$SYNC_CMD "$DATASET_MODULES" "ssh://root@$HOST:alizsw/sw/MODULES"
$SYNC_CMD --sshIdentity "/root/.ssh/id_rsa_aliZsync" "$DATASET_MODULES" "ssh://root@$HOST:alizsw/sw/MODULES"
echo -e "\t\t$HOST\tmodules synchronized"
}

sub_build() {
aliBuild build --defaults o2-dataflow "$1" --remote-store="https://s3.cern.ch/swift/v1/alibuild-repo"
}

sub_sync(){
echo "synchronizing tags"
source "$SCRIPT_DIR/aliZsync-job_pool.sh"
Expand Down Expand Up @@ -103,10 +109,32 @@ sub_init(){
exit 1
fi

echo "creating sparse file at $HOME/$POOLNAME.img with size $POOLSIZE"
truncate -s "$POOLSIZE" "$HOME/$POOLNAME.img"
SSH_KEYFILE="$HOME/.ssh/id_rsa_aliZsync"
if [ ! -f "$SSH_KEYFILE" ]; then
echo "creating ssh key file"
mkdir -p "$HOME/.ssh"
ssh-keygen -t rsa -b 4096 -C "aliZsync@`uname -n`" -f "$HOME/.ssh/id_rsa_aliZsync" -q -N ""

echo -n "Enter password for user root on inventory machines:"
read -s password
echo

echo "setting up passwordless authentication"
while read LINE; do
[[ $LINE =~ ^#.* ]] && continue
[[ $LINE =~ ^\[.* ]] && continue

# We only get the first word from the inventory line
HOST=$(echo "$LINE" | awk '{ print $1}')
echo -e "\t$HOST"
sshpass -p "$password" ssh-copy-id -i /root/.ssh/id_rsa_aliZsync "root@$HOST"
done < "$INVENTORY_FILE"
fi

echo "creating sparse file at $IMG_FILE_PATH with size $POOLSIZE"
truncate -s "$POOLSIZE" "$IMG_FILE_PATH"
echo "creating ZFS pool"
sudo zpool create -m "$PWD" "$POOLNAME" "$HOME/$POOLNAME.img"
sudo zpool create -m "$PWD" "$POOLNAME" "$IMG_FILE_PATH"
cd .

# no need to import after create: sudo zpool import -d $HOME -a
Expand All @@ -122,7 +150,8 @@ sub_init(){
}

sub_mount(){
sudo zpool import -d $HOME -a
IMG_DIR="$(basename "$(dirname "$IMG_FILE_PATH")")"
sudo zpool import -d "$IMG_DIR" -a
}

sub_tag(){
Expand Down
4 changes: 4 additions & 0 deletions hacking/aliZsync-sync-zfs-snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def getZFSCmdLine (self, args):
if self.sshIdentity:
cmdLine.extend (['-i', self.sshIdentity])

# Disable StrictHostKeyChecking, as we run in a closed environment
# TODO: make it an option
cmdLine.extend (['-o', 'StrictHostKeyChecking=no'])

cmdLine.append (self.user + '@' + self.server)

cmdLine.extend (args)
Expand Down
13 changes: 9 additions & 4 deletions hacking/alizsw
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
ProgName=$(basename $0)

POOLNAME="${ALIZSW_POOL_NAME:-alizsw}"
POOLSIZE="${ALIZSW_POOL_SIZE:-100G}"
IMG_FILE_PATH="${ALIZSW_IMG_FILE_PATH:-$HOME/$POOLNAME.img}"

TARGET_DIR="${ALIZSW_TARGET_ROOT:-/opt/alizsw}"
TAG_NAME="${2:-latest}"

Expand Down Expand Up @@ -71,10 +74,11 @@ sub_init(){
exit 1
fi

echo "creating sparse file at $HOME/$POOLNAME.img"
truncate -s 100G $HOME/$POOLNAME.img
echo "creating sparse file at $IMG_FILE_PATH"
truncate -s "$POOLSIZE" "$IMG_FILE_PATH"
echo "creating ZFS pool"
sudo zpool create -m $TARGET_DIR $POOLNAME $HOME/$POOLNAME.img
sudo mkdir -p "$TARGET_DIR"
sudo zpool create -m "$TARGET_DIR" "$POOLNAME" "$IMG_FILE_PATH"

cd .

Expand All @@ -92,7 +96,8 @@ sub_list(){
}

sub_mount(){
sudo zpool import -d $HOME -a
IMG_DIR="$(basename "$(dirname "$IMG_FILE_PATH")")"
sudo zpool import -d "$IMG_DIR" -a
}

subcommand=$1
Expand Down

0 comments on commit 78426c6

Please sign in to comment.