Jump to content

Tool:Verification pages

From Wikitech
Toolforge tools
Verification pages
Description Generates verification pages for users to verify statements about politicians for entry into Wikidata.
Keywords verification, wikidata
Author(s) mySociety Democratic Commons Team
Maintainer(s) (View all)
Source code https://github.com/mysociety/verification-pages
License No license specified

Controlling the service

Start

become verification-pages
webservice --backend=kubernetes ruby2 start /data/project/verification-pages/verification-pages/script/toolforge-start

Stop

become verification-pages
webservice --backend=kubernetes ruby2 stop

Update code and restart

Toolforge doesn't currently, at least as far as I understand, offer zero-downtime deploys, so there will be a short time while deploying where the webapp will return a 502 error. This should resolve itself once the Kubernetes pod has started up correctly.

become verification-pages
webservice shell
cd verification-pages
git pull
bundle check || bundle install
bin/rails db:migrate assets:precompile
^D
webservice --backend=kubernetes ruby2 restart

tools.verification-pages@tools-sgebastion-07:~$ webservice --backend=kubernetes ruby2 shell Pod is not ready in time tools.verification-pages@tools-sgebastion-07:~$ webservice --backend=kubernetes ruby2 shell Traceback (most recent call last):

 File "/usr/local/bin/webservice", line 198, in <module>
   job.shell()
 File "/usr/lib/python2.7/dist-packages/toollabs/webservice/backends/kubernetesbackend.py", line 457, in shell
   pykube.Pod(self.api, podSpec).create()
 File "/usr/lib/python2.7/dist-packages/pykube/objects.py", line 76, in create
   self.api.raise_for_status(r)
 File "/usr/lib/python2.7/dist-packages/pykube/http.py", line 104, in raise_for_status
   raise HTTPError(payload["message"])

pykube.exceptions.HTTPError: object is being deleted: pods "interactive" already exists

Sometimes bundle install can error due to https://github.com/bundler/bundler/issues/4367. running bundle install --jobs 1 should eventually work.

Sometimes when running that last restart command you'll see a Python stacktrace from the webservice tool. This appears to be harmless, but it's prudent to check that the service has correctly by checking the running pods and viewing the logs for the service using the Kubernetes commands below.

Kubernetes commands

Check which pods are running

kubectl get pods

View logs for a pod

First copy the pod name from the output of kubectl get pods and then run:

kubectl logs -f <POD-NAME>

Errors starting the webservice

Be sure to use the full start command otherwise you might see an error similar to:

Traceback (most recent call last):
 File "/usr/bin/webservice-runner", line 30, in <module>
   webservice.run(port)
 File "/usr/lib/python2.7/dist-packages/toollabs/webservice/services/genericwebservice.py", line 18, in run
   os.execv('/bin/sh', ['/bin/sh', '-c', self.extra_args])
TypeError: execv() arg 2 must contain only strings

Cron jobs

In order to install the crontab I ran the following commands:

become verification-pages
crontab -e

Then I added the following crontab entry, which refreshes all prompts at 05:00 UTC:

0 5 * * *  /usr/bin/jsub -N cron-tools.verification-pages-1 -once -quiet /data/project/verification-pages/verification-pages/script/toolforge-cron.daily

That runs ./script/toolforge-cron.daily from the verification-pages repo, which currently just runs the script to pull in new statements from suggestions-store.