-
Notifications
You must be signed in to change notification settings - Fork 1
Python Management Commands
Siqi Tian edited this page Feb 5, 2017
·
5 revisions
Contains Django management command scripts.
- Backs up static files, MySQL, Apache, and local
config/files intobackup/folder. - Uses subprocess.check_call() for
mysqldump,tarfile for creating TGZ files. - Due to lack of permissions of www-data user to
/etc/apache2/, Apache settings are archived by acronjob under ubuntu. - The
cronjob is triggered weekly. Summary is sent to admin after job finish either via email.
- Finds all JOB_ID records in JobIDs table that are older than KEEP_JOB months specified in
config/cron.conf. - Removes related result files in
data/and deletes the MySQL entry. - Iterates over each file in
data/and finds results that are not recorded in MySQL (orphans), and remove the files.
- Retrieves all releases of
primerizepackage, and writes versions and texts intocache/stat_dist.json. - Downloads all release ZIP files using curl with daslab-admin GitHub account credentials in
config/oauth.conf. Files are saved todist/. Releases already downloaded are skipped. - The latest master branch is downloaded as
dist/Primerize-master.zip. The LICENSE.md inside it is extracted and placed asdist/Primerize-LICENSE.md, which is used by license() insrc/views.pyfor /license/. - This command is triggered by GitHub webhooks, which is configured at https://github.com/DasLab/Primerize/settings/hooks, to keep the local ZIP files up-to-date. Webhooks are handled by git_hook() in
src/api.py.
- Uploads most recent backup onto
daslabGoogle Drive and cleans up obsolete backup files. - Uses subprocess.check_call() for
drive. Files are renamed with date as prefix. - Old files are determined by their last modified date and removed (default 45 days).
- The
cronjob is triggered weekly. Summary is sent to admin after job finish either via email or Slack.
- Restores static files, MySQL, Apache, and local
config/files from localbackup/files. - Uses subprocess.check_call() for
mysql,tarfileandshutilfor unpacking TGZ files.
- Collects system installed package versions into
cache/stat_sys.jsonandcache/stat_ver.json. - Uses subprocess.Popen() for
bashcommands. Some commands need to write tocache/temp.txttemporarily for output handling. Some values, e.g. mod_wsgi, are implemented for production only. Commands for memory readings are dependent onDEBUGas well. - Renders
cache/sys_ver.txt(only in production) based on information incache/stat_ver.json. It is displayed inbashupon login. - Calls get_backup_stat() from
src/console.pytoo.
New Admin Setup
Admin Responsibility
Server Environment
Overview
Linux
Python