bundles/docker-immich: database not existing should not error out the script
after all, we have monitoring to ensure the database container runs
This commit is contained in:
parent
f9e87bde9e
commit
57c1eb2605
1 changed files with 19 additions and 13 deletions
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import logging
|
||||||
from json import loads
|
from json import loads
|
||||||
from os import environ
|
from os import environ
|
||||||
from subprocess import check_output
|
from subprocess import check_output
|
||||||
|
@ -12,6 +13,8 @@ PSQL_USER = environ['DB_USERNAME']
|
||||||
PSQL_PASS = environ['DB_PASSWORD']
|
PSQL_PASS = environ['DB_PASSWORD']
|
||||||
PSQL_DB = environ['DB_DATABASE_NAME']
|
PSQL_DB = environ['DB_DATABASE_NAME']
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
docker_networks = loads(check_output(['docker', 'network', 'inspect', 'aaarghhh']))
|
docker_networks = loads(check_output(['docker', 'network', 'inspect', 'aaarghhh']))
|
||||||
|
|
||||||
container_ip = None
|
container_ip = None
|
||||||
|
@ -26,9 +29,9 @@ for network in docker_networks:
|
||||||
container_ip = container['IPv4Address'].split('/')[0]
|
container_ip = container['IPv4Address'].split('/')[0]
|
||||||
|
|
||||||
if not container_ip:
|
if not container_ip:
|
||||||
print(f'could not find ip address for container {PSQL_HOST=} in json')
|
logging.error(f'could not find ip address for container {PSQL_HOST=} in json')
|
||||||
print(docker_networks)
|
logging.debug(f'{docker_networks=}')
|
||||||
exit(1)
|
exit(0)
|
||||||
|
|
||||||
print(f'{PSQL_HOST=} {container_ip=}')
|
print(f'{PSQL_HOST=} {container_ip=}')
|
||||||
|
|
||||||
|
@ -49,6 +52,7 @@ with conn:
|
||||||
}
|
}
|
||||||
for i in cur.fetchall()
|
for i in cur.fetchall()
|
||||||
}
|
}
|
||||||
|
logging.debug(f'{albums=}')
|
||||||
|
|
||||||
with conn.cursor() as cur:
|
with conn.cursor() as cur:
|
||||||
cur.execute('SELECT "id","name" FROM users;')
|
cur.execute('SELECT "id","name" FROM users;')
|
||||||
|
@ -56,25 +60,27 @@ with conn:
|
||||||
i[0]: i[1]
|
i[0]: i[1]
|
||||||
for i in cur.fetchall()
|
for i in cur.fetchall()
|
||||||
}
|
}
|
||||||
|
logging.debug(f'{users=}')
|
||||||
|
|
||||||
for album_id, album in albums.items():
|
for album_id, album in albums.items():
|
||||||
print(f'----- working on album: {album["name"]}')
|
log = logging.getLogger(album["name"])
|
||||||
with conn:
|
with conn:
|
||||||
with conn.cursor() as cur:
|
with conn.cursor() as cur:
|
||||||
cur.execute('SELECT "usersId" FROM albums_shared_users_users WHERE "albumsId" = %s;', (album_id,))
|
cur.execute('SELECT "usersId" FROM albums_shared_users_users WHERE "albumsId" = %s;', (album_id,))
|
||||||
album_shares = [i[0] for i in cur.fetchall()]
|
album_shares = [i[0] for i in cur.fetchall()]
|
||||||
print(f' album is shared with {len(album_shares)} users: {album_shares}')
|
log.info(f'album is shared with {len(album_shares)} users: {album_shares}')
|
||||||
for user_id, user_name in users.items():
|
for user_id, user_name in users.items():
|
||||||
if user_id == album['owner'] or user_id in album_shares:
|
if user_id == album['owner'] or user_id in album_shares:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
print(f' sharing album with user {user_name} ... ', end='')
|
log.info(f'sharing album with user {user_name}')
|
||||||
|
try:
|
||||||
with conn.cursor() as cur:
|
with conn.cursor() as cur:
|
||||||
cur.execute(
|
cur.execute(
|
||||||
'INSERT INTO albums_shared_users_users ("albumsId","usersId","role") VALUES (%s, %s, %s);',
|
'INSERT INTO albums_shared_users_users ("albumsId","usersId","role") VALUES (%s, %s, %s);',
|
||||||
(album_id, user_id, 'viewer'),
|
(album_id, user_id, 'viewer'),
|
||||||
)
|
)
|
||||||
print('done')
|
except Exception:
|
||||||
print()
|
log.exception('failure while creating share')
|
||||||
|
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue