Skip to content

Commit

Permalink
MITHRIL_HOME to allow custom paths outside of CNODE_HOME
Browse files Browse the repository at this point in the history
  • Loading branch information
TrevorBenson committed Aug 7, 2024
1 parent 39d6192 commit e42b5f9
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
2 changes: 2 additions & 0 deletions scripts/cnode-helper-scripts/env
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
#CIP0094_POLL_URL="https://raw.githubusercontent.com/cardano-foundation/CIP-0094-polls/main/networks/polls.json" # URL for polls to vote against

#MITHRIL_DOWNLOAD="N" # (Y|N) Download latest Mithril snapshot
#MITHRIL_HOME="${CNODE_HOME}/mithril" # Override default Mithril path
#MITHRIL_SIGNER_ENABLED="N" # (Y|N) Enable the gLiveView Mithril Signer Section

#STRICT_VERSION_CHECK="Y" # (Y|N) Restrict operation to supported major.minor version leaving patch version open. If disabled, any version will be accepted (unsupported)
Expand Down Expand Up @@ -950,6 +951,7 @@ set_default_vars() {
[[ -z ${ASSET_POLICY_ID_FILENAME} ]] && ASSET_POLICY_ID_FILENAME="policy.id"
[[ -z ${CIP0094_POLL_URL} ]] && CIP0094_POLL_URL="https://raw.githubusercontent.com/cardano-foundation/CIP-0094-polls/main/networks/polls.json"
[[ -z ${MITHRIL_DOWNLOAD} ]] && MITHRIL_DOWNLOAD="N"
[[ -z ${MITHRIL_HOME} ]] && MITHRIL_HOME="${CNODE_HOME}/mithril"
[[ -z ${MITHRIL_SIGNER_ENABLED} ]] && MITHRIL_SIGNER_ENABLED="N"
[[ -z ${STRICT_VERSION_CHECK} ]] && STRICT_VERSION_CHECK="Y"
FG_BLACK='\e[30m'
Expand Down
4 changes: 2 additions & 2 deletions scripts/cnode-helper-scripts/gLiveView.sh
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,8 @@ unset cpu_now cpu_last

mithrilSignerVars() {
# mithril.env sourcing needed to have values in ${METRICS_SERVER_IP} and ${METRICS_SERVER_PORT}
. ${CNODE_HOME}/mithril/mithril.env
signerMetricsEnabled=$(grep -q "ENABLE_METRICS_SERVER=true" ${CNODE_HOME}/mithril/mithril.env && echo "true" || echo "false")
. ${MITHRIL_HOME}/mithril.env
signerMetricsEnabled=$(grep -q "ENABLE_METRICS_SERVER=true" ${MITHRIL_HOME}/mithril.env && echo "true" || echo "false")
if [[ "${signerMetricsEnabled}" == "true" ]] ; then
mithrilSignerMetrics=$(curl -s "http://${METRICS_SERVER_IP}:${METRICS_SERVER_PORT}/metrics" 2>/dev/null | grep -v -E "HELP|TYPE" | sed 's/mithril_signer_//g')
SIGNER_METRICS_HTTP_RESPONSE=$(curl --write-out "%{http_code}" --silent --output /dev/null --connect-timeout 2 http://${METRICS_SERVER_IP}:${METRICS_SERVER_PORT}/metrics)
Expand Down
2 changes: 1 addition & 1 deletion scripts/cnode-helper-scripts/guild-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ setup_folder() {
echo -e "\nexport ${CNODE_VNAME}_HOME=${CNODE_HOME}" >> "${HOME}"/.bashrc
fi

$sudo mkdir -p "${CNODE_HOME}"/files "${CNODE_HOME}"/db "${CNODE_HOME}"/guild-db "${CNODE_HOME}"/logs "${CNODE_HOME}"/scripts "${CNODE_HOME}"/scripts/archive "${CNODE_HOME}"/sockets "${CNODE_HOME}"/priv "${CNODE_HOME}"/mithril/data-stores
$sudo mkdir -p "${CNODE_HOME}"/files "${CNODE_HOME}"/db "${CNODE_HOME}"/guild-db "${CNODE_HOME}"/logs "${CNODE_HOME}"/scripts "${CNODE_HOME}"/scripts/archive "${CNODE_HOME}"/sockets "${CNODE_HOME}"/priv "${MITHRIL_HOME}"/data-stores
$sudo chown -R "$U_ID":"$G_ID" "${CNODE_HOME}" 2>/dev/null

}
Expand Down
4 changes: 2 additions & 2 deletions scripts/cnode-helper-scripts/mithril-client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ SKIP_UPDATE=N
environment_override() {
local var_to_override="$1"
local new_value="$2"
local env_file="${CNODE_HOME}/mithril/mithril.env"
local env_file="${MITHRIL_HOME}/mithril.env"

# Check if the variable exists in the environment file
if ! grep -q "^${var_to_override}=" "$env_file"; then
Expand Down Expand Up @@ -150,7 +150,7 @@ show_snapshot() {
download_stake_distribution() {
if [[ "${DOWNLOAD_STAKE_DISTRIBUTION}" == "Y" ]]; then
echo "INFO: Downloading latest mithril stake distribution.."
"${MITHRILBIN}" -v --aggregator-endpoint ${AGGREGATOR_ENDPOINT} mithril-stake-distribution download --download-dir "${CNODE_HOME}/mithril/" ${STAKE_DISTRIBUTION_DIGEST}
"${MITHRILBIN}" -v --aggregator-endpoint ${AGGREGATOR_ENDPOINT} mithril-stake-distribution download --download-dir "${MITHRIL_HOME}/" ${STAKE_DISTRIBUTION_DIGEST}
else
echo "INFO: Skipping stake distribution download.."
fi
Expand Down
5 changes: 3 additions & 2 deletions scripts/cnode-helper-scripts/mithril-signer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ deploy_systemd() {
Restart=always
RestartSec=60
User=${USER}
EnvironmentFile=${CNODE_HOME}/mithril/mithril.env
EnvironmentFile=${MITHRIL_HOME}/mithril.env
ExecStart=/bin/bash -l -c \"exec ${HOME}/.local/bin/$(basename "${0::-3}") -vv\"
KillSignal=SIGINT
SuccessExitStatus=143
Expand Down Expand Up @@ -239,9 +239,10 @@ else
echo "Starting Mithril Signer Server.."
trap 'user_interrupt_received' INT

if grep -q "ENABLE_METRICS_SERVER=true" ${CNODE_HOME}/mithril/mithril.env; then
if grep -q "ENABLE_METRICS_SERVER=true" ${MITHRIL_HOME}/mithril.env; then
METRICS_SERVER_PARAMS="--enable-metrics-server --metrics-server-ip ${METRICS_SERVER_IP} --metrics-server-port ${METRICS_SERVER_PORT}"
# If ENABLE_METRICS_SERVER is true, then an environment update will enable gLiveView automatically.
# shellcheck disable=SC2154
sudo sed -i 's/#MITHRIL_SIGNER_ENABLED="[YN]"/MITHRIL_SIGNER_ENABLED="Y"/' ${CNODE_HOME}/scripts/env
if ! "${MITHRILBIN}" ${METRICS_SERVER_PARAMS} -vv | tee -a "${LOG_DIR}/$(basename "${0::-3}")".log 2>&1 ; then
echo "Failed to start Mithril Signer Server with metrics enabled" | tee -a "${LOG_DIR}/$(basename "${0::-3}")".log 2>&1
Expand Down
18 changes: 9 additions & 9 deletions scripts/cnode-helper-scripts/mithril.library
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ set_defaults() {
}

create_data_stores_directory() {
if [[ ! -d "${CNODE_HOME}/mithril/data-stores" ]]; then
if [[ ! -d "${MITHRIL_HOME}/data-stores" ]]; then
sudo mkdir -p "${CNODE_HOME}"/mithril/data-stores
sudo chown -R "$U_ID":"$G_ID" "${CNODE_HOME}"/mithril 2>/dev/null
fi
Expand All @@ -111,7 +111,7 @@ set_env_file_ownership() {


check_mithril_environment_file_exists() {
local env_file="${CNODE_HOME}/mithril/mithril.env"
local env_file="${MITHRIL_HOME}/mithril.env"

if [[ -f "$env_file" ]]; then
if [[ "$UPDATE_ENVIRONMENT" != "Y" ]]; then
Expand Down Expand Up @@ -165,7 +165,7 @@ update_mithril_environment_for_signer() {
# Generate the full set of environment variables required by Mithril signer use case
export ERA_READER_ADDRESS=https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/${RELEASE}-${NETWORK_NAME,,}/era.addr
export ERA_READER_VKEY=https://raw.githubusercontent.com/input-output-hk/mithril/main/mithril-infra/configuration/${RELEASE}-${NETWORK_NAME,,}/era.vkey
sudo bash -c "cat <<-'EOF' > ${CNODE_HOME}/mithril/mithril.env
sudo bash -c "cat <<-'EOF' > ${MITHRIL_HOME}/mithril.env
KES_SECRET_KEY_PATH=${POOL_DIR}/${POOL_HOTKEY_SK_FILENAME}
OPERATIONAL_CERTIFICATE_PATH=${POOL_DIR}/${POOL_OPCERT_FILENAME}
NETWORK=${NETWORK_NAME,,}
Expand All @@ -175,7 +175,7 @@ update_mithril_environment_for_signer() {
DB_DIRECTORY=${DB_DIR}
CARDANO_NODE_SOCKET_PATH=${CARDANO_NODE_SOCKET_PATH}
CARDANO_CLI_PATH=${HOME}/.local/bin/cardano-cli
DATA_STORES_DIRECTORY=${CNODE_HOME}/mithril/data-stores
DATA_STORES_DIRECTORY=${MITHRIL_HOME}/data-stores
STORE_RETENTION_LIMITS=5
ERA_READER_ADAPTER_TYPE=cardano-chain
ERA_READER_ADAPTER_PARAMS=$(jq -nc --arg address "$(wget -q -O - "${ERA_READER_ADDRESS}")" --arg verification_key "$(wget -q -O - "${ERA_READER_VKEY}")" '{"address": $address, "verification_key": $verification_key}')
Expand All @@ -185,20 +185,20 @@ update_mithril_environment_for_signer() {
EOF"

if [[ "${ENABLE_RELAY_ENDPOINT}" == "y" ]]; then
sudo bash -c "echo RELAY_ENDPOINT=http://${RELAY_ENDPOINT_IP}:${RELAY_PORT} >> ${CNODE_HOME}/mithril/mithril.env"
sudo bash -c "echo RELAY_ENDPOINT=http://${RELAY_ENDPOINT_IP}:${RELAY_PORT} >> ${MITHRIL_HOME}/mithril.env"
fi

if [[ "${ENABLE_MITHRIL_METRICS}" == "y" ]]; then
sudo bash -c "echo ENABLE_METRICS_SERVER=true >> ${CNODE_HOME}/mithril/mithril.env"
sudo bash -c "echo METRICS_SERVER_IP=${METRICS_SERVER_IP} >> ${CNODE_HOME}/mithril/mithril.env"
sudo bash -c "echo METRICS_SERVER_PORT=${METRICS_SERVER_PORT} >> ${CNODE_HOME}/mithril/mithril.env"
sudo bash -c "echo ENABLE_METRICS_SERVER=true >> ${MITHRIL_HOME}/mithril.env"
sudo bash -c "echo METRICS_SERVER_IP=${METRICS_SERVER_IP} >> ${MITHRIL_HOME}/mithril.env"
sudo bash -c "echo METRICS_SERVER_PORT=${METRICS_SERVER_PORT} >> ${MITHRIL_HOME}/mithril.env"
fi

}

update_mithril_environment_for_client() {
echo "Info: Setting minimal environment variables supporting only the Mithril client use case."
bash -c "cat <<-'EOF' > ${CNODE_HOME}/mithril/mithril.env
bash -c "cat <<-'EOF' > ${MITHRIL_HOME}/mithril.env
NETWORK=${NETWORK_NAME,,}
RELEASE=${RELEASE}
AGGREGATOR_ENDPOINT=https://aggregator.${RELEASE}-${NETWORK_NAME,,}.api.mithril.network/aggregator
Expand Down

0 comments on commit e42b5f9

Please sign in to comment.