added caddy install
added osxfer script for transfering a root filesystem based on subvolumesmaster
parent
edfbbe7fe0
commit
0efd6a0b9e
|
@ -0,0 +1,22 @@
|
|||
|
||||
caddy_install () {
|
||||
|
||||
local target
|
||||
local dir="$(dirname $(realpath "${BASH_SOURCE:-$0}"))"
|
||||
target=${1:-/opt/caddy}
|
||||
[[ -d $target ]] || mkdir -p $target
|
||||
echo installing caddy to $target
|
||||
if /bin/cp -r -f $dir/caddy/* $target; then
|
||||
pushd $target || return
|
||||
echo CADDY_DIR=$target >> .env
|
||||
source .env
|
||||
cp conf/example.conf conf/$CONF
|
||||
./config
|
||||
else
|
||||
echo unable to copy caddy files to $target, install aborted
|
||||
fi
|
||||
popd || return
|
||||
}
|
||||
|
||||
# if script was executed then call the function
|
||||
(return 0 2>/dev/null) || caddy_install $@
|
|
@ -0,0 +1,9 @@
|
|||
# copy to .env and edit to suit
|
||||
COMPOSE_PROJECT_NAME=caddy
|
||||
# default NAME is caddy
|
||||
NAME=${COMPOSE_PROJECT_NAME}
|
||||
IMAGE=ucommandit/caddy-r53
|
||||
CREDENTIALS=${DNS_CHALLENGE_CREDENTIALS:-$PWD/credentials.env}
|
||||
# will use Caddyfile unless CONF is set
|
||||
# this file should be in /conf on your host (e.g. my.conf)
|
||||
CONF=$(hostnamectl hostname)
|
|
@ -0,0 +1,23 @@
|
|||
#!/bin/bash
|
||||
|
||||
# example using wildcart
|
||||
*.domain.net *.subdomain.domain.net {
|
||||
|
||||
tls domain.net@gmail.com {
|
||||
dns route53 {
|
||||
max_retries 10
|
||||
}
|
||||
}
|
||||
|
||||
# example simple files server
|
||||
# @files host files.domain.net
|
||||
# handle @files {
|
||||
# root * <some dir>
|
||||
# file_server browse
|
||||
# }
|
||||
|
||||
@portainer host docker.domain.net
|
||||
handle @portainer {
|
||||
reverse_proxy subdomain.domain.net:9000
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
#!/bin/bash
|
||||
docker-compose config
|
|
@ -0,0 +1,38 @@
|
|||
services:
|
||||
caddy:
|
||||
container_name: ${NAME:-caddy}
|
||||
image: ${IMAGE:-caddy}
|
||||
# if no $CONF is given then Caddyfile in ${PWD}/conf:/opt/caddy/conf will be used
|
||||
command: caddy run ${CONF}
|
||||
hostname: ${NAME:-caddy}
|
||||
env_file:
|
||||
- $CREDENTIALS
|
||||
volumes:
|
||||
- data:/opt/caddy/data
|
||||
- settings:/opt/caddy/settings
|
||||
- conf:/opt/caddy/conf
|
||||
# - files:/opt/caddy/files
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- 80:80
|
||||
- 443:443
|
||||
# port 2019 is for API, not required
|
||||
# - 2019:2019
|
||||
# binding data and settings are not required
|
||||
# But if there volumes are deleted caddy will need to redo all the certs
|
||||
volumes:
|
||||
data:
|
||||
# driver_opts:
|
||||
# type: none
|
||||
# device: ${PWD}/data
|
||||
# o: bind
|
||||
settings:
|
||||
# driver_opts:
|
||||
# type: none
|
||||
# device: ${PWD}/config
|
||||
# o: bind
|
||||
conf:
|
||||
driver_opts:
|
||||
type: none
|
||||
device: ${PWD}/conf
|
||||
o: bind
|
|
@ -0,0 +1,3 @@
|
|||
[[ $1 ]] && opt="-n $1"
|
||||
[[ $1 == "f" ]] && opt="-f"
|
||||
docker-compose logs $opt
|
|
@ -0,0 +1,9 @@
|
|||
# UCI Caddy Container
|
||||
|
||||
use caddy.inst to install on your host
|
||||
|
||||
by default install script will create file <hostname>.conf in /opt/caddy/conf
|
||||
|
||||
/opt/caddy/conf by default will be mounted in container
|
||||
|
||||
now create your (route53) dns challenge credentails file, by defualt with be /opt/caddy/credentials.env
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
./stop
|
||||
./start
|
|
@ -0,0 +1 @@
|
|||
docker-compose up
|
|
@ -0,0 +1 @@
|
|||
docker-compose down -v
|
|
@ -0,0 +1,5 @@
|
|||
echo upping the max size of the host buffer
|
||||
echo net.core.rmem_max=2500000 | sudo tee -a /etc/sysctl.conf
|
||||
# confirm
|
||||
sudo sysctl -p | grep rmem_max
|
||||
docker-compose up -d
|
|
@ -0,0 +1 @@
|
|||
docker-compose down
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
source .env
|
||||
docker exec -it ${NAME:-caddy} bash -l
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/bash
|
||||
./stop
|
||||
docker-compose pull
|
||||
./start
|
|
@ -1,36 +0,0 @@
|
|||
#!/bin/bash
|
||||
module_load filesystem
|
||||
module_load confirm
|
||||
|
||||
copy_rootfs () {
|
||||
local dr=""
|
||||
# local de=--delete-excluded
|
||||
[[ ! $(mounted $1) ]] && echo $1 is not a mountpoint exiting && return 2
|
||||
cmd=$(echo sudo rsync $dr $de --progress -aAXv --exclude={\
|
||||
"/dev/*",\
|
||||
"/proc/*",\
|
||||
"/sys/*",\
|
||||
"tmp/*",\
|
||||
"/run/*",\
|
||||
"/mnt/*",\
|
||||
"/media/*",\
|
||||
"/lost+found",\
|
||||
"/data/*",\
|
||||
"/backup/*",\
|
||||
"/snapshots/*",\
|
||||
"/remotes/*",\
|
||||
"*[Cc]ache*",\
|
||||
"*/[Ll]og/*",\
|
||||
"*/[Ll]ogs/*",\
|
||||
"*.[Ll]og",\
|
||||
"/etc/fstab*",\
|
||||
"/boot/refind_linux.conf"\
|
||||
}\
|
||||
/ $1
|
||||
)
|
||||
echo $cmd
|
||||
if confirm run this copy command; then
|
||||
$cmd
|
||||
fi
|
||||
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
#!/bin/bash
|
||||
|
||||
scripts_dir="$(dirname $(realpath "${BASH_SOURCE:-$0}"))"
|
||||
|
||||
clone_snaps () {
|
||||
local snap; local bsnap
|
||||
if ! sudo mkdir -p $TDIR/$TNAME &>/dev/null; then
|
||||
echo ERROR unable to make directory $TDIR/$TNAME
|
||||
return 1
|
||||
fi
|
||||
echo cloning transfered read only snapshots at $TSNAPS
|
||||
ls -la $TSNAPS
|
||||
echo to $TDIR/$TNAME
|
||||
echo "################"
|
||||
echo cdir: $CDIR, tname: $TNAME
|
||||
latest=$(sudo btrbk -c "$CDIR/$TNAME.conf" list --format col:h:target_subvolume | xargs -I % sh -c 'basename %' | sed '$!N; /^\(.*\)\n\1$/!P; D')
|
||||
echo $latest
|
||||
if [[ $latest ]]; then
|
||||
for snap in $latest; do
|
||||
# dests+=" $(btrbk -c $file list target --format col:h:target_path)"
|
||||
bsnap=$(basename "${snap%.*}")
|
||||
echo cloning $TSNAPS/$snap to $TDIR/$TNAME/$bsnap
|
||||
if [[ -d $TDIR/$TNAME/$bsnap ]]; then
|
||||
echo snapshot $TDIR/$TNAME/$bsnap already exists you must manually remove it if you want to overwrite
|
||||
echo "'sudo btrfs sub del $TDIR/$TNAME/$bsnap' or 'sudo btrfs sub del $TDIR/$TNAME/*'"
|
||||
else
|
||||
sudo btrfs sub snap $TSNAPS/$snap $TDIR/$TNAME/$bsnap
|
||||
echo $TDIR/$TNAME/$bsnap
|
||||
ls -la $TDIR/$TNAME/$bsnap
|
||||
fi
|
||||
done
|
||||
echo $TDIR/$TNAME
|
||||
ls -la $TDIR/$TNAME
|
||||
else
|
||||
echo no transfered snapshots, nothing to clone
|
||||
fi
|
||||
}
|
||||
|
||||
osxfer () {
|
||||
|
||||
local TDIR; local TSNAPS; local SDIR; local CDIR
|
||||
|
||||
efile=$1.env
|
||||
if [[ -f $efile ]]; then
|
||||
module_load confirm
|
||||
echo "#### sourcing $efile ########"
|
||||
source $efile
|
||||
TDIR=${TDIR:-/snapshots/transfer/target}
|
||||
TSNAPS=${TDIR:-/snapshots/transfer/target}/${TSNAPS:-tmp/tsnaps}
|
||||
SDIR=${SDIR:-/snapshots/transfer/source}
|
||||
CDIR=${CDIR:-/snapshots/conf}
|
||||
echo tsnaps: $TSNAPS
|
||||
# TODO make sure minimal environment is set
|
||||
source <(
|
||||
source $efile
|
||||
bash $(module_find btpl) $scripts_dir/os.conf.tmpl
|
||||
) >$CDIR/$TNAME.conf
|
||||
# echo "######### btrbk file: $TNAME.conf ##############"
|
||||
echo "$CDIR/$TNAME.conf"
|
||||
# echo "#######################"
|
||||
# if ! confirm "conf file is ok?"; then exit; fi
|
||||
module_load btrbk btrfs
|
||||
mkdir -p $TDIR &>/dev/null
|
||||
mkdir -p $SDIR &>/dev/null
|
||||
# echo $SDIR
|
||||
# ls -la /snapshots/transfer
|
||||
[[ $TLABEL ]] && sudo mount -L $TLABEL $TDIR
|
||||
[[ $TUUID ]] && sudo mount --UUID=$TUUID $TDIR
|
||||
[[ $TDEV ]] && sudo mount /dev/$TDEV $TDIR
|
||||
if mountpoint $TDIR &>/dev/null; then
|
||||
sudo mkdir -p $TSNAPS
|
||||
echo able to mount $TLABEL $TUUID $TDEV at $TDIR... continuing transfer
|
||||
if ls $TSNAPS/@root.* &>/dev/null; then
|
||||
echo exists
|
||||
if ! confirm a set of transfer snapshots exist at destination, resend?; then
|
||||
clone_snaps
|
||||
return
|
||||
fi
|
||||
fi
|
||||
if btrbk_run $2 "$CDIR/$TNAME.conf"; then
|
||||
echo successful transfer from $SMP/$SNAME to $TLABEL $TUUID $TDEV - $TSNAPS
|
||||
sudo btrbk -c "$CDIR/$TNAME.conf" list latest
|
||||
echo "########################"
|
||||
clone_snaps
|
||||
else
|
||||
echo ERROR: snapshot transfer to $TLABEL $TUUID $TDEV - $TSNAPS failed
|
||||
fi
|
||||
echo deleting temporary transfer snapshots at $SDIR
|
||||
sudo btrfs sub del $SDIR/*
|
||||
sudo rm -rf $SDIR
|
||||
# echo deleting temporary transfer snapshots at $TSNAPS
|
||||
# sudo btrfs sub del $TSNAPS/*
|
||||
# sudo rm -rf $TSNAPS
|
||||
echo unmounting $TDIR
|
||||
if sudo umount -R $TDIR; then
|
||||
if ! confirm "remove local mount directory $TDIR?"; then exit; fi
|
||||
sudo rm -f $TDIR
|
||||
else
|
||||
echo WARNING: not able to unmount $TDIR
|
||||
fi
|
||||
else
|
||||
echo unable to mount $TLABEL $TUUID $TDEV at $TDIR
|
||||
fi
|
||||
else
|
||||
echo environment file $efile does not exisit
|
||||
fi
|
||||
|
||||
}
|
Loading…
Reference in New Issue