Exemplo n.º 1
0
 def handle(self, *args, **options):
     context = {
         'project_name': paths.get_project_name(),
         'site_dir': paths.get_site_dir(),
     }
     banner = "%(project_name)s status" % context
     self.stdout.write(banner)
     self.stdout.write('-' * len(banner))
     self.stdout.write(' Orchestra version: ' + get_version())
     if djsettings.DEBUG:
         self.stdout.write(" debug enabled")
     else:
         self.stdout.write(" debug disabled")
     ps = run('ps aux').stdout.decode().replace('\n', ' ')
     for service in flatten(settings.ORCHESTRA_START_SERVICES):
         context['service'] = service
         if self.is_running(context, ps):
             self.stdout.write(" %(service)s online" % context)
         else:
             self.stdout.write(" %(service)s offline" % context)
         if service == 'nginx':
             try:
                 config_path = '/etc/nginx/sites-enabled/%(project_name)s.conf' % context
                 with open(config_path, 'r') as handler:
                     config = handler.read().replace('\n', ' ')
             except FileNotFoundError:
                 self.stdout.write("   * %s not found" % config_path)
             else:
                 regex = r'location\s+([^\s]+)\s+{.*uwsgi_pass unix:///var/run/uwsgi/app/%(project_name)s/socket;.*' % context
                 location = re.findall(regex, config)
                 if location:
                     ip = run(
                         "ip a | grep 'inet ' | awk {'print $2'} | grep -v '^127.0.' | head -n 1 | cut -d'/' -f1"
                     ).stdout.decode()
                     if not ip:
                         ip = '127.0.0.1'
                     location = 'http://%s%s' % (ip, location[0])
                     self.stdout.write("   * location %s" % location)
                 else:
                     self.stdout.write("   * location not found")
         elif service == 'postgresql':
             db_conn = connections['default']
             try:
                 c = db_conn.cursor()
             except OperationalError:
                 self.stdout.write("   * DB connection failed")
             else:
                 self.stdout.write("   * DB connection succeeded")
         elif service == 'uwsgi':
             uwsgi_config = '/etc/uwsgi/apps-enabled/%(project_name)s.ini' % context
             if os.path.isfile(uwsgi_config):
                 self.stdout.write("   * %s exists" % uwsgi_config)
             else:
                 self.stdout.write("   * %s does not exist" % uwsgi_config)
     cronbeat = 'crontab -l | grep "^.*/orchestra-beat %(site_dir)s/manage.py"' % context
     if run(cronbeat, valid_codes=(0, 1)).exit_code == 0:
         self.stdout.write(" cronbeat installed")
     else:
         self.stdout.write(" cronbeat not installed")
Exemplo n.º 2
0
 def handle(self, *args, **options):
     context = {
         'project_name': paths.get_project_name(),
         'site_dir': paths.get_site_dir(),
     }
     banner = "%(project_name)s status" % context
     self.stdout.write(banner)
     self.stdout.write('-'*len(banner))
     self.stdout.write(' Orchestra version: ' + get_version())
     if djsettings.DEBUG:
         self.stdout.write(" debug enabled")
     else:
         self.stdout.write(" debug disabled")
     ps = run('ps aux').stdout.decode().replace('\n', ' ')
     for service in flatten(settings.ORCHESTRA_START_SERVICES):
         context['service'] = service
         if self.is_running(context, ps):
             self.stdout.write(" %(service)s online" % context)
         else:
             self.stdout.write(" %(service)s offline" % context)
         if service == 'nginx':
             try:
                 config_path = '/etc/nginx/sites-enabled/%(project_name)s.conf' % context
                 with open(config_path, 'r') as handler:
                     config = handler.read().replace('\n', ' ')
             except FileNotFoundError:
                 self.stdout.write("   * %s not found" % config_path)
             else:
                 regex = r'location\s+([^\s]+)\s+{.*uwsgi_pass unix:///var/run/uwsgi/app/%(project_name)s/socket;.*' % context
                 location = re.findall(regex, config)
                 if location:
                     ip = run("ip a | grep 'inet ' | awk {'print $2'} | grep -v '^127.0.' | head -n 1 | cut -d'/' -f1").stdout.decode()
                     if not ip:
                         ip = '127.0.0.1'
                     location = 'http://%s%s' % (ip, location[0])
                     self.stdout.write("   * location %s" % location)
                 else:
                     self.stdout.write("   * location not found")
         elif service == 'postgresql':
             db_conn = connections['default']
             try:
                 c = db_conn.cursor()
             except OperationalError:
                 self.stdout.write("   * DB connection failed")
             else:
                 self.stdout.write("   * DB connection succeeded")
         elif service == 'uwsgi':
             uwsgi_config = '/etc/uwsgi/apps-enabled/%(project_name)s.ini' % context
             if os.path.isfile(uwsgi_config):
                 self.stdout.write("   * %s exists" % uwsgi_config)
             else:
                 self.stdout.write("   * %s does not exist" % uwsgi_config)
     cronbeat = 'crontab -l | grep "^.*/orchestra-beat %(site_dir)s/manage.py"' % context
     if run(cronbeat, valid_codes=(0, 1)).exit_code == 0:
         self.stdout.write(" cronbeat installed")
     else:
         self.stdout.write(" cronbeat not installed")
Exemplo n.º 3
0
    def handle(self, *args, **options):
        current_version = get_version()
        current_path = get_existing_pip_installation()

        if current_path is not None:
            desired_version = options.get('version')
            if args:
                desired_version = args[0]
            if current_version == desired_version:
                msg = "Not upgrading, you already have version %s installed"
                raise CommandError(msg % desired_version)
            # Create a backup of current installation
            base_path = os.path.abspath(os.path.join(current_path, '..'))
            char_set = string.ascii_uppercase + string.digits
            rand_name = ''.join(random.sample(char_set, 6))
            backup = os.path.join(base_path, 'orchestra.' + rand_name)
            run("mv %s %s" % (current_path, backup))

            # collect existing eggs previous to the installation
            eggs_regex = os.path.join(base_path, 'django_orchestra-*.egg-info')
            eggs = run('ls -d %s' % eggs_regex)
            eggs = eggs.stdout.splitlines()
            try:
                if desired_version:
                    r('pip install django-orchestra==%s' % desired_version)
                else:
                    # Did I mentioned how I hate PIP?
                    if run('pip --version|cut -d" " -f2').stdout == '1.0':
                        r('pip install django-orchestra --upgrade')
                    else:
                        # (F*****g pip)^2, it returns exit code 0 even when fails
                        # because requirement already up-to-date
                        r('pip install django-orchestra --upgrade --force')
            except CommandError:
                # Restore backup
                run('rm -rf %s' % current_path)
                run('mv %s %s' % (backup, current_path))
                raise CommandError("Problem runing pip upgrade, aborting...")
            else:
                # Some old versions of pip do not performe this cleaning ...
                # Remove all backups
                run('rm -fr %s' % os.path.join(base_path, 'orchestra\.*'))
                # Clean old egg files, yeah, cleaning PIP shit :P
                c_version = 'from orchestra import get_version; print get_version()'
                version = run('python -c "%s;"' % c_version).stdout
                for egg in eggs:
                    # Do not remove the actual egg file when upgrading twice the same version
                    if egg.split('/')[
                            -1] != "django_orchestra-%s.egg-info" % version:
                        run('rm -fr %s' % egg)
        else:
            raise CommandError(
                "You don't seem to have any previous PIP installation")

        # version specific upgrade operations
        if not options.get('pip_only'):
            call_command("postupgradeorchestra", version=current_version)
Exemplo n.º 4
0
 def handle(self, *args, **options):
     current_version = get_version()
     current_path = get_existing_pip_installation()
     
     if current_path is not None:
         desired_version = options.get('version')
         if args:
             desired_version = args[0]
         if current_version == desired_version:
             msg = "Not upgrading, you already have version %s installed"
             raise CommandError(msg % desired_version)
         # Create a backup of current installation
         base_path = os.path.abspath(os.path.join(current_path, '..'))
         char_set = string.ascii_uppercase + string.digits
         rand_name = ''.join(random.sample(char_set, 6))
         backup = os.path.join(base_path, 'orchestra.' + rand_name)
         run("mv %s %s" % (current_path, backup))
         
         # collect existing eggs previous to the installation
         eggs_regex = os.path.join(base_path, 'django_orchestra-*.egg-info')
         eggs = run('ls -d %s' % eggs_regex)
         eggs = eggs.stdout.splitlines()
         try:
             if desired_version:
                 r('pip install django-orchestra==%s' % desired_version)
             else:
                 # Did I mentioned how I hate PIP?
                 if run('pip --version|cut -d" " -f2').stdout == '1.0':
                     r('pip install django-orchestra --upgrade')
                 else:
                     # (F*****g pip)^2, it returns exit code 0 even when fails
                     # because requirement already up-to-date
                     r('pip install django-orchestra --upgrade --force')
         except CommandError:
             # Restore backup
             run('rm -rf %s' % current_path)
             run('mv %s %s' % (backup, current_path))
             raise CommandError("Problem runing pip upgrade, aborting...")
         else:
             # Some old versions of pip do not performe this cleaning ...
             # Remove all backups
             run('rm -fr %s' % os.path.join(base_path, 'orchestra\.*'))
             # Clean old egg files, yeah, cleaning PIP shit :P
             c_version = 'from orchestra import get_version; print get_version()'
             version = run('python -c "%s;"' % c_version).stdout
             for egg in eggs:
                 # Do not remove the actual egg file when upgrading twice the same version
                 if egg.split('/')[-1] != "django_orchestra-%s.egg-info" % version:
                     run('rm -fr %s' % egg)
     else:
         raise CommandError("You don't seem to have any previous PIP installation")
     
     # version specific upgrade operations
     if not options.get('pip_only'):
         call_command("postupgradeorchestra", version=current_version)
Exemplo n.º 5
0
 def handle_noargs(self, **options):
     self.stdout.write(get_version())
Exemplo n.º 6
0
def orchestra_version():
    return get_version()
Exemplo n.º 7
0
def controller_version():
    return get_version()