(For a while, this will probably be a hodge-podge)
On this page:
_VG = /public/vhost/g/gutenberg_FG = /public/ftp/pub/docs/books/gutenbergSomeone requests (e.g.) https://www.gutenberg.org/ebooks/12
_VG/html/.htaccess
has a RewriteRule that proxies the latter URL to
http://gutenberg2.ibiblio.org:8000/ebooks/12
(In what follows, _AC = /home/marcello/prj/autocat3)
On gutenberg2.ibiblio.org,
the app server
_AC/CherryPyApp.py
routes the /ebooks/12 path
to a BibrecPage instance.
The BibrecPage class is defined in
_AC/BibrecPage.py.
Its index method
constructs a BaseSearcher.OpenSearch instance os,
setting various properties. In particular:
It creates dc,
an instance of BaseSearcher.DC,
initializes it with the book's bib info via a call to dc.load_from_database,
and adds it to os.entries.
load_from_database
is defined (eventually) in
/usr/local/lib/python3.4/dist-packages/libgutenberg/GutenbergDatabaseDublinCore.py.
It executes lots of SQL commands to fill the instance's properties.
At the end, it calls load_files_from_database
to define the instance's files property
based on the rows for this ebook
in the database's files table.
We get an entry for "EPUB (with images)"
if one of those rows has fk_filetypes = 'epub.images'.
BaseSearcher.Cat
(holding various related info: similar books, bookshelves, ...)
os.template to 'bibrec'
(unless the user is using the mobile site?),
which causes _AC/templates/bibrec.html
to be chosen to generate the HTML.
The index method then passes os to Page.Page.format for rendering in HTML.
_AC/templates/bibrec.html
mostly controls what HTML to generate.
bs.DC in os.entries, generates a "Bibliographic Record" table.bs.Cat in os.entries, generates a 'more stuff' div.bs.DC in os.entries, generates a "Download This eBook" table
(iterating over the instance's files list).
The database's files table
reflects the contents of the filesystem.
Every day at 1am,
Marcello's crontab invokes _VG/private/bin/cron-rebuild-files,
which invokes ebookconverter --build=all
on a range of 2000 ebooks,
designed to cover the whole collection once a month.
(So, once we get to #56000, some books will be processed only in longer months, and once we get to #62000, some books will never be processed. As of 2017-03-26, we're at #54433 and growing by maybe 200 per month, so we should change the scheme before the end of 2017.)
Anyhow, ebookconverter
(_VG/local/bin/ebookconverter,
source mostly in
_VG/local/lib/python3.4/site-packages/ebookconverter/)
is a Python program
that invokes ebookmaker,
that creates (among other things) one RDF file per ebook:
_VG/html/cache/epub/$num/pg$num.rdf
Then, every day at 5am,
Marcello's crontab invokes _VG/private/bin/cron-rdf-catalog.
On Thursdays, this first invokes ebookconverter --build=rdf ...
But every day,
it finds all the RDF files under _VG/html/cache/epub,
makes a tar file of them (_VG/private/tmp/rdf/rdf-files.tar),
compresses that using zip and bzip2,
and puts the results at
_VG/html/cache/epub/feeds/rdf-files.tar.{bz2,zip}
See the Special:Version page for lots of useful information.
Currently, _VG/html/w is a symlink to _VG/html/mediawiki-1.23.
_VG/html/w/LocalSettings.php has a section entitled "Gutenberg Customization".
Among other things, it says:
require_once ("$IP/skins/GutenBook/GutenBook.php");
require_once ("$IP/skins/GutenVector/GutenVector.php");
$wgDefaultSkin = 'gutenvector';
which pulls in 2 skins,
GutenBook and GutenVector
(defined in their respective subdirectories of _VG/html/w/skins),
and then sets GutenVector as the default.
GutenVector is Marcello's extension of MediaWiki's Vector skin.
_VG/html/w/LocalSettings.php also says:
require_once ("$IP/extensions/EmailAddressImage/EmailAddressImage.php");
require_once ("$IP/extensions/Cite/Cite.php");
require_once ("extensions/QRCode.php");
require_once ("extensions/QRCodeInline.php");
require_once ("extensions/IFrame.php");
which defines 5 tag extensions:
<ref> and <references> for adding citations to pages.
<email>foo@domain.com</email>
results in the inline insertion of an image with the text foo@domain.com
<qrcode> generates a <div> that shows a QR code,
via <img src='https://chart.googleapis.com/...'/>
<qrcodeInline> generates a <div> that shows a QR code,
via <img src='data:image/png;base64,...'/>.
(The PNG image data is obtained by fetching http://gutenberg2.ibiblio.org:8000/qrcode/...)
<iframe>
The wiki uses a MariaDB database.
For database connection details (including password),
look in _VG/html/w/LocalSettings.php
for variables $wgDBserver etc
To connect to the server from login1, invoke:
source /opt/rh/rh-mariadb100/enable
(Better, put it in your .bashrc or .bash_profile or .profile.) This adds mysql-related stuff to your environment. Then:
mysql --host=mysql.ibiblio.org --database=gutenberg_wiki --user=gutenberg -p
and enter the password when prompted. This starts the mysql/MariaDB client.
Every day at 2am,
Marcello's crontab invokes _VG/private/bin/cron,
which (among other things) invokes
_VG/private/bin/wikibackup
and
_VG/private/bin/wikidump.
_VG/private/bin/wikibackup:
mysqldump
on the gutenberg_wiki database,
which generates a file of SQL commands
that could reconstruct the whole database from scratch.
This is run through bzip2 and put in
_VG/private/sqlbackups/$DATE-wikibackup.sql.bz2.
backups/sql/ directory.
wikibackup files
into _VG/private/sqlbackups/monthly/.
_VG/private/sqlbackups/
that are older than 2 months.
_VG/private/bin/wikidump:
_VG/html/w/maintenance/dumpBackup.php,
which generates an XML document
that records the current revision of each page in the wiki.
This is run through bzip2 and put in
_VG/private/sqlbackups/$DATE-wikidump.bz2.
backups/sql/ directory.
wikidump files
into _VG/private/sqlbackups/monthly/.
_VG/private/sqlbackups/
that are older than 2 months.
I'm not sure why we need
wikidump.bz2,
since it appears to contain just a subset of the info in
wikibackup.sql.bz2.
Before compression, wikibackup.sql
is about 50 times bigger than
wikidump.
After compression, it's about 30 times bigger.
MediaWiki's wiki describes the upgrade process here. Note that some of that page assumes you're doing an in-place upgrade (i.e., the new files overwrite the old), which is not what we do. For a not-in-place upgrade (where the new files are in a separate directory from the old), the preferred procedure is somewhat buried here. Here's my procedure:
cd /public/vhost/g/gutenberg/html
old=mediawiki-1.23
new=mediawiki-1.28.2
cp -p $old/LocalSettings.php $new/
cp -p -r $old/images/[a-z0-9]* $new/images/
# restrict to [a-z0-9]* to avoid overwriting images/{.htaccess,README}
cp -p -r $old/skins/Guten* $new/skins
# extensions:
# Cite is bundled.
cp -p -r $old/extensions/EmailAddressImage/ $new/extensions/
cp -p $old/extensions/{IFrame,QRCode,QRCodeInline}.php $new/extensions/
# No custom logo-image.
# No top-level .htaccess
LocalSettings.php,
make any necessary changes.
Delete:
$wgEnableSorbs = true; (dropped in 1.24)
$wgDisableCounters = true; (dropped in 1.25)
$wgSessionsInObjectCache = true; (deprecated + always-true since 1.26)
http://www.gutenberg.org/mediawiki-1.28.2/).
But note that, at this point, following links will generally send you to the old code.
source scl_source enable rh-php56 # This adds 'php' to your path.
php $old/maintenance/runJobs.php # no output, exits after about 3 seconds
# Have to do this before you put the wiki in read-only mode.
LocalSettings.php, put the wiki into read-only mode.
(This will only be visible to users if they try to edit a page.)
$wgReadOnly = '2017-06-26: Upgrading to MediaWiki 1.28.2!';
php $new/maintenance/update.php | tee $new/update_output.jmdyck.txt
# ... a few pages of output, then:
# Done in 23 s.
At this point, users may get "A database query error has occurred. This may indicate a bug in the software.", so proceed quickly to the next step.
rm w && ln -s mediawiki-1.28.2 w
Later, ...
_VG/private/lib/python/autocat/BookshelfScraper.py
stopped working properly.
It uses the MediaWiki 'action API' to get "bookshelf" pages and their content,
and after the upgrade, the API queries started to receive only partial results.
See here
for some discussion of limits,
and here
for how to get the whole result-set when it is truncated due to limits.
I modified the BookshelfScraper.py accordingly.
Many pages (e.g.,
Animal_(Bookshelf))
would show the text "Favorite-icon-16x16.png"
rather than rendering the icon itself.
Ultimately, this was because every request for the image
https://www.gutenberg.org/w/images/8/86/Favorite-icon-16x16.png
would result in a 302-redirect to
http://www.gutenberg.org/files/86/Favorite-icon-16x16.png,
which doesn't exist.
The bizarre rewriting of w/images/8 to files
was eventually traced to
mediawiki-1.28.2/images/.htaccess:
when its RewriteRule was commented out,
the redirect stopped happening.
MediaWiki task T30235
describes why the Rewrite stuff is there,
and it seems reasonable enough (modulo IE6).
But why it caused the redirect for us makes no sense.
Apparently it's an Apache bug:
see MW task T64289,
where people complain of similarly odd (though not identical) behaviour
caused by the rewrite.
However, the fix for that bug
(adding Options +FollowSymLinks to the .htaccess file)
doesn't work for us
(and it's not clear to me why it worked for anyone).
Anyhow, in the end, our solution was to
take the .htaccess file out of the picture:
mv .htaccess .htaccess.orig.moved_aside
What is the mechanism by which CAPTCHAs are triggered?
_VG/html/.htaccess
has a couple of RewriteRules
that rewrite (some) requests for dirs/.* and cache/epub/.*
into ratelimiter.php/....
_VG/html/ratelimiter.php
is a symbolic link to
_VG/html/ratelimiter2.php
_VG/html/ratelimiter1.php,
which appears to be an older, simpler version of _VG/html/ratelimiter2.php.
I don't think it's used any more.)
_VG/html/ratelimiter2.php
is that it performs an Apache sub-request for the original URL.
However, it first runs various checks that might cause something else to happen.
The most notable of these are redirect_deep_links() and rate_limit().
_VG/html/catalog/world/*.php
start with a call to rate_limit().)
rate_limit() is defined in _VG/private/lib/php/ratelimiter.phh.
It sends a HEAD request to http://gutenberg2.ibiblio.org:8000/iplimit/
rate_limit(),
we receive the response to the HEAD request and examine it.
If the response contains the header X-Ratelimiter-Denied,
then the function 307-redirects the original request to
http://www.gutenberg.org/w/captcha/question/
_VG/html/.htaccess
has a RewriteRule that rewrites the latter URL to
http://gutenberg2.ibiblio.org:8000/w/captcha/question/
with the 'P' flag for "Proxy"...
_VG/html/.htaccess
has a few RewriteRules that proxy certain gutenberg.org URLs
to http://gutenberg2.ibiblio.org:8000/...
(I think this mainly applies to URLs whose path-part starts with /ebooks
that haven't already been rewritten to /cache/epub URLs.)
gutenberg2.ibiblio.org,
/etc/init/autocat3.conf
ensures that there's always a python3 process
running /home/marcello/prj/autocat3/CherryPyApp.py.
It's an app server that listens on port 8000.
/var/log/autocat/
gutenweb{1-5}.int.ibiblio.org
(AKA gutenweb{1-5}.lb.ibiblio.org)
These are virtual hosts.
(Currently, 1-3 are running CentOS 6.8 on oVirt,
and 4+5 are running CentOS 7.0 on VMware.
Eventually, 1-3 will migrate to the latter.)
/public/scratch/logs/hosted_sites/www.gutenberg.org/,
which we can see.
Each of gutenweb{1-3} creates
4 access.log.$date.gz files per day
(one each for
gutenberg.org,
m.gutenberg.org,
server [for gutenberg.net], and
ssl.server [which appears to have identical content to server])
and also creates a varnish file.
For the most part, the requests logged in the varnish file are
a superset of the requests logged in the various access.log files
(although there are slight differences in how they are logged).
Thus, it suffices to analyze the varnish file.
Each of gutenweb{4-5} creates
3 access.log.$date.gz files per day
(one each for
gutenberg.org,
m.gutenberg.org, and
gutenberg.net?)
_VG/private/bin/cron-analog,
which:
_VG/private/bin/cron-topten,
which is a symlink to
_VG/private/lib/python/stats/cron-topten,
which:
_VG/private/lib/python/stats/CountDownloads.py --date=[yesterday],
which counts how often each book was (successfully) requested
(by a non-robot)
and updates db tables
scores.book_downloads,
books,
scores.filetype_downloads, and
scores.also_downloads.
_VG/private/lib/python/stats/stats_google.py,
which extracts data from the database,
sends it to http://chart.apis.google.com/, and
writes the results to _VG/html/browse/scores/filetypes{,-sum}{,-100}.png
_VG/html/catalog/admin/make-topten.php,
which extracts data from the database
and generates _VG/html/browse/scores/top*.php
(one for each language, plus 2 more).
_VG/private/bin/analog/cron.pl --copy --daily,
which:
_VG/private/logs/apache/
(which we keep for about a month); and
_VG/private/bin/analog/analog twice
to generate
_VG/html/internal/stats/$year/$month/$day-pages.html.gzip
and
_VG/html/internal/stats/$year/$month/month-pages.html.gzip
(which we keep forever).
If, for whatever reason, there are logs in
/public/scratch/logs/hosted_sites/www.gutenberg.org/
that didn't get processed,
you can catch up with commands such as:
cd /public/vhost/g/gutenberg/private/bin
. ./env
export PGPORT=5432
./cron-topten 2016-09-01
./analog/cron.pl --copy --daily --date=2016-09-01
(Note that when you invoke cron-topten
with a specific date argument like that,
it skips the last 2 steps,
i.e. it doesn't call make-topten.php or email a report.
Expect it to take about 13 minutes to run.)
(Hm, it looks like cron.pl
only works if you're marcello,
due to directory permissions.)
Postgres
psql --host gutenberg-pg1.int.ibiblio.org --username gutenberg --dbname gutenberg
gutenberg=> \dt
List of relations
Schema | Name | Type | Owner
--------+----------------------+-------+-----------
public | aliases | table | gutenberg
public | attriblist | table | gutenberg
public | attributes | table | gutenberg
public | author_urls | table | gutenberg
public | authors | table | gutenberg
public | books | table | gutenberg
public | bookshelves | table | gutenberg
public | categories | table | gutenberg
public | changelog | table | gutenberg
public | compressions | table | gutenberg
public | dcmitypes | table | gutenberg
public | dpid | table | gutenberg
public | encodings | table | gutenberg
public | filecount | table | gutenberg
public | files | table | gutenberg
public | filetypes | table | gutenberg
public | fts | table | gutenberg
public | langs | table | gutenberg
public | loccs | table | gutenberg
public | mirrors | table | gutenberg
public | mn_books_authors | table | gutenberg
public | mn_books_bookshelves | table | gutenberg
public | mn_books_categories | table | gutenberg
public | mn_books_langs | table | gutenberg
public | mn_books_loccs | table | gutenberg
public | mn_books_subjects | table | gutenberg
public | mn_users_permissions | table | gutenberg
public | permissions | table | gutenberg
public | roles | table | gutenberg
public | subjects | table | gutenberg
public | terms | table | gutenberg
public | tweets | table | gutenberg
public | users | table | gutenberg
(33 rows)
/home/push on pglaf.org.
/home/gbnewby/.bin/dopush.sh,
which goes to /home/push, and for each zip file it finds there,
does the following:
~gbnewby/.tmp/pg-upload/ on
login.ibiblio.org.
~gbnewby/ftp/$numpath/
and then discard it.
~gbnewby/ftp is a symlink to
_FG/
$numpath denotes a path within the PG post-10k hierarchy.
E.g., for $num = 12345, $numpath = 1/2/3/4/12345
_VG/private/logs/dopush/$num.zip.trig
/home/gbnewby/logs/dopush-log.txt
_VG/private/bin/cron-dopush,
which:
_VG/private/lib/python/autocat/FileInfo.py,
which looks in _VG/private/logs/dopush
for $num.zip.trig files, and for each, calls scan_directory, which:
_VG/html/files/$num/
(which is a symlink to _FG/$numpath)
for files, and for each:
scan_file or scan_zip, which ... prints file metadata_VG/private/bin/bitcollider-0.6.0 in a subprocess and then prints out various hashes$num.zip.trig file to _VG/private/logs/dopush/backup/
FileInfo.py is piped to autocat.php)
_VG/private/lib/python/autocat/autocat.php,
which takes in the output of FileInfo.py
(echoing it to stdout),
breaks it into sections
(one per file in _VG/html/files/$num/),
extracts info from the lines,
and updates the database
(adding a few lines per file to stdout).
_VG/private/lib/python/autocat/AutoDelete.py,
which extracts filenames from the database,
checks which files still exist in the filesystem,
and updates the database for any which don't.
_VG/local/bin/ebookconverter -v --range=1- --goback=24 twice:
once with --make=all and
once with --build=facebook --build=twitter
http://gutenberg2:8000/covers/small/latest/10,
saves it in _VG/html/cache/latest-covers.html.utf8,
and zips that up into _VG/html/cache/latest-covers.html.utf8.gzip.
If an ebook's auto-generated content is not appearing in the catalog,
/home/gbnewby/logs/dopush-log.txt.
Scan for the ebook number to find the record(s) of it being pushed.
You might see something like:
checkdir error: cannot create 52674/52674-h/images
File exists
unable to process 52674/52674-h/images/img-cover.jpg.
I don't know why the images dir would already exist,
or why its pre-existence would cause unzip to fail to put an image file in it,
but the absence of a cover-page image
will cause the auto-generation of epub and kindle versions to fail.
You should be able to fix it (at least partly) by re-pushing the file:
sudo mv /home/DONE/$num.zip /home/push
and wait for the next run of pglaf's dopush.
cron-dopush
should handle the FileInfo and autocat
processing for the re-push.
However, when it invokes ebookconverter,
that might or might not take care of rebuilding the missing files.
(Check _VG/private/logs/epub-maker/$timestamp.log.)
If it's been less than 24 hours since the problematic push,
the files will probably be generated.
If not, you should be able to do it yourself (on ibiblio.org):
source /public/vhost/g/gutenberg/private/bin/env
$LOCAL/bin/ebookconverter -v --make=all --range=$num
You should get a single line of output of the form:
Logging to: /public/vhost/g/gutenberg/private/logs/epub-maker/$timestamp.log
Look at that file, and also
_VG/html/cache/epub/$num/pg$num.converter.log,
but note that the latter may start with earlier output.
~gbnewby~gbnewby/.tmp/pg-upload/
- landing area for zipfiles pushed from pglaf.org
_FG (/public/ftp/pub/docs/books/gutenberg/)etext?? - The pre-10k directory structure[0-9] - The post-10k directory structureGUTINDEX.* - indexescache/generated - symlink to _VG/html/cache/epub_VG (/public/vhost/g/gutenberg)mobile - the mobile web sitehtml - the non-mobile web site
html/books and html/ftp
- both are symlinks to _FG/
html/cache/epub/$num/
- directory of generated files for ebook #$num
(not just EPUBs, that's a misnomer)
html/cache/epub/$num/pg$num.converter.log
- logging output from ebookmaker runs
html/dirs/
- contains lots of symlinks, mostly to items in _FG/
(Why isn't dirs simply a link to _FG itself?)
html/files/$num/
- symlink to _FG/$numpath/
static - CSS, Javascript, and image files that get copied into the web siteslocal - mostly third-party non-PG-specific software, mostly in C and python, mostly for document processing.
Includes a few PG-specific things you might not consider third-party:
epubmaker/ebookmaker, ebookconverter, libgutenberg.private - mostly PG-specific software for maintaining the collection and the site
private/bin/
- a directory of scripts, mostly invoked via cron
private/logs/dopush/$num.zip.trig
- an empty file whose existence tells cron-dopush to do something.
private/logs/dopush/backup/$num.zip.trig
- an empty file that indicates cron-dopush did something.
private/logs/epub-maker/$timestamp
- logging output from ebookconverter runs
Things a webmaster needs: