Jump to content

Maintenance server

From Wikitech
mwmaint servers are one of the four high-level deployments of MediaWiki at WMF.

Maintenance servers are where we run scheduled and ad-hoc command-line scripts relating to MediaWiki.

Service

As of June 2024, the servers are:

We manage the scheduling in Puppet (puppet: profile/mediawiki/maintenance.pp), where we declare which scripts to run, when and how often, and what wikis to run them on. As of 2020, the scripts are run via systemd timers. Previously, we used cron to run the maintenance jobs.

To run maintenance scripts on the Beta Cluster you need to connect to the equivalent servers on deployment-prep. E.g.:

deployment-mwmaint02.deployment-prep.eqiad1.wikimedia.cloud

Runbook

Run a maintenance script on a wiki

When running a long-running maintenance script, consider using screen.

To run a maintenance script, log into the active maintenance server.

Use the mwscript command-line utility:

mwscript scriptname.php --wiki dbname 

The above command will run the script scriptname.php located in the /maintenance directory of the specified wiki's php directory.

You can also use a path relative to root of the MediaWiki installation, for example to run a script from an extension rather than core. It is recommended that in this case you first browser to one of the MediaWiki directories to allow for tab completion:

$ cd /srv/mediawiki/php-1.xx-wmf.xx/
$ mwscript extensions/MyExtension/maintenance/scriptname.php --wiki dbname

If you need to pass parameters to your maintenance script, you can add them to the end. You may also want to explicitly declare the database parameter to avoid confusion:

mwscript scriptname.php --wiki=enwiki --days=1

In this case, the wiki parameter is handled by mwscript and the 'days' parameter is handled by scriptname.php. The "wiki" must be in wikiversions.json so the maintenance script machinery can figure out what MediaWiki version it is running.

Many maintenance scripts are used to run heavy database queries; remember to check the replication lag and other possible byproducts.

Run a custom maintenance script

You can also run an arbitrary PHP file outside the MediaWiki directory as a maintenance script. Typically this is done to test changes to maintenance scripts that cannot be done locally, or to avoid having to wait for a train deployment / doing a backport when running the fixed version of a maintenance script.

mwscript /home/foo/scriptname.php --wiki=enwiki

will run /home/foo/scriptname.php with the MediaWiki root directory set to whichever directory enwiki is served from (so all other files and classes referenced in the script will be loaded from their standard location).

Use this responsibly. The privilege policy applies here as well: you should not run non-trivial code in production that wasn't reviewed by at least one other person. Make sure that, if something goes wrong, others can reconstruct exactly what code was executed (e.g. by saying !log T12345 running mwscript /home/foo/scriptname.php --wiki=enwiki on IRC).

See also