1
1
Fork 1

Various DDNS updates.

Signed-off-by: Derek Smith <derek@farscapian.com>
This commit is contained in:
Derek Smith 2022-04-22 16:15:40 -04:00
parent e5a22e8dc4
commit 7ab9b4c482
Signed by: farscapian
GPG Key ID: 8F1CD799CCA516CC
4 changed files with 52 additions and 31 deletions

View File

@ -102,6 +102,15 @@ export MACVLAN_INTERFACE="$MACVLAN_INTERFACE"
# shellcheck disable=SC1091
source ./defaults.sh
# if there's a ./env file here, let's execute it. Admins can put various deployment-specific things there.
if [ -f $(pwd)/env ]; then
source $(pwd)/env;
else
touch "$(pwd)/env"
echo "We stubbed out a '$(pwd)/env' file for you. Put any LXD-remote specific information in there."
exit 1
fi
# iterate over all our server endpoints and provision them if needed.
# www
VPS_HOSTNAME=

View File

@ -35,7 +35,6 @@ if [ "$VPS_HOSTING_TARGET" != lxd ]; then
./generate_certs.sh
fi
else
# restore the certs. If they don't exist in a backup we restore from SITE_PATH
if [ -f "$SITE_PATH/certs.tar.gz" ]; then
scp "$SITE_PATH/certs.tar.gz" "ubuntu@$FQDN:$REMOTE_HOME/certs.tar.gz"

View File

@ -1,10 +1,10 @@
#!/bin/bash
set -eu
set -eux
# check to ensure the admin has specified a MACVLAN interface
if [ -z "$DEV_MACVLAN_INTERFACE" ]; then
echo "ERROR: DEV_MACVLAN_INTERFACE not defined in project."
if [ -z "$MACVLAN_INTERFACE" ]; then
echo "ERROR: MACVLAN_INTERFACE not defined in project."
exit 1
fi
@ -26,12 +26,13 @@ envsubst < ./lxc_profile.yml > "$SITE_PATH/cloud-init.yml"
# configure the profile with our generated cloud-init.yml file.
cat "$SITE_PATH/cloud-init.yml" | lxc profile edit "$LXD_VM_NAME"
wait_for_lxc_ip () {
function wait_for_lxc_ip {
LXC_INSTANCE_NAME="$1"
IP_V4_ADDRESS=
while true; do
IP_V4_ADDRESS="$(lxc list "$LXC_INSTANCE_NAME" --format csv --columns=4 | grep enp5s0 | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')" || true
export IP_V4_ADDRESS="$IP_V4_ADDRESS"
if [ -n "$IP_V4_ADDRESS" ]; then
# give the machine extra time to spin up.
wait-for-it -t 300 "$IP_V4_ADDRESS:22"
@ -44,6 +45,34 @@ done
}
function run_ddns {
# now that the VM has an IP, we can update the DNS record. TODO add additional DNS providers here; namecheap only atm.
DDNS_STRING="$VPS_HOSTNAME"
if [ "$VPS_HOSTNAME" = www ]; then
# next update our DDNS record. TODO enable local/remote name provider.
DDNS_STRING="@"
fi
# if the DNS record is incorrect, we run DDNS to get it corrected yo.
if "$(getent hosts "$FQDN" | awk '{ print $1 }')" != "$IP_V4_ADDRESS"; then
curl "https://dynamicdns.park-your-domain.com/update?host=$DDNS_STRING&domain=$DOMAIN_NAME&password=$DDNS_PASSWORD&ip=$IP_V4_ADDRESS"
DDNS_SLEEP_SECONDS=60
while true; do
# we test the www CNAME here so we can be assured the underlying has corrected.
if [[ "$(getent hosts "$FQDN" | awk '{ print $1 }')" == "$IP_V4_ADDRESS" ]]; then
echo ""
echo "SUCCESS: The DNS appears to be configured correctly."
echo "INFO: Waiting $DDNS_SLEEP_SECONDS seconds to allow stale DNS records to expire."
sleep "$DDNS_SLEEP_SECONDS";
break;
fi
printf "." && sleep 2;
done
fi
}
# create the default storage pool if necessary
if ! lxc storage list --format csv | grep -q default; then

View File

@ -1,18 +1,8 @@
#!/bin/bash
set -eu
set -eux
# create the ddclient.conf file
cat >/tmp/ddclient.conf <<EOL
### ddclient.conf
### namecheap
##################
use=web, web=checkip.dyndns.com/, web-skip='IP Address'
protocol=namecheap
server=dynamicdns.park-your-domain.com
login=${DOMAIN_NAME}
password=${DDNS_PASSWORD}
EOL
DDNS_STRING=
# for the www stack, we register only the domain name so our URLs look like https://$DOMAIN_NAME
if [ "$APP_TO_DEPLOY" = www ] || [ "$APP_TO_DEPLOY" = certonly ]; then
@ -21,22 +11,16 @@ else
DDNS_STRING="$DDNS_HOST"
fi
# append the correct DDNS string to ddclient.conf
echo "$DDNS_STRING" >> /tmp/ddclient.conf
cat /tmp/ddclient.conf
# send the ddclient.conf file to the remote vps.
docker-machine scp /tmp/ddclient.conf "$FQDN:$REMOTE_HOME/ddclient.conf"
docker-machine ssh "$FQDN" sudo cp "$REMOTE_HOME/ddclient.conf" /etc/ddclient.conf
docker-machine ssh "$FQDN" sudo chown root:root /etc/ddclient.conf
docker-machine ssh "$FQDN" sudo chmod 0600 /etc/ddclient.conf
docker-machine ssh "$FQDN" sudo apt-get -qq install -y ddclient wait-for-it git rsync duplicity sshfs
docker-machine ssh "$FQDN" sudo ddclient
# wait for DNS to get setup. Pass in the IP address of the actual VPS.
echo "INFO: Verifying correct DNS configuration. This may take a while."
MACHINE_IP="$(docker-machine ip "$FQDN")"
if [ "$VPS_HOSTING_TARGET" = aws ]; then
# wire DNS entries using namecheap DDNS API (via HTTPS rather than ddclient)
curl "https://dynamicdns.park-your-domain.com/update?host=$DDNS_STRING&domain=$DOMAIN_NAME&password=$DDNS_PASSWORD&ip=$MACHINE_IP"
#install dependencies.
docker-machine ssh "$FQDN" sudo apt-get -qq install -y wait-for-it git rsync duplicity sshfs
fi
DDNS_SLEEP_SECONDS=60
while true; do