dont overwrite units
This commit is contained in:
parent
343b730624
commit
845e180a66
2 changed files with 44 additions and 44 deletions
|
|
@ -76,33 +76,6 @@ install_lightning_pub() {
|
||||||
|
|
||||||
mv "$EXTRACT_DIR" "$INSTALL_DIR"
|
mv "$EXTRACT_DIR" "$INSTALL_DIR"
|
||||||
|
|
||||||
log "Restoring user data..."
|
|
||||||
cp "$BACKUP_DIR"/*.sqlite "$INSTALL_DIR/" 2>/dev/null || true
|
|
||||||
cp "$BACKUP_DIR"/.env "$INSTALL_DIR/" 2>/dev/null || true
|
|
||||||
cp -r "$BACKUP_DIR"/logs "$INSTALL_DIR/" 2>/dev/null || true
|
|
||||||
cp -r "$BACKUP_DIR"/metric_cache "$INSTALL_DIR/" 2>/dev/null || true
|
|
||||||
cp "$BACKUP_DIR"/.jwt_secret "$INSTALL_DIR/" 2>/dev/null || true
|
|
||||||
cp "$BACKUP_DIR"/.wallet_secret "$INSTALL_DIR/" 2>/dev/null || true
|
|
||||||
cp "$BACKUP_DIR"/.installed_commit "$INSTALL_DIR/" 2>/dev/null || true
|
|
||||||
cp "$BACKUP_DIR"/admin.npub "$INSTALL_DIR/" 2>/dev/null || true
|
|
||||||
cp "$BACKUP_DIR"/app.nprofile "$INSTALL_DIR/" 2>/dev/null || true
|
|
||||||
cp "$BACKUP_DIR"/admin.connect "$INSTALL_DIR/" 2>/dev/null || true
|
|
||||||
cp "$BACKUP_DIR"/admin.enroll "$INSTALL_DIR/" 2>/dev/null || true
|
|
||||||
|
|
||||||
# Ensure correct ownership post-restore (fixes potential mismatches)
|
|
||||||
chown -R "$USER_NAME:$USER_NAME" "$INSTALL_DIR/" 2>/dev/null || true
|
|
||||||
# Secure DB files (as before)
|
|
||||||
chmod 600 "$INSTALL_DIR/db.sqlite" 2>/dev/null || true
|
|
||||||
chmod 600 "$INSTALL_DIR/metrics.sqlite" 2>/dev/null || true
|
|
||||||
chmod 600 "$INSTALL_DIR/.jwt_secret" 2>/dev/null || true
|
|
||||||
chmod 600 "$INSTALL_DIR/.wallet_secret" 2>/dev/null || true
|
|
||||||
chmod 600 "$INSTALL_DIR/admin.connect" 2>/dev/null || true
|
|
||||||
chmod 600 "$INSTALL_DIR/admin.enroll" 2>/dev/null || true
|
|
||||||
# Ensure log/metric dirs are writable (dirs need execute for traversal)
|
|
||||||
chmod 755 "$INSTALL_DIR/logs" 2>/dev/null || true
|
|
||||||
chmod 755 "$INSTALL_DIR/logs/"*/ 2>/dev/null || true # Subdirs like apps/
|
|
||||||
chmod 755 "$INSTALL_DIR/metric_cache" 2>/dev/null || true
|
|
||||||
|
|
||||||
elif [ -d "$INSTALL_DIR" ]; then
|
elif [ -d "$INSTALL_DIR" ]; then
|
||||||
# --- CONFLICT/UNSAFE PATH ---
|
# --- CONFLICT/UNSAFE PATH ---
|
||||||
# This handles the case where the directory exists but is not a valid install (e.g., a git clone).
|
# This handles the case where the directory exists but is not a valid install (e.g., a git clone).
|
||||||
|
|
@ -149,6 +122,34 @@ install_lightning_pub() {
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Restore user data AFTER successful NPM install
|
||||||
|
log "Restoring user data..."
|
||||||
|
cp "$BACKUP_DIR"/*.sqlite "$INSTALL_DIR/" 2>/dev/null || true
|
||||||
|
cp "$BACKUP_DIR"/.env "$INSTALL_DIR/" 2>/dev/null || true
|
||||||
|
cp -r "$BACKUP_DIR"/logs "$INSTALL_DIR/" 2>/dev/null || true
|
||||||
|
cp -r "$BACKUP_DIR"/metric_cache "$INSTALL_DIR/" 2>/dev/null || true
|
||||||
|
cp "$BACKUP_DIR"/.jwt_secret "$INSTALL_DIR/" 2>/dev/null || true
|
||||||
|
cp "$BACKUP_DIR"/.wallet_secret "$INSTALL_DIR/" 2>/dev/null || true
|
||||||
|
cp "$BACKUP_DIR"/.installed_commit "$INSTALL_DIR/" 2>/dev/null || true
|
||||||
|
cp "$BACKUP_DIR"/admin.npub "$INSTALL_DIR/" 2>/dev/null || true
|
||||||
|
cp "$BACKUP_DIR"/app.nprofile "$INSTALL_DIR/" 2>/dev/null || true
|
||||||
|
cp "$BACKUP_DIR"/admin.connect "$INSTALL_DIR/" 2>/dev/null || true
|
||||||
|
cp "$BACKUP_DIR"/admin.enroll "$INSTALL_DIR/" 2>/dev/null || true
|
||||||
|
|
||||||
|
# Ensure correct ownership post-restore (fixes potential mismatches)
|
||||||
|
chown -R "$USER_NAME:$USER_NAME" "$INSTALL_DIR/" 2>/dev/null || true
|
||||||
|
# Secure DB files (as before)
|
||||||
|
chmod 600 "$INSTALL_DIR/db.sqlite" 2>/dev/null || true
|
||||||
|
chmod 600 "$INSTALL_DIR/metrics.sqlite" 2>/dev/null || true
|
||||||
|
chmod 600 "$INSTALL_DIR/.jwt_secret" 2>/dev/null || true
|
||||||
|
chmod 600 "$INSTALL_DIR/.wallet_secret" 2>/dev/null || true
|
||||||
|
chmod 600 "$INSTALL_DIR/admin.connect" 2>/dev/null || true
|
||||||
|
chmod 600 "$INSTALL_DIR/admin.enroll" 2>/dev/null || true
|
||||||
|
# Ensure log/metric dirs are writable (dirs need execute for traversal)
|
||||||
|
chmod 755 "$INSTALL_DIR/logs" 2>/dev/null || true
|
||||||
|
chmod 755 "$INSTALL_DIR/logs/"*/ 2>/dev/null || true # Subdirs like apps/
|
||||||
|
chmod 755 "$INSTALL_DIR/metric_cache" 2>/dev/null || true
|
||||||
|
|
||||||
# Store the commit hash for future update checks
|
# Store the commit hash for future update checks
|
||||||
# Note: LATEST_COMMIT will be empty on a fresh install, which is fine.
|
# Note: LATEST_COMMIT will be empty on a fresh install, which is fine.
|
||||||
# The file will be created, and the next run will be an upgrade.
|
# The file will be created, and the next run will be an upgrade.
|
||||||
|
|
@ -158,7 +159,7 @@ install_lightning_pub() {
|
||||||
touch "$INSTALL_DIR/.installed_commit"
|
touch "$INSTALL_DIR/.installed_commit"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -rf "$BACKUP_DIR"
|
rm -rf "$BACKUP_DIR" 2>/dev/null || true
|
||||||
|
|
||||||
return $upgrade_status
|
return $upgrade_status
|
||||||
}
|
}
|
||||||
|
|
@ -17,24 +17,23 @@ start_services() {
|
||||||
if [ "$SYSTEMCTL_AVAILABLE" = true ]; then
|
if [ "$SYSTEMCTL_AVAILABLE" = true ]; then
|
||||||
mkdir -p "$UNIT_DIR"
|
mkdir -p "$UNIT_DIR"
|
||||||
|
|
||||||
# Check and create lnd.service if needed
|
# Check and create lnd.service if needed (only if it doesn't exist)
|
||||||
LND_UNIT="$UNIT_DIR/lnd.service"
|
LND_UNIT="$UNIT_DIR/lnd.service"
|
||||||
|
if [ ! -f "$LND_UNIT" ]; then
|
||||||
NEW_LND_CONTENT="[Unit]\nDescription=LND Service\nAfter=network.target\n\n[Service]\nExecStart=${USER_HOME}/lnd/lnd\nRestart=always\n\n[Install]\nWantedBy=default.target"
|
NEW_LND_CONTENT="[Unit]\nDescription=LND Service\nAfter=network.target\n\n[Service]\nExecStart=${USER_HOME}/lnd/lnd\nRestart=always\n\n[Install]\nWantedBy=default.target"
|
||||||
if [ ! -f "$LND_UNIT" ] || [ "$(cat "$LND_UNIT")" != "$NEW_LND_CONTENT" ]; then
|
|
||||||
echo -e "$NEW_LND_CONTENT" > "$LND_UNIT"
|
echo -e "$NEW_LND_CONTENT" > "$LND_UNIT"
|
||||||
$SYSTEMCTL_CMD daemon-reload
|
$SYSTEMCTL_CMD daemon-reload
|
||||||
|
$SYSTEMCTL_CMD enable lnd >/dev/null 2>&1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check and create lightning_pub.service if needed
|
# Check and create lightning_pub.service if needed (only if it doesn't exist)
|
||||||
PUB_UNIT="$UNIT_DIR/lightning_pub.service"
|
PUB_UNIT="$UNIT_DIR/lightning_pub.service"
|
||||||
|
if [ ! -f "$PUB_UNIT" ]; then
|
||||||
NEW_PUB_CONTENT="[Unit]\nDescription=Lightning.Pub Service\nAfter=network.target\n\n[Service]\nExecStart=/bin/bash -c 'source ${NVM_DIR}/nvm.sh && npm start'\nWorkingDirectory=${INSTALL_DIR}\nRestart=always\n\n[Install]\nWantedBy=default.target"
|
NEW_PUB_CONTENT="[Unit]\nDescription=Lightning.Pub Service\nAfter=network.target\n\n[Service]\nExecStart=/bin/bash -c 'source ${NVM_DIR}/nvm.sh && npm start'\nWorkingDirectory=${INSTALL_DIR}\nRestart=always\n\n[Install]\nWantedBy=default.target"
|
||||||
if [ ! -f "$PUB_UNIT" ] || [ "$(cat "$PUB_UNIT")" != "$NEW_PUB_CONTENT" ]; then
|
|
||||||
echo -e "$NEW_PUB_CONTENT" > "$PUB_UNIT"
|
echo -e "$NEW_PUB_CONTENT" > "$PUB_UNIT"
|
||||||
$SYSTEMCTL_CMD daemon-reload
|
$SYSTEMCTL_CMD daemon-reload
|
||||||
fi
|
|
||||||
|
|
||||||
$SYSTEMCTL_CMD enable lnd >/dev/null 2>&1
|
|
||||||
$SYSTEMCTL_CMD enable lightning_pub >/dev/null 2>&1
|
$SYSTEMCTL_CMD enable lightning_pub >/dev/null 2>&1
|
||||||
|
fi
|
||||||
|
|
||||||
# Only start/restart LND if it was freshly installed or upgraded
|
# Only start/restart LND if it was freshly installed or upgraded
|
||||||
if [ "$LND_STATUS" = "0" ] || [ "$LND_STATUS" = "1" ]; then
|
if [ "$LND_STATUS" = "0" ] || [ "$LND_STATUS" = "1" ]; then
|
||||||
|
|
@ -45,15 +44,15 @@ start_services() {
|
||||||
log "${PRIMARY_COLOR}Starting${RESET_COLOR} ${SECONDARY_COLOR}LND${RESET_COLOR} service..."
|
log "${PRIMARY_COLOR}Starting${RESET_COLOR} ${SECONDARY_COLOR}LND${RESET_COLOR} service..."
|
||||||
$SYSTEMCTL_CMD start lnd
|
$SYSTEMCTL_CMD start lnd
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
log "${SECONDARY_COLOR}LND${RESET_COLOR} not updated, service status unchanged."
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check LND status after attempting to start/restart
|
# Check LND status after attempting to start/restart
|
||||||
if ! $SYSTEMCTL_CMD is-active --quiet lnd; then
|
if ! $SYSTEMCTL_CMD is-active --quiet lnd; then
|
||||||
log "Failed to start or restart ${SECONDARY_COLOR}LND${RESET_COLOR}. Please check the logs."
|
log "Failed to start or restart ${SECONDARY_COLOR}LND${RESET_COLOR}. Please check the logs."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
log "${SECONDARY_COLOR}LND${RESET_COLOR} not updated, service status unchanged."
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$PUB_UPGRADE" = "0" ] || [ "$PUB_UPGRADE" = "100" ]; then
|
if [ "$PUB_UPGRADE" = "0" ] || [ "$PUB_UPGRADE" = "100" ]; then
|
||||||
if [ "$PUB_UPGRADE" = "100" ]; then
|
if [ "$PUB_UPGRADE" = "100" ]; then
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue