Skip to content

Commit

Permalink
plex_db: add notify to failures
Browse files Browse the repository at this point in the history
add ability to only run integrity check.
  • Loading branch information
saltydk committed Jul 5, 2023
1 parent 5d13041 commit 3ca1126
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
4 changes: 4 additions & 0 deletions roles/plex_db/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@
plex_db_files:
- "com.plexapp.plugins.library.db"
- "com.plexapp.plugins.library.blobs.db"

plex_db_integrity_check_only: false
plex_db_failed_integrity: false
plex_db_failed_optimization: false
12 changes: 12 additions & 0 deletions roles/plex_db/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,15 @@
with_items: "{{ plex_instances }}"
loop_control:
loop_var: role

- name: A Plex instance failed the integrity check.
ansible.builtin.fail:
msg:
- "A Plex instance failed the integrity check."
when: plex_db_failed_integrity

- name: A Plex instance failed the optimization tasks.
ansible.builtin.fail:
msg:
- "A Plex instance failed the optimization tasks."
when: plex_db_failed_optimization
40 changes: 32 additions & 8 deletions roles/plex_db/tasks/main2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,31 @@
vars:
var_prefix: "plex"

- name: Check if main database passes integrity_check
ansible.builtin.shell: "'/opt/plexsql/Plex SQLite' '{{ plex_paths_db_location }}' 'PRAGMA integrity_check(1)'"
register: plex_db_integrity_check
failed_when: (plex_db_integrity_check.stdout != 'ok')
- name: Integrity check
block:
- name: Check if main database passes integrity_check
ansible.builtin.shell: "'/opt/plexsql/Plex SQLite' '{{ plex_paths_db_location }}' 'PRAGMA integrity_check(1)'"
register: plex_db_integrity_check
failed_when: (plex_db_integrity_check.stdout != 'ok')

- name: Check if blobs database passes integrity_check
ansible.builtin.shell: "'/opt/plexsql/Plex SQLite' '{{ plex_paths_db_blobs_location }}' 'PRAGMA integrity_check(1)'"
register: plex_db_blobs_integrity_check
failed_when: (plex_db_blobs_integrity_check.stdout != 'ok')

rescue:
- name: Set Fact
ansible.builtin.set_fact:
plex_db_failed_integrity: true

- name: Check if blobs database passes integrity_check
ansible.builtin.shell: "'/opt/plexsql/Plex SQLite' '{{ plex_paths_db_blobs_location }}' 'PRAGMA integrity_check(1)'"
register: plex_db_blobs_integrity_check
failed_when: (plex_db_blobs_integrity_check.stdout != 'ok')
- name: "Notify | Plex instance '{{ plex_name }}' failed the integrity check."
ansible.builtin.include_role:
name: notify
vars:
message: "Plex instance '{{ plex_name }}' failed the integrity check."

- name: Database tasks
when: not plex_db_integrity_check_only
block:
- name: Create backup directory
ansible.builtin.file:
Expand Down Expand Up @@ -72,6 +86,16 @@
failed_when: (plex_db_blobs_reindex.rc != 0)

rescue:
- name: Set Fact
ansible.builtin.set_fact:
plex_db_failed_optimization: true

- name: "Notify | Plex instance '{{ plex_name }}' failed the optimization tasks."
ansible.builtin.include_role:
name: notify
vars:
message: "Plex instance '{{ plex_name }}' failed the optimization tasks."

- name: Delete wal and shm files
ansible.builtin.file:
path: "{{ plex_paths_plugin_support_location }}/Databases/{{ item }}"
Expand Down

0 comments on commit 3ca1126

Please sign in to comment.