#!/bin/bash

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source $SCRIPT_DIR/_common.sh

# Get instance config or exit if not ready yet
_get_config

# Get ssh public keys:
SSH_KEYS_URL=$(jq -r '.sshKeysUrl // ""' $LAYEROPS_CONFIG_FILE)
[ -z "$SSH_KEYS_URL" ] || curl -H "User-Agent: NimeOps-UA" $SSH_KEYS_URL >> /home/layerops/.ssh/authorized_keys

# Init Wireguard interface
/etc/layerops/scripts/01-wireguard.sh

# Restart consul template services
systemctl restart consul-template-wg

{% if layerops_instance_type == "load_balancer" %}
# Workaround for LB: force restart nomad to be sure job "load-balancer" is redeployed
systemctl restart nomad

{% endif %}

{% if layerops_instance_type == "client" %}

systemctl restart consul-template-nomad-tags

{% endif %}
