Example #1
0
 def _postgres_import_dump(self):
     cmd.bash_execute(
         "pg_restore -Fc -d %s -U %s -j %d --no-owner --no-privileges %s" %
         (self.db_name, "staging", DB_DUMP_WORKERS, DB_DUMP_FILENAME))
     self._postgres_cmd("GRANT ALL PRIVILEGES ON DATABASE %s TO %s;" %
                        (self.db_name, self.db_user))
     self._postgres_cmd("ALTER DATABASE %s OWNER TO %s;" %
                        (self.db_name, self.db_user))
     self._postgres_cmd("ALTER SCHEMA public OWNER TO %s;" %
                        (self.db_user, ),
                        database=self.db_name)
     self._postgres_cmd("ALTER SCHEMA information_schema OWNER TO %s;" %
                        (self.db_user, ),
                        database=self.db_name)
     self._postgres_cmd("GRANT ALL ON ALL TABLES IN SCHEMA public TO %s;" %
                        (self.db_user, ),
                        database=self.db_name)
     self._postgres_cmd(
         "GRANT ALL ON ALL TABLES IN SCHEMA information_schema TO %s;" %
         (self.db_user, ),
         database=self.db_name)
     self._postgres_cmd(
         "GRANT ALL ON ALL SEQUENCES IN SCHEMA public TO %s;" %
         (self.db_user, ),
         database=self.db_name)
     self._postgres_cmd(
         "GRANT ALL ON ALL SEQUENCES IN SCHEMA information_schema TO %s;" %
         (self.db_user, ),
         database=self.db_name)
     self._postgres_cmd(
         "GRANT ALL ON ALL FUNCTIONS IN SCHEMA public TO %s;" %
         (self.db_user, ),
         database=self.db_name)
     self._postgres_cmd(
         "GRANT ALL ON ALL FUNCTIONS IN SCHEMA information_schema TO %s;" %
         (self.db_user, ),
         database=self.db_name)
     # Generate ALTER TABLE ... OWNER TO query for each of the tables in the 'public' schema
     cmd.bash_execute(
         "psql %s -c \"SELECT 'ALTER TABLE '|| schemaname || '.' || tablename ||' OWNER TO %s;' "
         "FROM pg_tables WHERE NOT schemaname IN ('pg_catalog', 'information_schema') "
         "ORDER BY schemaname, tablename;\" "
         "| cat | grep \"ALTER TABLE\" | "
         "psql %s" % (self.db_name, self.db_user, self.db_name))
     # Run VACUUM commands to optimise space utilisation
     self._postgres_cmd("VACUUM;", database=self.db_name)
     self._postgres_cmd("VACUUM FULL;", database=self.db_name)
Example #2
0
 def _postgres_cmd(self,
                   command,
                   user="******",
                   password=None,
                   database="staging"):
     if password:
         command = "PGPASSWORD=%s %s" % (password, command)
     command = "psql -U %s %s -c \"%s\"" % (user, database, command)
     return cmd.bash_execute(command)
Example #3
0
    def _jorvik_configure(self):
        # Skeleton configuration
        cmd.bash_execute("cp -R %s/* %s" %
                         (SKELETON_CONFIGURATION, self._get_nginx_root()))

        # Write database configuration
        database = "[client]\n" \
                   "host = localhost\n" \
                   "port = 5432\n" \
                   "database = %(db_name)s\n" \
                   "user = %(db_user)s\n" \
                   "password = %(db_pass)s\n" % {
            "db_name": self.db_name, "db_user": self.db_user,
            "db_pass": self.db_pass
        }
        cmd.file_write("%s/config/pgsql.cnf" % self._get_nginx_root(),
                       database)

        # Write media configuration
        media = "[media]\n" \
                "media_root = %(root)s/media/\n" \
                "media_url = /media/\n" \
                "[static]\n" \
                "static_root = %(root)s/static/\n" \
                "static_url = /static/\n" % {"root": self._get_nginx_root()}
        cmd.file_write("%s/config/media.cnf" % self._get_nginx_root(), media)

        # Write uwsgi.ini file
        uwsgi_ini = "[uwsgi]\n" \
                    "plugins = python3\n" \
                    "module = jorvik.wsgi:application\n" \
                    "virtualenv = %d/.venv\n" \
                    "chdir = %d\n" \
                    "processes = 4\n" \
                    "threads = 2\n" \
                    "vacuum = True\n"
        cmd.file_write("%s/uwsgi.ini" % self._get_nginx_root(), uwsgi_ini)
Example #4
0
 def _postgres_start(self):
     cmd.bash_execute("%s %s" % (SUDO_BIN, DB_START_SCRIPT))
Example #5
0
 def _postgres_stop(self):
     cmd.bash_execute("%s %s" % (SUDO_BIN, DB_STOP_SCRIPT))
Example #6
0
 def _django_cmd(self, command):
     return cmd.bash_execute(
         "DJANGO_SETTINGS_MODULE=jorvik.settings python manage.py %s" %
         command,
         cwd=self._get_nginx_root(),
         venv=".venv")
Example #7
0
 def _uwsgi_touch(self):
     cmd.bash_execute("touch uwsgi.ini", cwd=self._get_nginx_root())
Example #8
0
 def _python_venv_setup(self):
     cmd.bash_execute("python3 -m virtualenv -ppython3 .venv",
                      cwd=self._get_nginx_root())
     cmd.bash_execute("pip install -r requirements.txt",
                      cwd=self._get_nginx_root(),
                      venv=".venv")
Example #9
0
 def _git_pull(self):
     cmd.bash_execute("git pull", cwd=self._get_nginx_root())
Example #10
0
 def _git_clone(self):
     cmd.bash_execute("git clone -b %s %s %s" %
                      (self.branch, self.repository, self.name),
                      cwd=NGINX_ROOTS)