Package: nextcloud_news_updater
This Python library is a parallel feed updater for theNextcloud News appNextcloud does not require people to install threading or multiprocessing
libraries. Because the feed update process is mainly limited by I/O, parallel
fetching of RSS feed updates can speed up the updating process significantly.In addition, Web Cron is not a supported cron setting since the update
process may time out.Therefore the News app provides an API that offers a more fine grained
control over updating feeds. This Python project implements an update
mechanism that is based on theupdater REST APIor (new in Nextcloud News 8.1.0) the
console based update API.DependenciesPre-InstallationInstallationInstallation Using PipManual InstallationNo InstallationUsageRunning The Updater As Systemd ServiceTroubleshootingHow Do I Enable Support For Self-Signed CertificatesCan I Run The Updater Using CronUsing The CLI Based Updater FailsWorking with Centos/RHELDependenciesPython >=3.5Pre-InstallationTo run the updates via an external threaded script the cron updater has to be
disabled. To do that go to the admin section an uncheck theUse Nextcloud
croncheckbox or opennextcloud/data/news/config/config.iniand set:useCronUpdates = trueto:useCronUpdates = falseInstallationThere are two different ways to install the updater:Installation using pip (recommended)Manual installationNo installationInstallation Using PipSince 8.2 the package is available on pypi for installation via pip (the
Python library package manager).To install pip on your distribution of choice,consolidate the pip
documentationNote: You need to install the Python 3 version of pipAfter installing pip, run:sudo pip3 install nextcloud_news_updater --install-option="--install-scripts=/usr/bin"To update the library, run:sudo pip3 install --upgrade nextcloud_news_updater --install-option="--install-scripts=/usr/bin"To uninstall the library run:sudo pip3 uninstall nextcloud_news_updaterManual InstallationIf you don’t want to install the updater via pip, you can install it manually.
This requires setuptools to be installed. On Ubuntu this can be done by running:sudo apt-get install python3-setuptoolsThen install the package like this:python3 setup.py install --install-scripts=/usr/binTo uninstall the updater run:python3 setup.py uninstallNo InstallationIf you do not want to install the script at all you can call it directly.Simply run the updater using:python3 -m nextcloud_news_updater /path/to/nextcloudUsageThere are two ways to run the updater:Using the console API (recommended):nextcloud-news-updater /path/to/nextcloudUsing the REST API (when running the updater on a different machine than Nextcloud):nextcloud-news-updater https://domain.com/path/to/nextcloud --user admin_user --password admin_passwordNote:admin_useris a user id with admin rights,admin_passwordthe user’s passwordYou can view all options by running:nextcloud-news-updater --helpusage: __main__.py [-h] [--threads THREADS] [--timeout TIMEOUT]
                   [--interval INTERVAL] [--apilevel {v1-2,v2,v15}]
                   [--loglevel {info,error}] [--config CONFIG]
                   [--phpini PHPINI] [--user USER] [--password PASSWORD]
                   [--version] [--mode {endless,singlerun}] [--php PHP]
                   [url]

positional arguments:
  url                   The URL or absolute path to the directory where
                        Nextcloud is installed. Must be specified on the
                        command line or in the config file. If the URL starts
                        with http:// or https://, a user and password are
                        required. Otherwise the updater tries to use the
                        console based API which was added in 8.1.0

optional arguments:
  -h, --help            show this help message and exit
  --threads THREADS, -t THREADS
                        How many feeds should be fetched in parallel, defaults
                        to 10
  --timeout TIMEOUT, -s TIMEOUT
                        Maximum number of seconds for updating a feed,
                        defaults to 5 minutes
  --interval INTERVAL, -i INTERVAL
                        Update interval between fetching the next round of
                        updates in seconds, defaults to 15 minutes. The update
                        timespan will be subtracted from the interval.
  --apilevel {v1-2,v2,v15}, -a {v1-2,v2,v15}
                        API level. Use v15 for News 15 or later, or v1-2 for
                        releases prior to that
  --loglevel {info,error}, -l {info,error}
                        Log granularity, info will log all urls and received
                        data, error will only log errors
  --config CONFIG, -c CONFIG
                        Path to config file where all parameters except can be
                        defined as key values pair. An example is in
                        bin/example_config.ini
  --phpini PHPINI, -P PHPINI
                        Custom absolute path to the php.ini file to use for
                        the command line updater. If omitted, the default one
                        will be used
  --user USER, -u USER  Admin username to log into Nextcloud. Must be
                        specified on the command line or in the config file if
                        the updater should update over HTTP
  --password PASSWORD, -p PASSWORD
                        Admin password to log into Nextcloud if the updater
                        should update over HTTP
  --version, -v         Prints the updater's version
  --mode {endless,singlerun}, -m {endless,singlerun}
                        Mode to run the updater in: endless runs the update
                        again after the specified interval, singlerun only
                        executes the update once
  --php PHP             Path to the PHP binary, e.g. /usr/bin/php7.0, defaults
                        to phpYou can also put your settings in a config file, looking like this:[updater]# only needed when using the REST APIuser=admin# only needed when using the REST APIpassword=adminthreads=10interval=900loglevel=error# or https://domain.com/nextcloud when using the REST APIurl=/path/to/nextcloudphpini=/path/to/custom/php.ini# or v2 which is currently a draftapilevel=v1-2mode=endless# path to php binaryphp=/usr/bin/php7.0Note: You can omit options in the config file if you want to use the defaults, but you can not have more than the allowed parameters present, otherwise an exception will abort the updater.Then run the updater with:nextcloud-news-updater -c /path/to/configNote: Command line parameters will always overwrite config parameters, so if you just want to change your loglevel to info for one run you can now do the following without globally changing the config file:nextcloud-news-updater -c /path/to/config --mode singlerun --loglevel infoRunning The Updater As Systemd ServiceAlmost always you want to run and stop the updater using your in init system.
As for Systemd, you can create a simple text file at/etc/systemd/system/nextcloud-news-updater.servicewith the following contents:[Unit]After=default.target[Service]Type=simpleUser=httpExecStart=/usr/bin/nextcloud-news-updater -c /etc/nextcloud/news/updater.ini[Install]WantedBy=default.targetThen to enable and start it run:sudo systemctl enable nextcloud-news-updater.service
sudo systemctl start nextcloud-news-updater.serviceNote: If you are using the cli based updater (as in set an absolute directory as url)
you need to set the web-server user as user in the unit file. Otherwise the command
will fail because Nextcloud checks for the owner of its files. This user
varies from distribution to distribution, e.g in Debian and Ubuntu you would use thewww-datauser:[Unit]After=default.target[Service]Type=simpleUser=www-dataExecStart=/usr/bin/nextcloud-news-updater -c /etc/nextcloud/news/updater.ini[Install]WantedBy=default.targetIf you are using the REST API, most of the time you can get away by usingnobodyas
user, but again, that might vary depending on your distribution.TroubleshootingIf you are having trouble debugging updater errors, try running it again using theinfologlevel:nextcloud-news-updater --loglevel info -c /path/to/config.iniHow Do I Enable Support For Self-Signed CertificatesIf you are using self-signed certificates, don’t. It’s very easy to sign your cert for free fromLets EncryptIf you still have to use a self-signed certificate no matter what, don’t patch the code to turn off certificate verification but rather globally add your certificate to the trusted certificates. Read up on your distributions documentation to find out how.Can I Run The Updater Using CronYes, you can by using the–mode singlerunparameter which will exit after one full update.However it’s your job to ensure, that the job will not be executed more than once at the same time. If update jobs overlap, theycan take down your system and/or serversince each new updater will slow down the previous ones causing more updaters to be spawned.If you can not ensure that the updater is run only one at a time use the default mode (–mode endless). This mode runs the update in a loop. You can control the update frequency through the–intervalparameter (orintervalusing a config file). The updater works in the following way:
* If a full update takes longer than the passed interval, another update will be run immediately afterwards
* If a full update took less than the passed interval, the updater will sleep for the remaining time and run an update afterwardsUsing The CLI Based Updater FailsThe updater uses the PHP executable to run the occ file inside your nextcloud directory. The general process boils down to the following:# delete folders and feeds marked for deletionphp-f/home/bernhard/programming/core/occnews:updater:before-update# get all feeds to udpatephp-f/home/bernhard/programming/core/occnews:updater:all-feeds# run all feed updatesphp-f/home/bernhard/programming/core/occnews:updater:update-feedFEED_IDUSER_ID# delete old articlesphp-f/home/bernhard/programming/core/occnews:updater:after-updateMost of the time there are two possible points of failure that can be debugged by using the–logelevel infoparameter:Most distributions uses differentphp.inifiles for your command line and web-server. This can manifest itself in weird errors like not being able to connect to the database. The solution is to either adjustphp.iniused for the CLI PHP or to use a differentphp.inialtogether by specifying the–phpiniparameter, e.g.:nextcloud-news-updater -c /path/to/config --phpini /etc/php/nextcloud-news-updater.iniThenews:updater:all-feedscommand returns invalid JSON. This can be due to due broken or missingphp.inisettings or PHP warnings/errors produced by Nextcloud. The solution to this issue can range from adjusting yourphp.ini(see previous point) to manually patching Nextcloud to remove the warnings from the output.Working with Centos/RHELSince Centos only provides Python 3.4, you can useSoftwareCollectionsto install a newer Python version.For example Python 3.5:https://www.softwarecollections.org/en/scls/rhscl/rh-python35/# 1. Install the Software Collection Repository$sudoyuminstallcentos-release-scl# 2. Install the collection:$sudoyuminstallrh-python35# 3. Start using software collections:$sclenablerh-python35bash# 4. Install nextcloud-news.updater$sudopip3installnextcloud_news_updater--install-option="--install-scripts=/usr/bin"After the install you can run the updater as a service by extending the service file with the correct environment variable for your Python version. In this example we use Python 3.5:[Unit]After=default.target[Service]Type=simpleUser=httpExecStart=/usr/bin/nextcloud-news-updater -c /etc/nextcloud-news-updater.iniEnvironment=LD_LIBRARY_PATH=/opt/rh/rh-python35/root/usr/lib64[Install]WantedBy=default.target