Skip to content

Commit 5bfbaca

Browse files
Fix update.sh
1 parent a3d0141 commit 5bfbaca

File tree

2 files changed

+36
-27
lines changed

2 files changed

+36
-27
lines changed

server.log

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
3+
> node server.js
4+
5+
> Ready on http://0.0.0.0:3000
6+
> WebSocket server running on ws://0.0.0.0:3000/ws/script-execution

update.sh

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ restore_backup_files() {
355355
if [ -f ".env" ]; then
356356
rm -f ".env"
357357
fi
358-
if mv "$BACKUP_DIR/.env" ".env"; then
358+
if cp "$BACKUP_DIR/.env" ".env"; then
359359
log_success ".env file restored from backup"
360360
else
361361
log_error "Failed to restore .env file"
@@ -370,7 +370,7 @@ restore_backup_files() {
370370
if [ -d "data" ]; then
371371
rm -rf "data"
372372
fi
373-
if mv "$BACKUP_DIR/data" "data"; then
373+
if cp -r "$BACKUP_DIR/data" "data"; then
374374
log_success "Data directory restored from backup"
375375
else
376376
log_error "Failed to restore data directory"
@@ -397,7 +397,7 @@ restore_backup_files() {
397397
rm -rf "$target_dir"
398398
fi
399399

400-
if mv "$BACKUP_DIR/$backup_name" "$target_dir"; then
400+
if cp -r "$BACKUP_DIR/$backup_name" "$target_dir"; then
401401
log_success "$target_dir directory restored from backup"
402402
else
403403
log_error "Failed to restore $target_dir directory"
@@ -430,8 +430,8 @@ verify_database_restored() {
430430

431431
local db_size=$(stat -f%z "$db_file" 2>/dev/null || stat -c%s "$db_file" 2>/dev/null)
432432
if [ "$db_size" -eq 0 ]; then
433-
log_error "Database file is empty after restore!"
434-
return 1
433+
log_warning "Database file is empty - will be recreated by Prisma migrations"
434+
return 0 # Don't fail the update, let Prisma recreate the database
435435
fi
436436

437437
log_success "Database verified (file: $db_file, size: $db_size bytes)"
@@ -490,15 +490,15 @@ stop_application() {
490490
if [ -f "package.json" ] && [ -f "server.js" ]; then
491491
app_dir="$(pwd)"
492492
else
493-
# Try to find the application directory
494-
app_dir=$(find /root -name "package.json" -path "*/ProxmoxVE-Local*" -exec dirname {} \; 2>/dev/null | head -1)
495-
if [ -n "$app_dir" ] && [ -d "$app_dir" ]; then
493+
# Change to production application directory
494+
app_dir="/opt/ProxmoxVE-Local"
495+
if [ -d "$app_dir" ] && [ -f "$app_dir/server.js" ]; then
496496
cd "$app_dir" || {
497497
log_error "Failed to change to application directory: $app_dir"
498498
return 1
499499
}
500500
else
501-
log_error "Could not find application directory"
501+
log_error "Production application directory not found: $app_dir"
502502
return 1
503503
fi
504504
fi
@@ -741,11 +741,16 @@ start_application() {
741741
fi
742742
else
743743
log_error "Failed to enable/start service, falling back to npm start"
744-
start_with_npm
744+
if ! start_with_npm; then
745+
log_error "Failed to start application with npm"
746+
return 1
747+
fi
745748
fi
746749
else
747750
log "Service was not running before update or no service exists, starting with npm..."
748-
start_with_npm
751+
if ! start_with_npm; then
752+
return 1
753+
fi
749754
fi
750755
}
751756

@@ -869,23 +874,15 @@ main() {
869874
if [ -f "package.json" ] && [ -f "server.js" ]; then
870875
app_dir="$(pwd)"
871876
else
872-
# Try multiple common locations:
873-
for search_path in /opt /root /home /usr/local; do
874-
if [ -d "$search_path" ]; then
875-
app_dir=$(find "$search_path" -name "package.json" -path "*/ProxmoxVE-Local*" -exec dirname {} \; 2>/dev/null | head -1)
876-
if [ -n "$app_dir" ] && [ -d "$app_dir" ]; then
877-
break
878-
fi
879-
fi
880-
done
881-
882-
if [ -n "$app_dir" ] && [ -d "$app_dir" ]; then
877+
# Use production application directory
878+
app_dir="/opt/ProxmoxVE-Local"
879+
if [ -d "$app_dir" ] && [ -f "$app_dir/server.js" ]; then
883880
cd "$app_dir" || {
884881
log_error "Failed to change to application directory: $app_dir"
885882
exit 1
886883
}
887884
else
888-
log_error "Could not find application directory"
885+
log_error "Production application directory not found: $app_dir"
889886
exit 1
890887
fi
891888
fi
@@ -929,6 +926,7 @@ main() {
929926
# Restore .env and data directory before building
930927
restore_backup_files
931928

929+
932930
# Verify database was restored correctly
933931
if ! verify_database_restored; then
934932
log_error "Database verification failed, rolling back..."
@@ -944,12 +942,17 @@ main() {
944942
rollback
945943
fi
946944

947-
# Cleanup
945+
# Start the application
946+
if ! start_application; then
947+
log_error "Failed to start application after update"
948+
rollback
949+
fi
950+
951+
# Cleanup only after successful start
948952
rm -rf "$source_dir"
949953
rm -rf "/tmp/pve-update-$$"
950-
951-
# Start the application
952-
start_application
954+
rm -rf "$BACKUP_DIR"
955+
log "Backup directory cleaned up"
953956

954957
log_success "Update completed successfully!"
955958
}

0 commit comments

Comments
 (0)