Initial commit

This commit is contained in:
2024-07-13 00:53:45 +03:00
commit 00eabc8150
25 changed files with 870 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
upstream ******* {
server unix:///var/www/*******/deployment/uwsgi_nginx.sock;
}
server {
charset utf-8;
client_max_body_size 75M;
listen 80;
server_name ==========;
if ($host !~ ^(app\.example\.com|admin\.example\.com)$) {
return 404;
}
location / {
uwsgi_pass *******;
include /var/www/*******/deployment/uwsgi_params;
}
location /static {
# autoindex on;
alias /var/www/*******/static/;
}
location /media/ {
# autoindex on;
alias /var/www/*******/media/;
}
}

View File

@@ -0,0 +1,16 @@
[program:*******]
command=uwsgi --emperor "/var/www/*******/deployment/*******-uwsgi.ini"
stdout_logfile=/var/www/logs/*******/supervisor.log
stderr_logfile=/var/www/logs/*******/supervisor_err.log
autostart=true
autorestart=true
[program:*******_celery]
command=/var/www/venvs/*******/bin/celery -A ******* worker --beat
directory=/var/www/*******
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/www/logs/*******/supervisor_celery.log
stderr_logfile=/var/www/logs/*******/supervisor_celery_err.log

View File

@@ -0,0 +1,11 @@
[uwsgi]
chdir = /var/www/*******
module = *******.wsgi
home = /var/www/venvs/*******
plugins = python3
virtualenv = /var/www/venvs/*******
master = true
processes = 10
socket = /var/www/*******/deployment/uwsgi_nginx.sock
chmod-socket = 666
vacuum = true

View File

@@ -0,0 +1,24 @@
#!/bin/bash
# Check if project_name argument is provided
if [ -z "$PROJECT_NAME" ]; then
echo "Error: PROJECT_NAME is not set."
exit 1
fi
project_name="$PROJECT_NAME"
# Create /var/www directory
mkdir -p /var/www
# Change group of /var/www directory to oleg20111511
chgrp oleg20111511 /var/www
# Change permissions of /var/www directory to 775
chmod 775 /var/www
# Create /var/www/logs/"project_name" directory
# mkdir -p "/var/www/logs/$project_name"
echo "Project setup complete."

View File

@@ -0,0 +1,23 @@
#!/bin/bash
# Update package lists
sudo apt update
# Install Supervisor
sudo apt install supervisor -y
# Install Nginx
sudo apt install nginx -y
# Install redis
sudo apt install redis -y
# Install certbot
sudo apt install python3-certbot-nginx -y
# Install uWSGI and its dependencies
sudo apt install uwsgi build-essential python3-dev -y
# Install the Python 3 plugin for uWSGI
sudo apt install uwsgi-plugin-python3 -y

View File

@@ -0,0 +1,29 @@
#!/bin/bash
# Check if username and password arguments are provided
if [ $# -ne 2 ]; then
echo "Usage: $0 <username> <password>"
exit 1
fi
username=$1
password=$2
# Install PostgreSQL
sudo apt-get update
sudo apt-get install -y postgresql
# Create a new database named "jfl"
sudo -u postgres psql -c "CREATE DATABASE $username;"
# Create a user with provided username and password
sudo -u postgres psql -c "CREATE USER $username WITH PASSWORD '$password';"
# Grant all privileges on the "jfl" database to the user
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE $username TO $username;"
# Grant permission to create and delete databases
sudo -u postgres psql -c "ALTER USER $username CREATEDB;"
echo "Database setup complete."

View File

@@ -0,0 +1,36 @@
#!/bin/bash
# Check if username and password arguments are provided
if [ -z "$PROJECT_NAME" ]; then
echo "Error: PROJECT_NAME is not set."
exit 1
fi
project_name=$PROJECT_NAME
ln -s /var/www/$project_name/deployment/$project_name-nginx.conf /etc/nginx/sites-enabled/$project_name-nginx.conf
ln -s /var/www/$project_name/deployment/$project_name-sv.conf /etc/supervisor/conf.d/$project_name-sv.conf
logs_dir="/var/www/logs"
project_logs_dir="$logs_dir/$project_name"
# Create /var/www/logs directory if it doesn't exist
if [ ! -d "$logs_dir" ]; then
sudo mkdir -p "$logs_dir"
sudo chown -R "$USER:$USER" "$logs_dir"
sudo chmod -R 755 "$logs_dir"
echo "Created directory $logs_dir"
fi
# Create /var/www/logs/$project_name directory if it doesn't exist
if [ ! -d "$project_logs_dir" ]; then
sudo mkdir -p "$project_logs_dir"
sudo chown -R "$USER:$USER" "$project_logs_dir"
sudo chmod -R 755 "$project_logs_dir"
echo "Created directory $project_logs_dir"
fi

View File

@@ -0,0 +1,43 @@
#!/bin/bash
# echo "export PROJECT_NAME=value" >> ~/.bashrc
# Check if project_name arugment is provided
# if [ $# -ne 1 ]; then
# echo "Usage: $0 <project_name>"
# exit 1
# fi
# project_name=$1
if [ -z "$PROJECT_NAME" ]; then
echo "Error: PROJECT_NAME is not set."
exit 1
fi
# Change to your desired directory
cd /var/www/$PROJECT_NAME
# Perform a git pull
git pull
git submodule init
git submodule update
# Activate virtual environment
source /var/www/venvs/$PROJECT_NAME/bin/activate
# Collect static files
python manage.py collectstatic --noinput
# Create database migrations
python manage.py makemigrations
# Apply database migrations
python manage.py migrate
# Restart supervisor processes
sudo supervisorctl restart $PROJECT_NAME
sudo supervisorctl restart "$PROJECT_NAME"_celery

View File

@@ -0,0 +1,14 @@
uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;
uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;
uwsgi_param REQUEST_SCHEME $scheme;
uwsgi_param HTTPS $https if_not_empty;
uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;