mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-25 18:40:06 -04:00
Automatically restarting kiwix container when new zim is downloaded using new Controller.
This commit is contained in:
parent
d703bdc268
commit
7183cf5e85
5 changed files with 23 additions and 25 deletions
|
|
@ -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() {
|
|||
</ErrorMessage>
|
||||
}
|
||||
|
||||
let kiwixRestartMessage;
|
||||
if (flags.kiwix_restart) {
|
||||
kiwixRestartMessage = <KiwixRestartMessage/>;
|
||||
}
|
||||
|
||||
let internetDownMessage;
|
||||
if (!flags.have_internet && !settings.wrol_mode) {
|
||||
internetDownMessage = <ErrorMessage icon='globe'>
|
||||
|
|
@ -95,7 +90,6 @@ function FlagsMessages() {
|
|||
{dbDownMessage || refreshRequiredMessage}
|
||||
{settings && settings['ignore_outdated_zims'] === false && flags.outdated_zims ?
|
||||
<OutdatedZimsMessage onClick={fetchSettings}/> : null}
|
||||
{kiwixRestartMessage}
|
||||
{internetDownMessage}
|
||||
</>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -153,16 +153,6 @@ export const OutdatedZimsMessage = ({onClick}) => {
|
|||
</Message>
|
||||
}
|
||||
|
||||
export const KiwixRestartMessage = () => {
|
||||
return <WarningMessage>
|
||||
<Message.Header>Kiwix must be restarted</Message.Header>
|
||||
<p>New Zim files have been downloaded; you must restart your containers.</p>
|
||||
|
||||
<p>Run the following to restart your containers:</p>
|
||||
<pre> docker-compose restart</pre>
|
||||
</WarningMessage>
|
||||
}
|
||||
|
||||
const ZimSearchEntry = ({zimId, onTag, onUntag, entry}) => {
|
||||
const {path, title, headline, tag_names} = entry;
|
||||
const [open, setOpen] = React.useState(false);
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -84,7 +84,6 @@ class SettingsRequest:
|
|||
@dataclass
|
||||
class FlagsStatusResponse:
|
||||
db_up: bool
|
||||
kiwix_restart: bool
|
||||
map_importing: bool
|
||||
outdated_zims: bool
|
||||
refresh_cleanup: bool
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue