Fix: Service management errors in sigvild-gallery restoration

- Fix Unix timestamp conversion in restore.yml using proper strftime syntax
- Add service existence check before stopping sigvild-gallery service
- Fix systemd service template environment variable syntax error
- Add proper error handling for fresh deployments where service doesn't exist yet

Resolves service management failures during restoration on fresh VPS installations.
This commit is contained in:
2025-12-07 21:21:31 +01:00
parent 0507e3291d
commit 4df87dd57f
2 changed files with 26 additions and 5 deletions

View File

@@ -17,7 +17,7 @@
- name: Display found backup files
debug:
msg: "Found backup: {{ item.path }} ({{ (item.size / 1024 / 1024) | round(2) }}MB, {{ item.mtime | to_datetime }})"
msg: "Found backup: {{ item.path }} ({{ (item.size / 1024 / 1024) | round(2) }}MB, {{ '%Y-%m-%d %H:%M:%S' | strftime(item.mtime | int) }})"
loop: "{{ backup_files.files | sort(attribute='mtime') }}"
when: backup_files.files | length > 0
@@ -33,6 +33,15 @@
- existing_data.stat.exists
- backup_files.files | length > 0
- name: Skip restore due to existing data
debug:
msg:
- "🛡️ SAFETY: Restore skipped to protect existing data"
- "Remove {{ sigvild_gallery_data_dir }}/data.db manually to enable restore"
when:
- existing_data.stat.exists
- backup_files.files | length > 0
- name: Restore from latest backup
block:
- name: Get latest backup file
@@ -45,12 +54,22 @@
- "Restoring from latest backup: {{ latest_backup | basename }}"
- "Target directory: {{ sigvild_gallery_data_dir }}"
- name: Check if sigvild-gallery service exists
stat:
path: /etc/systemd/system/sigvild-gallery.service
register: sigvild_service_file
- name: Stop sigvild-gallery service before restoration
systemd:
name: sigvild-gallery
state: stopped
register: service_stopped_for_restore
ignore_errors: true # Service might not exist on fresh deployment
when: sigvild_service_file.stat.exists
ignore_errors: true
- name: Display service stop status
debug:
msg: "{{ 'Service stopped for restoration' if sigvild_service_file.stat.exists else 'Service does not exist yet - skipping stop' }}"
- name: Upload backup to remote server
copy:
@@ -116,7 +135,9 @@
- "Restored data size: {{ restored_size.stdout }}"
- "Location: {{ sigvild_gallery_data_dir }}"
when: backup_files.files | length > 0
when:
- backup_files.files | length > 0
- not existing_data.stat.exists
- name: No backup available message
debug:

View File

@@ -10,7 +10,7 @@ WorkingDirectory={{ sigvild_gallery_home }}
ExecStart={{ sigvild_gallery_binary }} serve --http={{ sigvild_gallery_host }}:{{ sigvild_gallery_port }}
# Environment variables
Environment="SIGVILD_ENVIRONMENT"="production" # Lets caddy handle CORS
Environment="SIGVILD_ENVIRONMENT"="production"
Environment="HOST_USERNAME={{ sigvild_gallery_host_username }}"
Environment="HOST_PASSWORD={{ sigvild_gallery_host_password }}"
Environment="HOST_DISPLAY_NAME=Wedding Host"