You are browsing a read-only backup copy of Wikitech. The live site can be found at wikitech.wikimedia.org
Scap
thcipriani@tin:~$ scap fortune | scap say
------------------------------------------------
/ \
| S.C.A.P.: scatter crap around production |
\ /
------------------------------------------------
\
\
\
___ ____
⎛ ⎛ ,----
\ //==--'
_//|,.·//==--' ____________________________
_OO≣=- ︶ ᴹw ⎞_§ ______ ___\ ___\ ,\__ \/ __ \
(∞)_, ) ( | ______/__ \/ /__ / /_/ / /_/ /
¨--¨|| |- ( / ______\____/ \___/ \__^_/ .__/
««_/ «_/ jgs/bd808 /_/
scap
is the Wikimedia deployment tool. Scap started life as a series of shell scripts written around 2004. Prior to 2004, the code was loaded from an NFS-mount ("insta-deployment") on the Apache servers. It was ported from Bash to Python in 2013. Starting in late 2015 it was modified to support the use-case of deploying software beyond just MediaWiki. Previously, other software was deployed with salt-based git-deployment tool called Trebuchet.
Scap is used for:
Usage
As of July 2017 there are two sets of operations that can be preformed by scap
:
MediaWiki Deployments
Basic commands.
scap pull
- Performs the action only on the one server on which the command is run
- syncs
/srv/mediawiki-staging
from a deployment rsync server->/srv/mediawiki
on the local server - This action was formerly run as
sync-common
scap sync-file
- This is an all-script!
- for a single file
- checks PHP syntax
- syncs
/srv/mediawiki-staging/(some file)
->/srv/mediawiki
scap sync-wikiversions
- This is an all-script!
- syncs
/srv/mediawiki-staging/wikiversions.{json,cdb}
->/srv/mediawiki
scap sync
- This is an all-script!
- "sync-common-all-php"
- lints PHP files in
./wmf-config
,./multiversion
- Sync deploy directory (/srv/mediawiki-staging) on localhost with staging area (/srv/mediawiki)
- for all mediawiki versions currently deployed (usually 2) it:
- rebuilds localization caches of core and extensions
- creates json files from localization caches for better rsync performance
- runs scap pull on co-master servers to update
/srv/mediawiki-staging
- runs scap pull on rsync fanout servers to update
/srv/mediawiki
- runs scap pull on "all" servers to update
/srv/mediawiki
from nearest rsync proxy - rebuilds localization caches on "all" servers from json files that were synced by scap pull
rsync
is not the optimal tool forcdb
files, so json is synced and cdb files are built from those
- compiles wikiversions.json to wikiversions.cdb on localhost
- runs scap sync-wikiversions
SWAT deploys
SWAT deploys are small code deployment windows that happen 3 times per day in #wikimedia-operations connect on Freenode. SWAT deploys use the commands above to merge and deploy code. For more detailed instructions there is a page that details how to run a SWAT deployment
Other software deployments
Scap is capable of deploying software other than MediaWiki. These commands are meant to be run from the active deployment server in the directory for the repo you are deploying. These repos are all sub-directories of /srv/deployment
. For example, Parsoid is deployed from the directory /srv/deployment/parsoid/deploy
scap deploy
- This is a deployment-server-script!
- Uses git to sync deployment-server:
/srv/deployment/[repo]
-> targets:/srv/deployment/[repo]
- Syncs in 5 separate stages
config-deploy
(optional/requires configuration) - uses templates in the/srv/deployment/[repo]/scap
directory to deploy a configuration file on the targetsfetch
- Usesgit fetch
to fetch code from thedeployment-server
to a local cache repo (for example:target:/srv/deployment/parsoid/deploy-cache/cache
)promote
- Uses
git clone
to create a checkout of the current repo in the state it's in on thedeployment-server
(for example: it will make a checkout intarget:/srv/deployment/parsoid/deploy-cache/revs/xxxxxxxxxxxxxxxxxxxxx
) - Creates symlink on target from revision to final location (for example: it will make a symlink
target:/srv/deployment/parsoid/deploy-cache/revs/xxxxxxxxxxxxxxxxxxxxx
->target:/srv/deployment/parsoid/deploy
)
- Uses
service_restart
(optional) - if aservice_name
is specified inscap/scap.cfg
that service will be restartedfinalize
- removes files on targets used for rollback.
Usage
usage: scap deploy [-h] [-v] [--environment ENVIRONMENT]
[-r REV] [-l LIMIT_HOSTS] [-f] [--dry-run]
[--service-restart] [-i] [message [message ...]]
Sync new service code across cluster.
positional arguments:
message Log message for SAL
optional arguments:
-h, --help show this help message and exit
-r REV, --rev REV Revision to deploy
-l LIMIT_HOSTS, --limit-hosts LIMIT_HOSTS
Limit deploy to hosts matching expression
-f, --force force re-fetch and checkout
--dry-run Compile and deploy config files to a temp location and
output a diff against the previously deployed config
files.
--service-restart Restart service
-i, --init Setup a repo for initial deployment
Examples
# show verbose output:
scap deploy -v "Updating repo"
# deploy using configuration inside scap/environments/staging/scap.cfg
scap deploy --environtment staging
# deploy only to the scap-target-01 host
scap deploy -l 'scap-target-01'
# deploy only to the 5 hosts [scap-target-01..scap-target-05]
scap deploy -l 'scap-target-[01:05]'
# deploy to all hosts EXCEPT those in eqiad
scap deploy -l '!scap-target-*.eqiad.wmnet'
deployer@tin:/srv/deployment/foo/deploy$ scap deploy
20:46:12 Started deploy_foo/deploy
Entering 'foo'
20:46:12
== DEFAULT ==
:* scap-target-07
:* scap-target-08
:* scap-target-09
:* scap-target-04
:* scap-target-05
:* scap-target-06
:* scap-target-10
:* scap-target-01
:* scap-target-02
:* scap-target-03
deploy_foo/deploy_config_deploy: 100% (ok: 10; fail: 0; left: 0)
deploy_foo/deploy_fetch: 100% (ok: 10; fail: 0; left: 0)
deploy_foo/deploy_promote: 100% (ok: 10; fail: 0; left: 0)
20:46:42 Finished deploy_foo/deploy (duration: 00m 29s)
scap deploy --service-restart
- This is a deployment-server-script!
- If a
service_name
is defined inscap/scap.cfg
, the--service-restart
command can be used to restart a service on all targets
Usage
deployer@tin:/srv/deployment/foo/deploy$ scap deploy --service-restart -v "Restarting for Upgrade"
17:17:30 Started restart [foo_deploy/deploy@61368b4]
17:17:30 Deploying Rev: 61368b4253c9f6a5d2d62d482319d644b31791f0
17:17:30 Prepare config deploy
17:17:30 Config deploy file: /srv/deployment/foo/deploy/scap/config-files.yaml
17:17:30 Update DEPLOY_HEAD
17:17:30 Creating /srv/deployment/foo/deploy/.git/DEPLOY_HEAD
17:17:30 Update server info
Entering 'foo'
17:17:30 Started restart [foo/deploy@61368b4]: Restarting for Upgrade
17:17:30
== DEFAULT ==
:* scap-target-07
:* scap-target-08
:* scap-target-09
:* scap-target-04
:* scap-target-05
:* scap-target-06
:* scap-target-10
:* scap-target-01
:* scap-target-02
:* scap-target-03
17:17:30 Running remote deploy cmd ['scap', 'deploy-local', '-v', '--repo', 'foo/deploy', '-g', 'default', 'restart_service', '--refresh-config']
foo/deploy: restart_service stage(s): 100% (ok: 10; fail: 0; left: 0)
17:17:44
== DEFAULT ==
:* scap-target-07
:* scap-target-08
:* scap-target-09
:* scap-target-04
:* scap-target-05
:* scap-target-06
:* scap-target-10
:* scap-target-01
:* scap-target-02
:* scap-target-03
17:17:44 Running remote deploy cmd ['scap', 'deploy-local', '-v', '--repo', 'foo/deploy', '-g', 'default', 'finalize', '--refresh-config']
foo/deploy: finalize stage(s): 100% (ok: 10; fail: 0; left: 0)
17:17:55 Finished restart [foo/deploy@61368b4] (duration: 00m 24s)
scap deploy-log
- This is a deployment-server-script!
The scap deploy-log command provides powerful filters for the scap deploy logs.
The main deploy application sends all structured log output to a file under scap/log/git-tag.log. deploy-log is meant to run during or after a deploy, potentially in a separate terminal. Log entries can be filtered on one or more fields using a given free-form expression. By default scap deploy-log will periodically scan the scap/log directory for new files and immediately begin tailing any newly discovered log file.
As an alternative to the default behavior, you can either specify the log file to parse via the scap deploy-log --file option or choose the newest log file by using scap deploy-log --latest; in this case, it will simply filter the entire file for matching records and exit, rather than watching for more log files to be created.
The default behavior is convenient for monitoring an ongoing deployment from a separate terminal. Simply start scap deploy-log in a separate terminal prior to running scap deploy. Once your deployment starts, scap deploy-log will discover the new log file and immediately begin displaying relevant log messages
Usage
scap deploy-log [--file <file>] [--latest] [-v] [expr]
scap deploy-log [--file <file>] [--latest] [-v] [expr]
-f <file>, --file <file>
Used to explicitly specify the log file to be parsed. If no file is specified then deploy-log will automatically open any newly created log files and immediately begin outputting any matching log messages.
-l, --latest
Parse and filter the latest log file, exiting once the entire file has been processed.
-v, --verbose
Produce verbose output
expr
Optional filter expression which is used to match log entries in <file>
Examples
# show verbose output:
scap deploy-log -v
# tail the most recent log file:
scap deploy-log --latest
# show log messages for the host named scap-target-01
scap deploy-log 'host == scap-target-01'
# show log messages matching a regex pattern:
scap deploy-log 'msg ~ "some important (message|msg)"'
# show WARNING messages for hosts whose name begins with "scap-target-"
scap deploy-log 'levelno >= WARNING host == scap-target-*'
Deployment-server-script
A deployment-server-script is a script that is meant to be run from the active deployment server that operates on target boxes via ssh.
All-script
An all-script is a deployment-server-script that operates on mediawiki-installation boxes via ssh. These scripts performs the action on all (relevant) servers.
The specific servers include:
- app servers
- image scalers
- job runners (Job queue)
Wholesome Fun
bd808@silver:~$ scap fortune | scap say
------------------------------------------------
/ \
| S.C.A.P.: someone can always pontificate |
\ /
------------------------------------------------
\
\
\
___ ____
⎛ ⎛ ,----
\ //==--'
_//|,.·//==--' ____________________________
_OO≣=- ︶ ᴹw ⎞_§ ______ ___\ ___\ ,\__ \/ __ \
(∞)_, ) ( | ______/__ \/ /__ / /_/ / /_/ /
¨--¨|| |- ( / ______\____/ \___/ \__^_/ .__/
««_/ «_/ jgs/bd808 /_/