- Kiwix must be restarted
- New Zim files have been downloaded; you must restart your containers.
-
- Run the following to restart your containers:
- docker-compose restart
-
-}
-
const ZimSearchEntry = ({zimId, onTag, onUntag, entry}) => {
const {path, title, headline, tag_names} = entry;
const [open, setOpen] = React.useState(false);
diff --git a/modules/zim/lib.py b/modules/zim/lib.py
index 06a421bf..d1be187a 100644
--- a/modules/zim/lib.py
+++ b/modules/zim/lib.py
@@ -17,7 +17,9 @@ from modules.zim.models import Zim, Zims, TagZimEntry, ZimSubscription
from wrolpi import flags
from wrolpi.cmd import run_command
from wrolpi.common import register_modeler, logger, extract_html_text, extract_headlines, get_media_directory, walk, \
- register_refresh_cleanup, background_task, get_wrolpi_config, unique_by_predicate
+ register_refresh_cleanup, background_task, get_wrolpi_config, unique_by_predicate, aiohttp_post
+from wrolpi.dates import Seconds
+from wrolpi.events import Events
from wrolpi.db import get_db_session, get_db_curs
from wrolpi.downloader import DownloadFrequency
from wrolpi.files.lib import refresh_files, split_file_name_words
@@ -26,6 +28,8 @@ from wrolpi.vars import PYTEST, DOCKERIZED
logger = logger.getChild(__name__)
+CONTROLLER_SERVICE = 'http://controller:8087'
+
__all__ = [
'flag_outdated_zim_files',
'get_all_entries_tags',
@@ -573,9 +577,23 @@ async def restart_kiwix():
logger.warning('Unable to restart Kiwix serve because we are testing')
return
if DOCKERIZED:
- logger.warning('Setting Kiwix restart because this is in a docker container')
- flags.kiwix_restart.set()
- return
+ logger.info('Restarting Kiwix via controller API')
+ try:
+ async with aiohttp_post(f'{CONTROLLER_SERVICE}/api/services/zim/restart',
+ timeout=Seconds.minute) as response:
+ if response.status == 200:
+ logger.info('Successfully restarted Kiwix container')
+ return 0
+ else:
+ logger.error(f'Failed to restart Kiwix: {response.status}')
+ Events.send_user_notify(
+ 'Failed to restart Kiwix automatically. Please restart manually: docker compose restart zim')
+ return 1
+ except Exception as e:
+ logger.error(f'Failed to restart Kiwix: {e}')
+ Events.send_user_notify(
+ 'Failed to restart Kiwix automatically. Please restart manually: docker compose restart zim')
+ return 1
logger.info('Restarting Kiwix serve')
diff --git a/wrolpi/flags.py b/wrolpi/flags.py
index d09977d0..e3d0a441 100644
--- a/wrolpi/flags.py
+++ b/wrolpi/flags.py
@@ -110,8 +110,6 @@ db_up = Flag('db_up')
refreshing = Flag('refreshing')
# Outdated Zims need to be removed.
outdated_zims = Flag('outdated_zims', store_db=True)
-# Kiwix server needs to be restarted.
-kiwix_restart = Flag('kiwix_restart')
# Map Importing
map_importing = Flag('map_importing')
# Used to disable or enable downloading when Internet is down.
@@ -132,7 +130,6 @@ def get_flags() -> dict:
"""Return a list of all Flags which are set."""
flags = dict(
db_up=db_up.is_set(),
- kiwix_restart=kiwix_restart.is_set(),
map_importing=map_importing.is_set(),
outdated_zims=outdated_zims.is_set(),
refresh_cleanup=refresh_cleanup.is_set(),
diff --git a/wrolpi/schema.py b/wrolpi/schema.py
index 75e6cf1b..2583f201 100644
--- a/wrolpi/schema.py
+++ b/wrolpi/schema.py
@@ -84,7 +84,6 @@ class SettingsRequest:
@dataclass
class FlagsStatusResponse:
db_up: bool
- kiwix_restart: bool
map_importing: bool
outdated_zims: bool
refresh_cleanup: bool