diff --git a/contrib/systemd/Makefile b/contrib/systemd/Makefile new file mode 100644 index 0000000..17245ba --- /dev/null +++ b/contrib/systemd/Makefile @@ -0,0 +1,7 @@ +install: + install sist2-update-all.sh /usr/bin/sist2-update-all.sh + install sist2-update-files.sh /usr/bin/sist2-update-files.sh + install sist2-update-nextcloud.sh /usr/bin/sist2-update-nextcloud.sh + install sist2-update.service /etc/systemd/system/sist2-update.service + install sist2-update.timer /etc/systemd/system/sist2-update.timer + systemctl daemon-reload diff --git a/contrib/systemd/README.md b/contrib/systemd/README.md new file mode 100644 index 0000000..a28e132 --- /dev/null +++ b/contrib/systemd/README.md @@ -0,0 +1,31 @@ +# Systemd integration example + +This example contains my (yatli) personal configuration for sist2 auto-updating. +The following indices are involved in this configuration: + +| Index | Path | Description | +|-----------|------------------|--------------------------------------------| +| files | /zpool/files | Main file repository | +| nextcloud | /zpool/nextcloud | Externally synchronized to a cloud account | + +The systemd integration achieves automatic sist2 scanning & indexing everyday at 3:00AM. + +### Tailoring the configuration for yourself + +`sist2-update-all.sh` calls update scripts for each sist2 index. Add or remove +update scripts accordingly to suit your need. Each update script (e.g. +`sist2-update-files.sh`) has important parameters laid down at the beginning so +make sure to edit them to point to your files and index locations. + +### Installation + +```bash +# install the services and scripts +sudo make install +# enable & start the timer +sudo systemctl enable sist2-update.timer +sudo systemctl start sist2-update.timer +# verify that the timer has been enabled +systemctl list-timers --all +``` + diff --git a/contrib/systemd/sist2-update-all.sh b/contrib/systemd/sist2-update-all.sh new file mode 100755 index 0000000..e116d8b --- /dev/null +++ b/contrib/systemd/sist2-update-all.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e +__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +echo "Update index: Files" +source ${__dir}/sist2-update-files.sh +echo "Update index: Nextcloud" +source ${__dir}/sist2-update-nextcloud.sh +echo "Done. Restarting sist2." +docker restart sist2-sist2-1 diff --git a/contrib/systemd/sist2-update-files.sh b/contrib/systemd/sist2-update-files.sh new file mode 100755 index 0000000..650de8c --- /dev/null +++ b/contrib/systemd/sist2-update-files.sh @@ -0,0 +1,34 @@ +#!/bin/bash +set -e +DATE=$(date +%Y_%m_%d) +CONTENT=/zpool/files +ORIG=/mnt/ssd/sist-index/files.idx +NEW=/mnt/ssd/sist-index/files_$DATE.idx +EXCLUDE='ZArchives|TorrentStore|TorrentDownload|624f0c59-1fef-44f6-95e9-7483296f2833|ubuntu-full-2021-12-07' +NAME=Files +#REWRITE_URL="http://localhost:33333/activate?collection=$NAME&path=" +REWRITE_URL="" + +sist2 scan \ + --threads 14 \ + --mem-throttle 32768 \ + --quality 1.0 \ + --name $NAME \ + --ocr-lang=eng+chi_sim \ + --ocr-ebooks \ + --ocr-images \ + --exclude=$EXCLUDE \ + --rewrite-url=$REWRITE_URL \ + --incremental=$ORIG \ + --output=$NEW \ + $CONTENT +echo ">>> Scan complete" +rm -rf $ORIG +mv $NEW $ORIG + +unset http_proxy +unset https_proxy +unset HTTP_PROXY +unset HTTPS_PROXY +sist2 index $ORIG --incremental=yes +echo ">>> Index complete" diff --git a/contrib/systemd/sist2-update-nextcloud.sh b/contrib/systemd/sist2-update-nextcloud.sh new file mode 100755 index 0000000..b17f478 --- /dev/null +++ b/contrib/systemd/sist2-update-nextcloud.sh @@ -0,0 +1,33 @@ +#!/bin/bash +set -e +DATE=$(date +%Y_%m_%d) +CONTENT=/zpool/nextcloud/v-yadli +ORIG=/mnt/ssd/sist-index/nextcloud.idx +NEW=/mnt/ssd/sist-index/nextcloud_$DATE.idx +EXCLUDE='Yatao|.*263418493\\/Image\\/.*' +NAME=NextCloud +# REWRITE_URL="http://localhost:33333/activate?collection=$NAME&path=" +REWRITE_URL="" + +sist2 scan \ + --threads 14 \ + --mem-throttle 32768 \ + --quality 1.0 \ + --name $NAME \ + --ocr-lang=eng+chi_sim \ + --ocr-ebooks \ + --ocr-images \ + --exclude=$EXCLUDE \ + --rewrite-url=$REWRITE_URL \ + --incremental=$ORIG \ + --output=$NEW \ + $CONTENT +echo ">>> Scan complete" +rm -rf $ORIG +mv $NEW $ORIG + +unset http_proxy +unset https_proxy +unset HTTP_PROXY +unset HTTPS_PROXY +sist2 index $ORIG --incremental=yes diff --git a/contrib/systemd/sist2-update.service b/contrib/systemd/sist2-update.service new file mode 100644 index 0000000..2688722 --- /dev/null +++ b/contrib/systemd/sist2-update.service @@ -0,0 +1,6 @@ +[Unit] +Description=sist2-update + +[Service] +User=yatli +ExecStart=/bin/bash /usr/bin/sist2-update-all.sh diff --git a/contrib/systemd/sist2-update.timer b/contrib/systemd/sist2-update.timer new file mode 100644 index 0000000..57b5bbc --- /dev/null +++ b/contrib/systemd/sist2-update.timer @@ -0,0 +1,10 @@ +[Unit] +Description=sist2-update + +[Timer] +OnCalendar=*-*-* 3:00:00 +Persistent=true +Unit=sist2-update.service + +[Install] +WantedBy=timers.target