- Create service file :
sudo nano /etc/systemd/system/my_project.service
Add :
[Unit]
Description= description_text_you_want
After=network.target
[Service]
User=user_name
Group=www-data
EnvironmentFile=.env_file_absolute_path
Environment="PATH=virtual_env_path"
WorkingDirectory=app_working_directory
ExecStart=gunicorn_path --workers 3 --bind unix:my_project.sock -m 007 project.wsgi:app
[Install]
WantedBy=multi-user.target
- To find virtual env path and gunicorn path use :
which gunicorn
- Start and enable app :
sudo systemctl start my_project
sudo systemctl enable my_project
- Check for status app :
sudo systemctl status my_project
- To restart app :
sudo systemctl daemon-reload
sudo systemctl restart my_project
- Create server block :
sudo nano /etc/nginx/sites-available/my_project
- Add :
server {
server_name IP adress or domain nam;
access_log /path_to_myproject/logs/access.log;
error_log /path_to_myproject/logs/error.log error;
location / {
proxy_pass http://unix:path_to_myproject/my_project.sock;
include proxy_params;
}
}
- Link to sites-enabled :
sudo ln -s /etc/nginx/sites-available/my_project /etc/nginx/sites-enabled
- Check for syntax errors :
sudo nginx -t
- Restart nginx :
sudo systemctl restart nginx
Or you can restart nginx with bash ~/restart_nginx.sh
For each project you cand add to ~/.profile :
alias my_project-log="sudo journalctl -u my_project -n 150"
alias my_project-reboot="sudo systemctl daemon-reload && sudo systemctl restart my_project"
alias my_project-status="sudo systemctl status my_project"
- Connect with superuser :
sudo -u postgres psql
- connect to databse :
\c databse_name
- copy :
COPY table_name FROM 'absolute_path_to_csv_file' delimiter 'delimiter' csv header;