Fix update.sh
This commit is contained in:
6
server.log
Normal file
6
server.log
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
> pve-scripts-local@0.1.0 start
|
||||||
|
> node server.js
|
||||||
|
|
||||||
|
> Ready on http://0.0.0.0:3000
|
||||||
|
> WebSocket server running on ws://0.0.0.0:3000/ws/script-execution
|
||||||
57
update.sh
57
update.sh
@@ -355,7 +355,7 @@ restore_backup_files() {
|
|||||||
if [ -f ".env" ]; then
|
if [ -f ".env" ]; then
|
||||||
rm -f ".env"
|
rm -f ".env"
|
||||||
fi
|
fi
|
||||||
if mv "$BACKUP_DIR/.env" ".env"; then
|
if cp "$BACKUP_DIR/.env" ".env"; then
|
||||||
log_success ".env file restored from backup"
|
log_success ".env file restored from backup"
|
||||||
else
|
else
|
||||||
log_error "Failed to restore .env file"
|
log_error "Failed to restore .env file"
|
||||||
@@ -370,7 +370,7 @@ restore_backup_files() {
|
|||||||
if [ -d "data" ]; then
|
if [ -d "data" ]; then
|
||||||
rm -rf "data"
|
rm -rf "data"
|
||||||
fi
|
fi
|
||||||
if mv "$BACKUP_DIR/data" "data"; then
|
if cp -r "$BACKUP_DIR/data" "data"; then
|
||||||
log_success "Data directory restored from backup"
|
log_success "Data directory restored from backup"
|
||||||
else
|
else
|
||||||
log_error "Failed to restore data directory"
|
log_error "Failed to restore data directory"
|
||||||
@@ -397,7 +397,7 @@ restore_backup_files() {
|
|||||||
rm -rf "$target_dir"
|
rm -rf "$target_dir"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if mv "$BACKUP_DIR/$backup_name" "$target_dir"; then
|
if cp -r "$BACKUP_DIR/$backup_name" "$target_dir"; then
|
||||||
log_success "$target_dir directory restored from backup"
|
log_success "$target_dir directory restored from backup"
|
||||||
else
|
else
|
||||||
log_error "Failed to restore $target_dir directory"
|
log_error "Failed to restore $target_dir directory"
|
||||||
@@ -430,8 +430,8 @@ verify_database_restored() {
|
|||||||
|
|
||||||
local db_size=$(stat -f%z "$db_file" 2>/dev/null || stat -c%s "$db_file" 2>/dev/null)
|
local db_size=$(stat -f%z "$db_file" 2>/dev/null || stat -c%s "$db_file" 2>/dev/null)
|
||||||
if [ "$db_size" -eq 0 ]; then
|
if [ "$db_size" -eq 0 ]; then
|
||||||
log_error "Database file is empty after restore!"
|
log_warning "Database file is empty - will be recreated by Prisma migrations"
|
||||||
return 1
|
return 0 # Don't fail the update, let Prisma recreate the database
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log_success "Database verified (file: $db_file, size: $db_size bytes)"
|
log_success "Database verified (file: $db_file, size: $db_size bytes)"
|
||||||
@@ -490,15 +490,15 @@ stop_application() {
|
|||||||
if [ -f "package.json" ] && [ -f "server.js" ]; then
|
if [ -f "package.json" ] && [ -f "server.js" ]; then
|
||||||
app_dir="$(pwd)"
|
app_dir="$(pwd)"
|
||||||
else
|
else
|
||||||
# Try to find the application directory
|
# Change to production application directory
|
||||||
app_dir=$(find /root -name "package.json" -path "*/ProxmoxVE-Local*" -exec dirname {} \; 2>/dev/null | head -1)
|
app_dir="/opt/ProxmoxVE-Local"
|
||||||
if [ -n "$app_dir" ] && [ -d "$app_dir" ]; then
|
if [ -d "$app_dir" ] && [ -f "$app_dir/server.js" ]; then
|
||||||
cd "$app_dir" || {
|
cd "$app_dir" || {
|
||||||
log_error "Failed to change to application directory: $app_dir"
|
log_error "Failed to change to application directory: $app_dir"
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
log_error "Could not find application directory"
|
log_error "Production application directory not found: $app_dir"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -741,11 +741,16 @@ start_application() {
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
log_error "Failed to enable/start service, falling back to npm start"
|
log_error "Failed to enable/start service, falling back to npm start"
|
||||||
start_with_npm
|
if ! start_with_npm; then
|
||||||
|
log_error "Failed to start application with npm"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
log "Service was not running before update or no service exists, starting with npm..."
|
log "Service was not running before update or no service exists, starting with npm..."
|
||||||
start_with_npm
|
if ! start_with_npm; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -869,23 +874,15 @@ main() {
|
|||||||
if [ -f "package.json" ] && [ -f "server.js" ]; then
|
if [ -f "package.json" ] && [ -f "server.js" ]; then
|
||||||
app_dir="$(pwd)"
|
app_dir="$(pwd)"
|
||||||
else
|
else
|
||||||
# Try multiple common locations:
|
# Use production application directory
|
||||||
for search_path in /opt /root /home /usr/local; do
|
app_dir="/opt/ProxmoxVE-Local"
|
||||||
if [ -d "$search_path" ]; then
|
if [ -d "$app_dir" ] && [ -f "$app_dir/server.js" ]; then
|
||||||
app_dir=$(find "$search_path" -name "package.json" -path "*/ProxmoxVE-Local*" -exec dirname {} \; 2>/dev/null | head -1)
|
|
||||||
if [ -n "$app_dir" ] && [ -d "$app_dir" ]; then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ -n "$app_dir" ] && [ -d "$app_dir" ]; then
|
|
||||||
cd "$app_dir" || {
|
cd "$app_dir" || {
|
||||||
log_error "Failed to change to application directory: $app_dir"
|
log_error "Failed to change to application directory: $app_dir"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
log_error "Could not find application directory"
|
log_error "Production application directory not found: $app_dir"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -929,6 +926,7 @@ main() {
|
|||||||
# Restore .env and data directory before building
|
# Restore .env and data directory before building
|
||||||
restore_backup_files
|
restore_backup_files
|
||||||
|
|
||||||
|
|
||||||
# Verify database was restored correctly
|
# Verify database was restored correctly
|
||||||
if ! verify_database_restored; then
|
if ! verify_database_restored; then
|
||||||
log_error "Database verification failed, rolling back..."
|
log_error "Database verification failed, rolling back..."
|
||||||
@@ -944,12 +942,17 @@ main() {
|
|||||||
rollback
|
rollback
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Cleanup
|
# Start the application
|
||||||
|
if ! start_application; then
|
||||||
|
log_error "Failed to start application after update"
|
||||||
|
rollback
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Cleanup only after successful start
|
||||||
rm -rf "$source_dir"
|
rm -rf "$source_dir"
|
||||||
rm -rf "/tmp/pve-update-$$"
|
rm -rf "/tmp/pve-update-$$"
|
||||||
|
rm -rf "$BACKUP_DIR"
|
||||||
# Start the application
|
log "Backup directory cleaned up"
|
||||||
start_application
|
|
||||||
|
|
||||||
log_success "Update completed successfully!"
|
log_success "Update completed successfully!"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user