diff --git a/50x.html b/50x.html
index c4446ff2..2214a36c 100644
--- a/50x.html
+++ b/50x.html
@@ -17,14 +17,17 @@
Or, start them individually:
sudo systemctl start wrolpi-app
sudo systemctl start wrolpi-api
+sudo systemctl start wrolpi-kiwix
View the logs
journalctl -u wrolpi-app
journalctl -u wrolpi-api
+journalctl -u wrolpi-kiwix
Watch the logs
journalctl -fu wrolpi-app
journalctl -fu wrolpi-api
+journalctl -fu wrolpi-kiwix
diff --git a/app/src/components/Zim.js b/app/src/components/Zim.js
index a0b80750..c725539a 100644
--- a/app/src/components/Zim.js
+++ b/app/src/components/Zim.js
@@ -479,7 +479,7 @@ class ManageZim extends React.Component {
;
- if (subscriptions && Object.keys(subscriptions).length > 0) {
+ if (catalog && catalog.length > 0) {
kiwixCatalog = /dev/null | grep -i kiwix >/dev/null; then
+ echo "OK: Kiwix app responded"
+else
+ echo "FAILED: Kiwix app did not respond"
+fi
+
echo
# Media Directory
diff --git a/modules/zim/downloader.py b/modules/zim/downloader.py
index 99fcbe82..504fa632 100644
--- a/modules/zim/downloader.py
+++ b/modules/zim/downloader.py
@@ -108,6 +108,11 @@ class KiwixZimDownloader(Downloader):
else:
background_task(refresh_files([output_path, ]))
+ # Restart Kiwix serve, so it finds the new zim file.
+ return_code = await lib.restart_kiwix()
+ if return_code != 0:
+ logger.error(f'Failed to restart kiwix')
+
# Location is just the generic Kiwix viewer.
return DownloadResult(success=True, location='/zim')
diff --git a/modules/zim/lib.py b/modules/zim/lib.py
index 96279016..03cad581 100644
--- a/modules/zim/lib.py
+++ b/modules/zim/lib.py
@@ -482,3 +482,19 @@ def flag_kiwix_restart():
flags.kiwix_restart.set()
else:
logger.debug(f'Not setting kiwix_restart flag because this is not Dockerized')
+
+
+async def restart_kiwix():
+ if DOCKERIZED:
+ logger.warning('Unable to restart Kiwix serve because it is in a docker container')
+ return
+
+ logger.info('Restarting Kiwix serve')
+
+ cmd = f'sudo /usr/bin/systemctl restart wrolpi-kiwix.service'
+ proc = await asyncio.create_subprocess_shell(cmd)
+ stdout, stderr = await proc.communicate()
+ logger.debug(f'systemctl returned {proc.returncode}')
+ if proc.returncode != 0 and stderr:
+ logger.debug(stderr)
+ return proc.returncode
diff --git a/pi-gen/stage2/04-wrolpi/01-packages b/pi-gen/stage2/04-wrolpi/01-packages
index 820610cd..1eddbbe6 100644
--- a/pi-gen/stage2/04-wrolpi/01-packages
+++ b/pi-gen/stage2/04-wrolpi/01-packages
@@ -20,6 +20,8 @@ gdal-bin
git
gnupg-agent
hostapd
+kiwix
+kiwix-tools
libagg-dev
libapache2-mod-tile
libboost-all-dev
@@ -75,3 +77,4 @@ ttf-unifont
unzip
vim
wget
+zim-tools
diff --git a/pi-gen/stage2/04-wrolpi/03-run-chroot.sh b/pi-gen/stage2/04-wrolpi/03-run-chroot.sh
index 8f33b563..f909e511 100755
--- a/pi-gen/stage2/04-wrolpi/03-run-chroot.sh
+++ b/pi-gen/stage2/04-wrolpi/03-run-chroot.sh
@@ -22,9 +22,9 @@ sed -i 's/port = 5433/port = 5432/' /etc/postgresql/13/main/postgresql.conf
# Install Node console commands.
single-file --version || npm i -g serve@12.0.1 single-file-cli@1.0.15 readability-extractor@0.0.6 carto@1.2.0
-# Put the latest WROLPi release in /opt/wrolpi.
+# Put the latest WROLPi master in /opt/wrolpi.
rm -rf /opt/wrolpi
-git clone -b release https://github.com/lrnselfreliance/wrolpi.git /opt/wrolpi
+git clone -b master https://github.com/lrnselfreliance/wrolpi.git /opt/wrolpi
git config --global --add safe.directory /opt/wrolpi
# Install Python requirements.
@@ -37,6 +37,14 @@ cd /opt/wrolpi/app
npm install
npm run build
+# Add wrolpi database password to pi user
+cat >/home/pi/.pgpass <<'EOF'
+127.0.0.1:5432:gis:_renderd:wrolpi
+127.0.0.1:5432:wrolpi:wrolpi:wrolpi
+EOF
+chown -R pi:pi /home/pi
+chmod 0600 /home/pi/.pgpass
+
chown -R wrolpi:wrolpi /opt/wrolpi
# Configure nginx.
@@ -49,6 +57,9 @@ cat >/etc/sudoers.d/90-wrolpi <<'EOF'
%wrolpi ALL= NOPASSWD:/usr/bin/systemctl restart renderd.service
%wrolpi ALL= NOPASSWD:/usr/bin/systemctl stop renderd.service
%wrolpi ALL= NOPASSWD:/usr/bin/systemctl start renderd.service
+%wrolpi ALL= NOPASSWD:/usr/bin/systemctl restart wrolpi-kiwix.service
+%wrolpi ALL= NOPASSWD:/usr/bin/systemctl stop wrolpi-kiwix.service
+%wrolpi ALL= NOPASSWD:/usr/bin/systemctl start wrolpi-kiwix.service
%wrolpi ALL= NOPASSWD:/usr/bin/systemctl restart wrolpi-api.service
%wrolpi ALL= NOPASSWD:/usr/bin/systemctl stop wrolpi-api.service
%wrolpi ALL= NOPASSWD:/usr/bin/systemctl start wrolpi-api.service
@@ -63,10 +74,12 @@ chown wrolpi:wrolpi /media/wrolpi
cp /opt/wrolpi/etc/raspberrypios/wrolpi-api.service /etc/systemd/system/
cp /opt/wrolpi/etc/raspberrypios/wrolpi-app.service /etc/systemd/system/
+cp /opt/wrolpi/etc/raspberrypios/wrolpi-kiwix.service /etc/systemd/system/
cp /opt/wrolpi/etc/raspberrypios/wrolpi.target /etc/systemd/system/
systemctl enable wrolpi-api.service
systemctl enable wrolpi-app.service
+systemctl enable wrolpi-kiwix.service
# NetworkManager for the hotspot.
systemctl enable NetworkManager
diff --git a/scripts/install_debian_11.sh b/scripts/install_debian_11.sh
index 70aab437..36a86e46 100755
--- a/scripts/install_debian_11.sh
+++ b/scripts/install_debian_11.sh
@@ -38,7 +38,7 @@ apt install -y \
# Install npm.
npm --version || curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
-apt install -y nodejs
+apt-get install -y nodejs
node -v
npm -v
@@ -70,12 +70,29 @@ EOF
chown -R wrolpi:wrolpi /home/wrolpi /opt/wrolpi
chmod 0600 /home/wrolpi/.pgpass
+# Allow pi user to access database.
+cat >/home/pi/.pgpass <<'EOF'
+127.0.0.1:5432:gis:_renderd:wrolpi
+127.0.0.1:5432:wrolpi:wrolpi:wrolpi
+EOF
+chown -R pi:pi /home/pi
+chmod 0600 /home/pi/.pgpass
+
# Give WROLPi group a few privileged commands via sudo without password.
cat >/etc/sudoers.d/90-wrolpi <<'EOF'
%wrolpi ALL=(ALL) NOPASSWD:/usr/bin/nmcli,/usr/bin/cpufreq-set
%wrolpi ALL= NOPASSWD:/usr/bin/systemctl restart renderd.service
%wrolpi ALL= NOPASSWD:/usr/bin/systemctl stop renderd.service
%wrolpi ALL= NOPASSWD:/usr/bin/systemctl start renderd.service
+%wrolpi ALL= NOPASSWD:/usr/bin/systemctl restart wrolpi-kiwix.service
+%wrolpi ALL= NOPASSWD:/usr/bin/systemctl stop wrolpi-kiwix.service
+%wrolpi ALL= NOPASSWD:/usr/bin/systemctl start wrolpi-kiwix.service
+%wrolpi ALL= NOPASSWD:/usr/bin/systemctl restart wrolpi-api.service
+%wrolpi ALL= NOPASSWD:/usr/bin/systemctl stop wrolpi-api.service
+%wrolpi ALL= NOPASSWD:/usr/bin/systemctl start wrolpi-api.service
+%wrolpi ALL= NOPASSWD:/usr/bin/systemctl restart wrolpi-app.service
+%wrolpi ALL= NOPASSWD:/usr/bin/systemctl stop wrolpi-app.service
+%wrolpi ALL= NOPASSWD:/usr/bin/systemctl start wrolpi-app.service
EOF
chmod 660 /etc/sudoers.d/90-wrolpi
# Verify this new file is valid.
@@ -87,14 +104,17 @@ chown wrolpi:wrolpi /media/wrolpi
# Install the systemd services
cp /opt/wrolpi/etc/raspberrypios/wrolpi-api.service /etc/systemd/system/
-cp /opt/wrolpi/etc/debian11/wrolpi-app.service /etc/systemd/system/
+cp /opt/wrolpi/etc/raspberrypios/wrolpi-app.service /etc/systemd/system/
+cp /opt/wrolpi/etc/raspberrypios/wrolpi-kiwix.service /etc/systemd/system/
cp /opt/wrolpi/etc/raspberrypios/wrolpi.target /etc/systemd/system/
/usr/bin/systemctl daemon-reload
systemctl enable wrolpi-api.service
systemctl enable wrolpi-app.service
+systemctl enable wrolpi-kiwix.service
# Stop the services so the user has to start them again. We don't want to run outdated services when updating.
systemctl stop wrolpi-api.service
systemctl stop wrolpi-app.service
+systemctl stop wrolpi-kiwix.service
# Configure Postgresql. Do this after the API is stopped.
sudo -u postgres psql -c '\l' | grep wrolpi || (
@@ -111,6 +131,8 @@ sudo -u postgres psql -c "alter user wrolpi with superuser"
# Install map only if that script hasn't finished.
[ -f /var/www/html/leaflet.css ] || /opt/wrolpi/scripts/install_map_debian_11.sh
+chown -R wrolpi:wrolpi /opt/wrolpi
+
set +x
ip=$(hostname -I | cut -d' ' -f1)
diff --git a/scripts/install_raspberrypios.sh b/scripts/install_raspberrypios.sh
index 52040b88..55c846a9 100755
--- a/scripts/install_raspberrypios.sh
+++ b/scripts/install_raspberrypios.sh
@@ -6,8 +6,8 @@ set -e
# Update if we haven't updated in the last day.
[ -z "$(find -H /var/lib/apt/lists -maxdepth 0 -mtime -1)" ] && apt update
-# Install dependencies
-apt install -y \
+# Install dependencies used in pi-gen.
+apt-get install -y \
apt-transport-https \
ca-certificates \
calibre \
@@ -38,7 +38,7 @@ apt install -y \
# Install npm.
npm --version || curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
-apt install -y nodejs
+apt-get install -y nodejs
node -v
npm -v
@@ -70,12 +70,31 @@ EOF
chown -R wrolpi:wrolpi /home/wrolpi /opt/wrolpi
chmod 0600 /home/wrolpi/.pgpass
+# Allow pi user to access database.
+[ -d /home/pi ] && (
+ cat >/home/pi/.pgpass <<'EOF'
+127.0.0.1:5432:gis:_renderd:wrolpi
+127.0.0.1:5432:wrolpi:wrolpi:wrolpi
+EOF
+ chown -R pi:pi /home/pi
+ chmod 0600 /home/pi/.pgpass
+)
+
# Give WROLPi group a few privileged commands via sudo without password.
cat >/etc/sudoers.d/90-wrolpi <<'EOF'
%wrolpi ALL=(ALL) NOPASSWD:/usr/bin/nmcli,/usr/bin/cpufreq-set
%wrolpi ALL= NOPASSWD:/usr/bin/systemctl restart renderd.service
%wrolpi ALL= NOPASSWD:/usr/bin/systemctl stop renderd.service
%wrolpi ALL= NOPASSWD:/usr/bin/systemctl start renderd.service
+%wrolpi ALL= NOPASSWD:/usr/bin/systemctl restart wrolpi-kiwix.service
+%wrolpi ALL= NOPASSWD:/usr/bin/systemctl stop wrolpi-kiwix.service
+%wrolpi ALL= NOPASSWD:/usr/bin/systemctl start wrolpi-kiwix.service
+%wrolpi ALL= NOPASSWD:/usr/bin/systemctl restart wrolpi-api.service
+%wrolpi ALL= NOPASSWD:/usr/bin/systemctl stop wrolpi-api.service
+%wrolpi ALL= NOPASSWD:/usr/bin/systemctl start wrolpi-api.service
+%wrolpi ALL= NOPASSWD:/usr/bin/systemctl restart wrolpi-app.service
+%wrolpi ALL= NOPASSWD:/usr/bin/systemctl stop wrolpi-app.service
+%wrolpi ALL= NOPASSWD:/usr/bin/systemctl start wrolpi-app.service
EOF
chmod 660 /etc/sudoers.d/90-wrolpi
# Verify this new file is valid.
@@ -88,13 +107,16 @@ chown wrolpi:wrolpi /media/wrolpi
# Install the systemd services
cp /opt/wrolpi/etc/raspberrypios/wrolpi-api.service /etc/systemd/system/
cp /opt/wrolpi/etc/raspberrypios/wrolpi-app.service /etc/systemd/system/
+cp /opt/wrolpi/etc/raspberrypios/wrolpi-kiwix.service /etc/systemd/system/
cp /opt/wrolpi/etc/raspberrypios/wrolpi.target /etc/systemd/system/
/usr/bin/systemctl daemon-reload
systemctl enable wrolpi-api.service
systemctl enable wrolpi-app.service
+systemctl enable wrolpi-kiwix.service
# Stop the services so the user has to start them again. We don't want to run outdated services when updating.
systemctl stop wrolpi-api.service
systemctl stop wrolpi-app.service
+systemctl stop wrolpi-kiwix.service
# Configure Postgresql. Do this after the API is stopped.
sudo -u postgres psql -c '\l' | grep wrolpi || (
@@ -111,6 +133,8 @@ sudo -u postgres psql -c "alter user wrolpi with superuser"
# Install map only if that script hasn't finished.
[ -f /var/www/html/leaflet.css ] || /opt/wrolpi/scripts/install_map_raspberrypios.sh
+chown -R wrolpi:wrolpi /opt/wrolpi
+
set +x
ip=$(hostname -i | cut -d' ' -f1)
diff --git a/scripts/start_kiwix_serve.sh b/scripts/start_kiwix_serve.sh
new file mode 100755
index 00000000..68f5a5f7
--- /dev/null
+++ b/scripts/start_kiwix_serve.sh
@@ -0,0 +1,18 @@
+#! /usr/bin/env bash
+# This file imports all *.zim files in the media directory, then starts kiwix-serve.
+
+[ ! -d /media/wrolpi ] && echo "Cannot start kiwix without media directory mounted" && exit 1
+
+LIBRARY=/media/wrolpi/zims/library.xml
+
+# Create the zim directory, if necessary.
+[ ! -d /media/wrolpi/zims ] && mkdir /media/wrolpi/zims
+# We will replace the library file.
+rm -f ${LIBRARY}
+# Find all Zim files and import them.
+find /media/wrolpi -iname '*.zim' -exec kiwix-manage ${LIBRARY} add {} \;
+
+[ ! -f ${LIBRARY} ] && echo "Could not find any Zim files to import" && exit 2
+
+# Serve kiwix on the
+kiwix-serve --library ${LIBRARY} --address 0.0.0.0 --port 8085