diff --git a/app/src/DashboardPage.js b/app/src/DashboardPage.js index 6dabc1f0..7fba0d20 100644 --- a/app/src/DashboardPage.js +++ b/app/src/DashboardPage.js @@ -28,7 +28,7 @@ import _ from "lodash"; import {TagsDashboard} from "./Tags"; import {Upload} from "./components/Upload"; import {SearchView, useSearch, useSearchSuggestions} from "./components/Search"; -import {KiwixRestartMessage, OutdatedZimsMessage} from "./components/Zim"; +import {OutdatedZimsMessage} from "./components/Zim"; import {useSearchFilter, useSearchRecentFiles, useWROLMode} from "./hooks/customHooks"; import {FileCards, FileSearchFilterButton} from "./components/Files"; import {DateSelectorButton} from "./components/DatesSelector"; @@ -77,11 +77,6 @@ function FlagsMessages() { } - let kiwixRestartMessage; - if (flags.kiwix_restart) { - kiwixRestartMessage = ; - } - let internetDownMessage; if (!flags.have_internet && !settings.wrol_mode) { internetDownMessage = @@ -95,7 +90,6 @@ function FlagsMessages() { {dbDownMessage || refreshRequiredMessage} {settings && settings['ignore_outdated_zims'] === false && flags.outdated_zims ? : null} - {kiwixRestartMessage} {internetDownMessage} } diff --git a/app/src/components/Zim.js b/app/src/components/Zim.js index ff06fda4..92df06f7 100644 --- a/app/src/components/Zim.js +++ b/app/src/components/Zim.js @@ -153,16 +153,6 @@ export const OutdatedZimsMessage = ({onClick}) => { } -export const KiwixRestartMessage = () => { - return - 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