vhost-stack/bin/vhost-user-jails-sync.sh
Matthew Saunders Brown 4226322936 initial commit
2021-04-04 13:28:22 -07:00

52 lines
1.1 KiB
Bash

#!/bin/bash
#
# vhost-stack
# https://git.stack-source.com/msb/vhost-stack
# MIT License Copyright (c) 2021 Matthew Saunders Brown
# load config
source /usr/local/etc/vhost.conf || echo "ERROR: Either you do not have vhost user permissions or the config file is missing." && exit
mode=q
if [ -n "$1" ]; then
if [ "$1" = 'verbose' ] || [ "$1" = 'v' ]; then
mode=i
elif [ "$1" = 'dry-run' ] || [ "$1" = 'n' ]; then
mode=vn
fi
fi
# check that node is "active"
vhost::set-nodeRole
if [ "$nodeRole" != "active" ]; then
echo "NOTICE: node role not 'active'. bailing out"
exit 1
fi
# make sure jails dir exists
if [[ ! -e /usr/jails/ ]]; then
echo "/usr/jails does not exist"
exit 1
fi
# check if any jails exist
if [ ! "$(ls -A /usr/jails/)" ]; then
echo "no jails exist"
exit 1
fi
# get list of jails
cd /usr/jails/
jails=(*)
vhost::set-clusterNodes other
for jail in "${jails[@]}"
do
for node in "${clusterNodes[@]}"
do
rsync -$mode --archive --no-times --hard-links --exclude=/usr/jails/$jail/home --exclude=/usr/jails/$jail/var/www --relative --delete --rsh=/usr/bin/ssh /usr/jails/$jail root@$node.lan:/
done
done