deploy
This commit is contained in:
parent
351b3e16fa
commit
20fed1d457
4 changed files with 108 additions and 82 deletions
|
|
@ -36,7 +36,7 @@ get_log_info() {
|
|||
while [ $(($(date +%s) - START_TIME)) -lt $MAX_WAIT_TIME ]; do
|
||||
current_lines=$(wc -l < "$latest_unlocker_log")
|
||||
if [ $current_lines -gt $initial_lines ]; then
|
||||
latest_entry=$(tail -n $((current_lines - initial_lines)) "$latest_unlocker_log" | grep "unlocker >>" | tail -n 1)
|
||||
latest_entry=$(tail -n $((current_lines - initial_lines)) "$latest_unlocker_log" | grep -E "unlocker >> (the wallet is already unlocked|created wallet with pub|unlocked wallet with pub)" | tail -n 1)
|
||||
if [ -n "$latest_entry" ]; then
|
||||
break
|
||||
fi
|
||||
|
|
@ -49,7 +49,17 @@ get_log_info() {
|
|||
exit 1
|
||||
fi
|
||||
|
||||
log "Wallet status: $(echo "$latest_entry" | cut -d' ' -f4-)"
|
||||
if [[ "$latest_entry" == *"the wallet is already unlocked"* ]]; then
|
||||
log "Wallet status: The wallet is already unlocked"
|
||||
elif [[ "$latest_entry" == *"created wallet with pub"* ]]; then
|
||||
log "Wallet status: A new wallet has been created"
|
||||
elif [[ "$latest_entry" == *"unlocking"* ]]; then
|
||||
log "Wallet status: The wallet is in the process of unlocking"
|
||||
elif [[ "$latest_entry" == *"unlocked wallet with pub"* ]]; then
|
||||
log "Wallet status: The wallet has been successfully unlocked"
|
||||
else
|
||||
log "Wallet status: Unknown (unexpected status message)"
|
||||
fi
|
||||
|
||||
log "Retrieving connection information..."
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Function to log errors
|
||||
log_error() {
|
||||
log "ERROR: $1"
|
||||
log "Exiting with status $2"
|
||||
|
|
@ -33,8 +32,22 @@ detect_os_arch
|
|||
if [ "$OS" = "Mac" ]; then
|
||||
handle_macos
|
||||
else
|
||||
install_lnd || log_error "LND installation failed" $?
|
||||
lnd_upgrade_status=$?
|
||||
lnd_output=$(install_lnd)
|
||||
install_result=$?
|
||||
|
||||
if [ $install_result -ne 0 ]; then
|
||||
log_error "LND installation failed" $install_result
|
||||
fi
|
||||
|
||||
# Extract the LND status from the output
|
||||
lnd_status=$(echo "$lnd_output" | grep "LND_STATUS:" | cut -d':' -f2)
|
||||
|
||||
case $lnd_status in
|
||||
0) log "LND fresh installation completed successfully." ;;
|
||||
1) log "LND upgrade completed successfully." ;;
|
||||
2) log "LND is already up-to-date. No action needed." ;;
|
||||
*) log "WARNING: Unexpected status from install_lnd: $lnd_status" ;;
|
||||
esac
|
||||
|
||||
install_nodejs || log_error "NodeJS installation failed" $?
|
||||
|
||||
|
|
@ -57,7 +70,8 @@ else
|
|||
log "Full output: $pub_output"
|
||||
fi
|
||||
|
||||
start_services $lnd_upgrade_status $pub_upgrade_status
|
||||
log "Starting services..."
|
||||
start_services $lnd_status $pub_upgrade_status
|
||||
get_log_info
|
||||
|
||||
log "Installation process completed successfully"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#!/bin/bash
|
||||
|
||||
install_lnd() {
|
||||
local lnd_status=0
|
||||
|
||||
log "Starting LND installation/check process..."
|
||||
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
USER_HOME=$(getent passwd ${SUDO_USER} | cut -d: -f6)
|
||||
USER_NAME=$SUDO_USER
|
||||
|
|
@ -9,35 +13,44 @@ install_lnd() {
|
|||
USER_NAME=$(whoami)
|
||||
fi
|
||||
|
||||
log "Checking latest LND version..."
|
||||
LND_VERSION=$(wget -qO- https://api.github.com/repos/lightningnetwork/lnd/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')
|
||||
log "Latest LND version: $LND_VERSION"
|
||||
|
||||
LND_URL="https://github.com/lightningnetwork/lnd/releases/download/${LND_VERSION}/lnd-${OS}-${ARCH}-${LND_VERSION}.tar.gz"
|
||||
|
||||
# Check if LND is already installed
|
||||
if [ -d "$USER_HOME/lnd" ]; then
|
||||
log "LND directory found. Checking current version..."
|
||||
CURRENT_VERSION=$("$USER_HOME/lnd/lnd" --version | grep -oP 'version \K[^\s]+')
|
||||
log "Current LND version: $CURRENT_VERSION"
|
||||
|
||||
if [ "$CURRENT_VERSION" == "${LND_VERSION#v}" ]; then
|
||||
log "${SECONDARY_COLOR}LND${RESET_COLOR} is already up-to-date (version $CURRENT_VERSION)."
|
||||
return 0
|
||||
lnd_status=2 # Set status to 2 to indicate no action needed
|
||||
else
|
||||
if [ "$SKIP_PROMPT" != true ]; then
|
||||
read -p "LND version $CURRENT_VERSION is installed. Do you want to upgrade to version $LND_VERSION? (y/N): " response
|
||||
case "$response" in
|
||||
[yY][eE][sS]|[yY])
|
||||
log "${PRIMARY_COLOR}Upgrading${RESET_COLOR} ${SECONDARY_COLOR}LND${RESET_COLOR} from version $CURRENT_VERSION to $LND_VERSION..."
|
||||
PERFORM_UPGRADE=true
|
||||
lnd_status=1 # Set status to 1 to indicate upgrade
|
||||
;;
|
||||
*)
|
||||
log "$(date '+%Y-%m-%d %H:%M:%S') Upgrade cancelled."
|
||||
return 0
|
||||
lnd_status=2 # Set status to 2 to indicate no action needed
|
||||
;;
|
||||
esac
|
||||
else
|
||||
log "${PRIMARY_COLOR}Upgrading${RESET_COLOR} ${SECONDARY_COLOR}LND${RESET_COLOR} from version $CURRENT_VERSION to $LND_VERSION..."
|
||||
PERFORM_UPGRADE=true
|
||||
lnd_status=1 # Set status to 1 to indicate upgrade
|
||||
fi
|
||||
fi
|
||||
else
|
||||
log "LND not found. Proceeding with fresh installation..."
|
||||
fi
|
||||
|
||||
if [ $lnd_status -eq 0 ] || [ $lnd_status -eq 1 ]; then
|
||||
log "${PRIMARY_COLOR}Downloading${RESET_COLOR} ${SECONDARY_COLOR}LND${RESET_COLOR}..."
|
||||
|
||||
# Start the download
|
||||
|
|
@ -79,11 +92,10 @@ EOF"
|
|||
fi
|
||||
|
||||
log "${SECONDARY_COLOR}LND${RESET_COLOR} installation and configuration completed."
|
||||
|
||||
# Return 1 if it was an upgrade, 0 otherwise
|
||||
if [ "$PERFORM_UPGRADE" = true ]; then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
|
||||
log "LND installation/check process complete. Status: $lnd_status"
|
||||
# Echo the LND status
|
||||
echo "LND_STATUS:$lnd_status"
|
||||
return 0 # Always return 0 to indicate success
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
start_services() {
|
||||
LND_UPGRADE=$1
|
||||
LND_STATUS=$1
|
||||
PUB_UPGRADE=$2
|
||||
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
|
|
@ -47,55 +47,45 @@ EOF"
|
|||
sudo systemctl enable lnd >/dev/null 2>&1
|
||||
sudo systemctl enable lightning_pub >/dev/null 2>&1
|
||||
|
||||
if [ "$LND_UPGRADE" = "1" ]; then
|
||||
log "${PRIMARY_COLOR}Restarting${RESET_COLOR} ${SECONDARY_COLOR}LND${RESET_COLOR} service..."
|
||||
sudo systemctl restart lnd &
|
||||
lnd_pid=$!
|
||||
wait $lnd_pid
|
||||
# Always attempt to start or restart LND
|
||||
if systemctl is-active --quiet lnd; then
|
||||
log "LND restarted successfully using systemd."
|
||||
if [ "$LND_STATUS" = "1" ]; then
|
||||
log "${PRIMARY_COLOR}Restarting${RESET_COLOR} ${SECONDARY_COLOR}LND${RESET_COLOR} service..."
|
||||
sudo systemctl restart lnd
|
||||
else
|
||||
log "Failed to restart ${SECONDARY_COLOR}LND${RESET_COLOR} using systemd."
|
||||
exit 1
|
||||
log "${SECONDARY_COLOR}LND${RESET_COLOR} service is already running."
|
||||
fi
|
||||
else
|
||||
log "${PRIMARY_COLOR}Starting${RESET_COLOR} ${SECONDARY_COLOR}LND${RESET_COLOR} service..."
|
||||
sudo systemctl start lnd &
|
||||
lnd_pid=$!
|
||||
wait $lnd_pid
|
||||
if systemctl is-active --quiet lnd; then
|
||||
log "LND started successfully using systemd."
|
||||
else
|
||||
log "Failed to start ${SECONDARY_COLOR}LND${RESET_COLOR} using systemd."
|
||||
exit 1
|
||||
sudo systemctl start lnd
|
||||
fi
|
||||
|
||||
# Check LND status after attempting to start/restart
|
||||
if ! systemctl is-active --quiet lnd; then
|
||||
log "Failed to start or restart ${SECONDARY_COLOR}LND${RESET_COLOR}. Please check the logs."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "Giving ${SECONDARY_COLOR}LND${RESET_COLOR} a few seconds to start before starting ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR}..."
|
||||
sleep 10
|
||||
|
||||
# Always attempt to start or restart Lightning.Pub
|
||||
if systemctl is-active --quiet lightning_pub; then
|
||||
if [ "$PUB_UPGRADE" = "100" ]; then
|
||||
log "${PRIMARY_COLOR}Restarting${RESET_COLOR} ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} service..."
|
||||
sudo systemctl restart lightning_pub &
|
||||
lightning_pub_pid=$!
|
||||
wait $lightning_pub_pid
|
||||
if systemctl is-active --quiet lightning_pub; then
|
||||
log "Lightning.Pub restarted successfully using systemd."
|
||||
sudo systemctl restart lightning_pub
|
||||
else
|
||||
log "Failed to restart ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} using systemd."
|
||||
exit 1
|
||||
log "${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} service is already running."
|
||||
fi
|
||||
else
|
||||
log "${PRIMARY_COLOR}Starting${RESET_COLOR} ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} service..."
|
||||
sudo systemctl start lightning_pub &
|
||||
lightning_pub_pid=$!
|
||||
wait $lightning_pub_pid
|
||||
if systemctl is-active --quiet lightning_pub; then
|
||||
log "Lightning.Pub started successfully using systemd."
|
||||
else
|
||||
log "Failed to start ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR} using systemd."
|
||||
exit 1
|
||||
sudo systemctl start lightning_pub
|
||||
fi
|
||||
|
||||
# Check Lightning.Pub status after attempting to start/restart
|
||||
if ! systemctl is-active --quiet lightning_pub; then
|
||||
log "Failed to start or restart ${SECONDARY_COLOR}Lightning.Pub${RESET_COLOR}. Please check the logs."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue