Commit 0ac2bac7cd3d8c8eeaba146efec6e665b3a489c7
Exists in
spb-release/3.0
Merge branch 'spb-release/3.0' of portal.softwarepublico.gov.br:softwarepublico/…
…colab into spb-release/3.0
Showing
4 changed files
with
32 additions
and
1 deletions
Show diff stats
colab/proxy/management/commands/import_proxy_data.py
| ... | ... | @@ -2,6 +2,9 @@ |
| 2 | 2 | |
| 3 | 3 | import importlib |
| 4 | 4 | import inspect |
| 5 | +import logging | |
| 6 | +import os | |
| 7 | +import sys | |
| 5 | 8 | |
| 6 | 9 | from django.core.management.base import BaseCommand |
| 7 | 10 | from django.conf import settings |
| ... | ... | @@ -12,7 +15,30 @@ from colab.proxy.utils.proxy_data_api import ProxyDataAPI |
| 12 | 15 | class Command(BaseCommand): |
| 13 | 16 | help = "Import proxy data into colab database" |
| 14 | 17 | |
| 18 | + lock_file = settings.IMPORT_DATA_LOCK_FILE | |
| 19 | + | |
| 15 | 20 | def handle(self, *args, **kwargs): |
| 21 | + if os.path.exists(self.lock_file): | |
| 22 | + print(("This script is already running. " | |
| 23 | + "(If your are sure it's not please " | |
| 24 | + "delete the lock file in {}')").format(self.lock_file)) | |
| 25 | + sys.exit(1) | |
| 26 | + | |
| 27 | + if not os.path.exists(os.path.dirname(self.lock_file)): | |
| 28 | + os.mkdir(os.path.dirname(self.lock_file), 0755) | |
| 29 | + | |
| 30 | + run_lock = file(self.lock_file, 'w') | |
| 31 | + run_lock.close() | |
| 32 | + | |
| 33 | + try: | |
| 34 | + self.run() | |
| 35 | + except Exception as e: | |
| 36 | + logging.exception(e) | |
| 37 | + raise | |
| 38 | + finally: | |
| 39 | + os.remove(self.lock_file) | |
| 40 | + | |
| 41 | + def run(self): | |
| 16 | 42 | print "Executing extraction command..." |
| 17 | 43 | |
| 18 | 44 | for module_name in settings.PROXIED_APPS.keys(): | ... | ... |
colab/settings.py
| ... | ... | @@ -251,6 +251,9 @@ MESSAGE_TAGS = { |
| 251 | 251 | # Colab Settings |
| 252 | 252 | COLAB_HOME_URL = '/dashboard' |
| 253 | 253 | |
| 254 | +# Plugins | |
| 255 | +IMPORT_DATA_LOCK_FILE = '/var/lock/colab/import_data.lock' | |
| 256 | + | |
| 254 | 257 | # Super Archives |
| 255 | 258 | SUPER_ARCHIVES_PATH = '/var/lib/mailman/archives/private' |
| 256 | 259 | SUPER_ARCHIVES_EXCLUDE = [] | ... | ... |
colab/super_archives/management/commands/import_emails.py
| ... | ... | @@ -270,7 +270,7 @@ class Command(BaseCommand, object): |
| 270 | 270 | self.log(("This script is already running. " |
| 271 | 271 | "(If your are sure it's not please " |
| 272 | 272 | "delete the lock file in {}')").format(self.lock_file)) |
| 273 | - sys.exit(0) | |
| 273 | + sys.exit(1) | |
| 274 | 274 | |
| 275 | 275 | if not os.path.exists(os.path.dirname(self.lock_file)): |
| 276 | 276 | os.mkdir(os.path.dirname(self.lock_file), 0755) | ... | ... |
misc/lib/systemd/system/colab.service
| ... | ... | @@ -3,6 +3,8 @@ Description=Colab |
| 3 | 3 | |
| 4 | 4 | [Service] |
| 5 | 5 | User=colab |
| 6 | +ExecStartPre=/usr/bin/mkdir -p /var/lock/colab | |
| 7 | +ExecStartPre=/usr/bin/chown -R colab:colab /var/lock/colab | |
| 6 | 8 | ExecStart=/usr/lib/colab/bin/gunicorn colab.wsgi:application --bind=127.0.0.1:8001 --workers=3 |
| 7 | 9 | Restart=on-failure |
| 8 | 10 | ... | ... |