Compare commits
5 Commits
raspbian-d
...
centos-dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b4dfdaeac7 | ||
|
|
ac8b6d8941 | ||
|
|
f7b8d6da96 | ||
|
|
2258b1df0e | ||
|
|
7a2ec49b6d |
100
README.md
100
README.md
@@ -1,4 +1,4 @@
|
|||||||
# Django Setup for Raspbian Jessie
|
# Django Setup for CentOS 7
|
||||||
## Install
|
## Install
|
||||||
```bash
|
```bash
|
||||||
vim vars
|
vim vars
|
||||||
@@ -15,23 +15,20 @@ export gitkey="" <-- put the path to the ssh key git will use here
|
|||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo -s <-- you must be root to run script
|
sudo ./install.sh
|
||||||
./install.sh
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Reset
|
## Reset
|
||||||
If anything goes wrong with the project and you don't want to perform a full uninstall:
|
If anything goes wrong with the project and you don't want to perform a full uninstall:
|
||||||
```bash
|
```bash
|
||||||
sudo -s
|
sudo ./reset
|
||||||
./reset
|
|
||||||
```
|
```
|
||||||
will reset the project but leave the dependencies installed. You can rerun the installer with different variables to fix what was incorrect. WARNING: This will delete your project (including your database)
|
will reset the project but leave the dependencies installed. You can rerun the installer with different variables to fix what was incorrect. WARNING: This will delete your project (including your database)
|
||||||
|
|
||||||
## Uninstall
|
## Uninstall
|
||||||
To completely remove every trace of the project from your server:
|
To completely remove every trace of the project from your server:
|
||||||
```bash
|
```bash
|
||||||
sudo -s
|
sudo ./uninstall
|
||||||
./uninstall
|
|
||||||
```
|
```
|
||||||
This will completely remove everything.
|
This will completely remove everything.
|
||||||
|
|
||||||
@@ -40,15 +37,18 @@ This will completely remove everything.
|
|||||||
### vars
|
### vars
|
||||||
```bash
|
```bash
|
||||||
# Django project settings
|
# Django project settings
|
||||||
user=""
|
user="centos"
|
||||||
projectname=""
|
projectname="mysite"
|
||||||
hostname=""
|
hostname="centos.duco.net"
|
||||||
letsencrypt=False
|
letsencrypt=False
|
||||||
|
|
||||||
|
# set True if CentOS minimal install
|
||||||
|
install_epel_release=False
|
||||||
|
|
||||||
# general install settings
|
# general install settings
|
||||||
logdir="/var/log/djangosetup/"
|
logdir="/var/log/djangosetup/"
|
||||||
aptlogloc=$logdir"apt.log"
|
yumlogloc=$logdir"yum.log"
|
||||||
aptlogmsg="See $aptlogloc for more info."
|
yumlogmsg="See $yumlogloc for more info."
|
||||||
firelogloc=$logdir"firewall.log"
|
firelogloc=$logdir"firewall.log"
|
||||||
firelogmsg="See $firelogloc for more info."
|
firelogmsg="See $firelogloc for more info."
|
||||||
pylogloc=$logdir"python.log"
|
pylogloc=$logdir"python.log"
|
||||||
@@ -72,11 +72,15 @@ My recommendation is to use nginx as the user. The installer takes care of creat
|
|||||||
|
|
||||||
The projectname variable can be whatever you want. When Django starts the project it will use this name.
|
The projectname variable can be whatever you want. When Django starts the project it will use this name.
|
||||||
|
|
||||||
The hostname will be added as an environment variable for gunicorn. Multiple hosts are not supported at the moment so set this to the address you'll test with. You can add additional hosts by manually editing ```settings.py```.
|
The hostname will be inserted into "ALLOWED_HOSTS" in your app settings. Multiple hosts are not supported at the moment so set this to the address you'll test with. You can add additional hosts by manually editing ```settings.py```.
|
||||||
|
|
||||||
|
```install_epel_release=True```
|
||||||
|
|
||||||
|
If you are installing this on a system with the minimal CentOS build you'll need install_epel_release to be True. ```epel_release``` installs nginx. Kinda hard to run the site without that.
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
### Dependencies
|
### Dependencies
|
||||||
In order for this script to work its magic you'll need a few packages provided by apt.
|
In order for this script to work its magic you'll need a few packages provided by Yum. This part is likely to break due to Yum's inconsistency accross distributions, firewall and proxy configurations, and whether CentOS had its morning coffee.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# check if root
|
# check if root
|
||||||
@@ -93,43 +97,61 @@ tput setaf 0
|
|||||||
if [ ! -d $logdir ] ; then
|
if [ ! -d $logdir ] ; then
|
||||||
mkdir $logdir
|
mkdir $logdir
|
||||||
fi
|
fi
|
||||||
|
if [ $install_epel_release = True ] ; then
|
||||||
|
yum -y install epel-release 1>> $yumlogloc 2>> $yumlogloc 3>> $pylogloc
|
||||||
|
fi
|
||||||
```
|
```
|
||||||
|
|
||||||
The first part of the script is fairly straight forward. If you aren't root user, the installer can't use apt and won't work. After checking if you are the root user it creates the necessary directories to prevent future complaints.
|
The first part of the script is fairly straight forward. If you aren't root user, the installer can't use yum and won't work. After checking if you are the root user it creates the necessary directories to prevent future complaints and installs the aforementioned epel-release package if you want it.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# install dependencies
|
# install dependencies
|
||||||
packages=(gcc wget nginx ufw make sqlite3 bzip2 openssl libffi-dev libssl-dev libsqlite3-dev zlib1g-dev libbz2-dev)
|
packages=(gcc wget nginx libsqlite3x-devel.x86_64 postgresql-server postgresql-devel postgresql-contrib bzip2-devel zlib-devel libffi-devel openssl-devel policycoreutils-python.x86_64)
|
||||||
for package in ${packages[@]};
|
for package in ${packages[@]};
|
||||||
do
|
do
|
||||||
echo -e "\tInstalling $package"
|
echo -e "\tInstalling $package"
|
||||||
touch $aptlogloc
|
yum -y install $package 1>> $yumlogloc 2>> $yumlogloc 3>> $yumlogloc
|
||||||
apt install -y $package 1>> $aptlogloc 2>> $aptlogloc 3>> $aptlogloc
|
|
||||||
if [ $? -ne 0 ] ; then
|
if [ $? -ne 0 ] ; then
|
||||||
echo -e "apt failed to install $package. $aptlogmsg"
|
echo -e "yum failed to install $package. $yumlogmsg"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
```
|
```
|
||||||
|
|
||||||
The next part of the script installs apt dependencies. The script verifies that the installation goes smoothly and exits if an error occurs.
|
The next part of the script installs yum dependencies. The script verifies that the installation goes smoothly and exits if an error occurs.
|
||||||
|
|
||||||
### Firewall
|
### Firewall
|
||||||
```bash
|
```bash
|
||||||
# firewall
|
# set firewall
|
||||||
ports=(22 80 443)
|
echo -e "firewall-cmd --zone=public --add-port=80/tcp --permanent" > $firelogloc
|
||||||
for port in ${ports[@]};
|
firewall-cmd --zone=public --add-port=80/tcp --permanent >> $firelogloc
|
||||||
do
|
|
||||||
echo -e "ufw allow $port/tcp" > $firelogloc
|
|
||||||
ufw allow $port/tcp 1>> $firelogloc 2>> $firelogloc
|
|
||||||
if [ $? -ne 0 ] ; then
|
if [ $? -ne 0 ] ; then
|
||||||
echo -e "\tfirewall failed to update port $port correctly. $firelogmsg"
|
echo -e "firewall failed to update port 80 correctly (this may not be an issue). $firelogmsg"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "firewall-cmd --zone=public --add-port=443/tcp --permanent" >> $firelogloc
|
||||||
|
firewall-cmd --zone=public --add-port=443/tcp --permanent >> $firelogloc
|
||||||
|
if [ $? -ne 0 ] ; then
|
||||||
|
echo -e "firewall failed to update port 443 correctly, (this may not be an issue). $firelogmsg"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "firewall-cmd --reload" >> $firelogloc
|
||||||
|
firewall-cmd --reload >> $firelogloc
|
||||||
|
if [ $? -ne 0 ] ; then
|
||||||
|
echo -e "firewall failed to reload, (this may not be an issue). $firelogmsg"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "semanage permissive -a httpd_t" >> $firelogloc
|
||||||
|
semanage permissive -a httpd_t >> $firelogloc
|
||||||
|
if [ $? -ne 0 ] ; then
|
||||||
|
echo -e "semanage failed to set permissive. See $firelogmsg"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
done
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The next part of the script opens the necessary ports through ufw.
|
The firewall commands are specific to a CentOS 7 minimal install. You may not need them. The installer doesn't really care if they fail because they aren't mission critical. It'll yell at you and that's about it.
|
||||||
|
|
||||||
|
The **semanage** command fixes an issue where the websocket would be inaccessible after an install.
|
||||||
|
|
||||||
### Python
|
### Python
|
||||||
```bash
|
```bash
|
||||||
@@ -230,19 +252,19 @@ fi
|
|||||||
```
|
```
|
||||||
Next the script starts the Django project. You'll notice that the project structure looks like this:
|
Next the script starts the Django project. You'll notice that the project structure looks like this:
|
||||||
```
|
```
|
||||||
|
|
||||||
[projectname]/
|
[projectname]/
|
||||||
├── [config]/
|
├── [projectname]/
|
||||||
│ ├── __init__.py
|
│ ├── [projectname]/
|
||||||
│ ├── settings.py
|
│ │ ├── __init__.py
|
||||||
│ ├── urls.py
|
│ │ ├── settings.py
|
||||||
│ └── wsgi.py
|
│ │ ├── urls.py
|
||||||
├── manage.py
|
│ │ └── wsgi.py
|
||||||
|
│ └── manage.py
|
||||||
└── venv/
|
└── venv/
|
||||||
```
|
```
|
||||||
When making changes to nginx or gunicorn it's important to keep this structure in mind.
|
When making changes to nginx or gunicorn it's important to keep this structure in mind. There are 3 folders called ```$projectname```.
|
||||||
|
|
||||||
After starting the Django project, the script updates allowed hosts, collects static, and makes migrations.
|
After this, the script updates allowed hosts, collects static, and makes migrations.
|
||||||
|
|
||||||
### Gunicorn
|
### Gunicorn
|
||||||
```bash
|
```bash
|
||||||
@@ -253,7 +275,7 @@ After=network.target
|
|||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
User=$user
|
User=$user
|
||||||
Group=www-data
|
Group=nginx
|
||||||
WorkingDirectory=/home/$user/$projectname/$projectname
|
WorkingDirectory=/home/$user/$projectname/$projectname
|
||||||
ExecStart=/home/$user/$projectname/venv/bin/gunicorn --workers 3 --bind unix:/home/$user/$projectname/$projectname.sock $projectname.wsgi:application
|
ExecStart=/home/$user/$projectname/venv/bin/gunicorn --workers 3 --bind unix:/home/$user/$projectname/$projectname.sock $projectname.wsgi:application
|
||||||
|
|
||||||
|
|||||||
443
install.sh
443
install.sh
@@ -5,323 +5,304 @@
|
|||||||
# Installs Dependencies automatically
|
# Installs Dependencies automatically
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
|
# source vars
|
||||||
|
source ./vars
|
||||||
|
|
||||||
# check if root
|
# check if root
|
||||||
if [ $EUID -ne 0 ] ; then
|
if [[ $EUID -ne 0 ]]; then
|
||||||
echo -e "This script must be run as root"
|
echo -e "This script must be run as root"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
cd /root/
|
||||||
|
|
||||||
# source vars
|
tput setaf 2
|
||||||
source vars
|
|
||||||
|
|
||||||
echo -e "Installing dependencies"
|
echo -e "Installing dependencies"
|
||||||
|
tput setaf 9
|
||||||
# create necessary dirs
|
# create necessary dirs
|
||||||
if [ ! -d $logdir ] ; then
|
if [ ! -d $logdir ] ; then
|
||||||
mkdir $logdir
|
mkdir $logdir
|
||||||
fi;
|
fi
|
||||||
|
|
||||||
|
if [ $install_epel_release=True ] ; then
|
||||||
|
yum -y install epel-release 1>> $yumlogloc 2>> $yumlogloc 3>> $yumlogloc
|
||||||
|
fi
|
||||||
|
|
||||||
# install dependencies
|
# install dependencies
|
||||||
echo -e "\tRunning apt update";
|
packages=(gcc wget nginx libsqlite3x-devel.x86_64 postgresql-server postgresql-devel postgresql-contrib bzip2-devel zlib-devel libffi-devel openssl-devel policycoreutils-python.x86_64)
|
||||||
apt update 1> $aptlogloc 2>> $aptlogloc 3>> $aptlogloc;
|
|
||||||
for package in ${packages[@]};
|
for package in ${packages[@]};
|
||||||
do
|
do
|
||||||
echo -e "\tInstalling $package"
|
echo -e "\tInstalling $package"
|
||||||
apt install -y $package 1>> $aptlogloc 2>> $aptlogloc 3>> $aptlogloc
|
yum -y install $package 1>> $yumlogloc 2>> $yumlogloc 3>> $yumlogloc
|
||||||
if [ $? -ne 0 ] ; then
|
if [ $? -ne 0 ] ; then
|
||||||
echo -e "apt failed to install $package. $aptlogmsg"
|
echo -e "yum failed to install $package. $yumlogmsg"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
###############################################################################
|
# firewall
|
||||||
# Sqlite3
|
ports=(80 443)
|
||||||
# Download and setup Sqlite3 and modules
|
for port in ${ports[@]};
|
||||||
################################################################################
|
do
|
||||||
echo -e "Install Sqlite3"
|
echo -e "firewall-cmd --zone=public --add-port=$port/tcp --permanent" > $firelogloc
|
||||||
|
firewall-cmd --zone=public --add-port=$port/tcp --permanent 1>> $firelogloc 2>> $firelogloc
|
||||||
# fetch Sqlite
|
|
||||||
wget -O sqlite.tar.gz $sqlink 1> $pylogloc 2>> $pylogloc 3>> $pylogloc
|
|
||||||
if [ $? -ne 0 ] ; then
|
if [ $? -ne 0 ] ; then
|
||||||
echo -e "Failed to fetch sqlite, make sure wget is installed and $pylink is what you're after. $pylogmsg"
|
echo -e "\tfirewall failed to update port $port correctly (this may not be an issue). $firelogmsg"
|
||||||
exit 1
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo -e "firewall-cmd --reload" >> $firelogloc
|
||||||
|
firewall-cmd --reload 1>> $firelogloc 2>> $firelogloc
|
||||||
|
if [ $? -ne 0 ] ; then
|
||||||
|
echo -e "\tfirewall failed to reload, (this may not be an issue). $firelogmsg"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir sqlite
|
echo -e "semanage permissive -a httpd_t" >> $firelogloc
|
||||||
tar xf sqlite.tar.gz -C sqlite --strip-components=1 1>> $pylogloc 2>> $pylogloc 3>> $pylogloc
|
semanage permissive -a httpd_t >> $firelogloc
|
||||||
if [ $? -ne 0 ] ; then
|
if [ $? -ne 0 ] ; then
|
||||||
echo -e "Failed to unzip sqlite. $pylogmsg"
|
echo -e "semanage failed to set permissive. See $firelogmsg"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd sqlite
|
|
||||||
if [ $? -ne 0 ] ; then
|
|
||||||
echo -e "Something went wrong while unzipping. $pylogmsg"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# install Sqlite3
|
|
||||||
echo -e "\tConfigure"
|
|
||||||
./configure 1>> $pylogloc 2>> $pylogloc 3>> $pylogloc
|
|
||||||
if [ $? -ne 0 ] ; then
|
|
||||||
echo -e "./configure failed. $pylogmsg"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo -e "\tMake"
|
|
||||||
make 1>> $pylogloc 2>> $pylogloc 3>> $pylogloc
|
|
||||||
if [ $? -ne 0 ] ; then
|
|
||||||
echo -e "make failed. $pylogmsg"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo -e "\tMake install"
|
|
||||||
make install 1>> $pylogloc 2>> $pylogloc 3>> $pylogloc
|
|
||||||
if [ $? -ne 0 ] ; then
|
|
||||||
echo -e "make install failed. $pylogmsg"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Python
|
# Python
|
||||||
# Download and setup Python and modules
|
# Download and setup Python and modules
|
||||||
################################################################################
|
################################################################################
|
||||||
|
tput setaf 2
|
||||||
echo -e "Installing Python"
|
echo -e "Installing Python"
|
||||||
|
tput setaf 9
|
||||||
|
|
||||||
wget -O python.tar.gz $pylink 1> $pylogloc 2>> $pylogloc 3>> $pylogloc
|
# fetch Python
|
||||||
|
if [ ! -d $pyinstalldir ] ; then # if we already installed python
|
||||||
|
wget $pylink 1> $pylogloc 2>> $pylogloc 3>> $pylogloc
|
||||||
if [ $? -ne 0 ] ; then
|
if [ $? -ne 0 ] ; then
|
||||||
echo -e "Failed to fetch python, make sure wget is installed and $pylink is what you're after. $pylogmsg"
|
echo -e "Failed to fetch python, make sure wget is installed and $pylink is what you're after. $pylogmsg"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
tar xf Python-3.7.0.tar.xz 1>> $pylogloc 2>> $pylogloc 3>> $pylogloc
|
||||||
mkdir python
|
|
||||||
tar xf python.tar.gz -C python --strip-components=1 1>> $pylogloc 2>> $pylogloc 3>> $pylogloc
|
|
||||||
if [ $? -ne 0 ] ; then
|
if [ $? -ne 0 ] ; then
|
||||||
echo -e "Failed to unzip python. $pylogmsg"
|
echo -e "Failed to unzip python. $pylogmsg"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
cd Python-3.7.0
|
||||||
cd python
|
|
||||||
if [ $? -ne 0 ] ; then
|
if [ $? -ne 0 ] ; then
|
||||||
echo -e "Something went wrong while unzipping. $pylogmsg"
|
echo -e "Missing python directory. $pylogmsg"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# install Python
|
# install Python
|
||||||
echo -e "\tConfigure"
|
echo -e "\tConfigure"
|
||||||
./configure 1>> $pylogloc 2>> $pylogloc 3>> $pylogloc
|
./configure --prefix $pyinstalldir 1>> $pylogloc 2>> $pylogloc 3>> $pylogloc
|
||||||
if [ $? -ne 0 ] ; then
|
if [ $? -ne 0 ] ; then
|
||||||
echo -e "./configure failed. $pylogmsg"
|
echo -e "./configure failed. $pylogmsg"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "\tMake"
|
echo -e "\tMake"
|
||||||
make 1>> $pylogloc 2>> $pylogloc 3>> $pylogloc
|
make 1>> $pylogloc 2>> $pylogloc 3>> $pylogloc
|
||||||
if [ $? -ne 0 ] ; then
|
if [ $? -ne 0 ] ; then
|
||||||
echo -e "make failed. $pylogmsg"
|
echo -e "make failed. $pylogmsg"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
echo -e "\tMake altinstall"
|
||||||
echo -e "\tMake install"
|
make altinstall 1>> $pylogloc 2>> $pylogloc 3>> $pylogloc
|
||||||
make install 1>> $pylogloc 2>> $pylogloc 3>> $pylogloc
|
|
||||||
if [ $? -ne 0 ] ; then
|
if [ $? -ne 0 ] ; then
|
||||||
echo -e "make install failed. $pylogmsg"
|
echo -e "make altinstall failed. $pylogmsg"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
# upgrade pip and install virtualenv
|
# upgrade pip and install virtualenv
|
||||||
echo -e "\tUpgrading pip"
|
echo -e "\tUpgrading pip"
|
||||||
python3 -m pip install --upgrade pip 1>> $pylogloc 2>> $pylogloc 3>> $pylogloc
|
/usr/src/python37/bin/python3.7 -m pip install --upgrade pip 1>> $pylogloc 2>> $pylogloc 3>> $pylogloc
|
||||||
if [ $? -ne 0 ] ; then
|
if [ $? -ne 0 ] ; then
|
||||||
echo -e "pip upgrade failed. $pylogmsg"
|
echo -e "pip upgrade failed. $pylogmsg"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo -e "\tInstalling virtualenv"
|
echo -e "\tInstalling virtualenv"
|
||||||
python3 -m pip install virtualenv 1>> $pylogloc 2>> $pylogloc 3>> $pylogloc
|
/usr/src/python37/bin/python3.7 -m pip install virtualenv 1>> $pylogloc 2>> $pylogloc 3>> $pylogloc
|
||||||
if [ $? -ne 0 ] ; then
|
if [ $? -ne 0 ] ; then
|
||||||
echo -e "installing virtualenv failed. $pylogmsg"
|
echo -e "installing virtualenv failed. $pylogmsg"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
cd /root/
|
cd /root/
|
||||||
rm python.tar.xz 1>> $pylogloc 2>> $pylogloc
|
rm Python-3.7.0.tar.xz 1>> $pylogloc 2>> $pylogloc
|
||||||
rm -rf python 1>> $pylogloc 2>> $pylogloc
|
rm -rf Python-3.7.0 1>> $pylogloc 2>> $pylogloc
|
||||||
if [ $? -ne 0 ] ; then
|
if [ $? -ne 0 ] ; then
|
||||||
echo -e "Failed to remove Python install files. $pylogmsg"
|
echo -e "Failed to remove Python install files. $pylogmsg"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ################################################################################
|
################################################################################
|
||||||
# # Django
|
# Django
|
||||||
# # Download, setup and configure Django
|
# Download, setup and configure Django
|
||||||
# ################################################################################
|
################################################################################
|
||||||
# tput setaf 2
|
tput setaf 2
|
||||||
# echo -e "Starting Django project"
|
echo -e "Starting Django project"
|
||||||
# tput setaf 9
|
tput setaf 9
|
||||||
|
|
||||||
# adduser $user 1> /dev/null 2> /dev/null 3> /dev/null
|
adduser $user 1> /dev/null 2> /dev/null 3> /dev/null
|
||||||
# if [ ! -d "/home/$user" ] ; then
|
if [ ! -d "/home/$user" ] ; then
|
||||||
# mkdir /home/$user
|
mkdir /home/$user
|
||||||
# chown -R $user:$user /home/$user
|
chown -R $user:$user /home/$user
|
||||||
# fi
|
fi
|
||||||
# mkdir /home/$user/$projectname
|
mkdir /home/$user/$projectname
|
||||||
# if [ $? -ne 0 ] ; then
|
if [ $? -ne 0 ] ; then
|
||||||
# echo -e "Failed to create $projectname directory. $djamsg"
|
echo -e "Failed to create $projectname directory. $djamsg"
|
||||||
# exit 1
|
exit 1
|
||||||
# fi
|
fi
|
||||||
|
|
||||||
# # virtual environment
|
# virtual environment
|
||||||
# echo -e "\tCreating venv"
|
echo -e "\tCreating venv"
|
||||||
# cd /home/$user/$projectname
|
cd /home/$user/$projectname
|
||||||
# /usr/src/python37/bin/python3.7 -m virtualenv venv 1>> $djalogloc 2>> $djalogloc 3>> $djalogloc
|
/usr/src/python37/bin/python3.7 -m virtualenv venv 1>> $djalogloc 2>> $djalogloc 3>> $djalogloc
|
||||||
# if [ $? -ne 0 ] ; then
|
if [ $? -ne 0 ] ; then
|
||||||
# echo -e "Failed to create virtual environment. $djamsg"
|
echo -e "Failed to create virtual environment. $djamsg"
|
||||||
# exit 1
|
exit 1
|
||||||
# fi
|
fi
|
||||||
# source venv/bin/activate 1>> $djalogloc 2>> $djalogloc 3>> $djalogloc
|
source venv/bin/activate 1>> $djalogloc 2>> $djalogloc 3>> $djalogloc
|
||||||
# if [ $? -ne 0 ] ; then
|
if [ $? -ne 0 ] ; then
|
||||||
# echo -e "Failed to source virtual environment. $djamsg"
|
echo -e "Failed to source virtual environment. $djamsg"
|
||||||
# exit 1
|
exit 1
|
||||||
# fi
|
fi
|
||||||
|
|
||||||
# # pip installs
|
# pip installs
|
||||||
# pips=(django gunicorn psycopg2-binary)
|
pips=(django gunicorn psycopg2-binary)
|
||||||
# for pip in ${pips[@]};
|
for pip in ${pips[@]};
|
||||||
# do
|
do
|
||||||
# echo -e "\tInstalling $pip"
|
echo -e "\tInstalling $pip"
|
||||||
# pip install $pip 1>> $djalogloc 2>> $djalogloc 3>> $djalogloc
|
pip install $pip 1>> $djalogloc 2>> $djalogloc 3>> $djalogloc
|
||||||
# if [ $? -ne 0 ] ; then
|
if [ $? -ne 0 ] ; then
|
||||||
# echo -e "Failed to install $pip. $djamsg"
|
echo -e "Failed to install $pip. $djamsg"
|
||||||
# exit 1
|
exit 1
|
||||||
# fi
|
fi
|
||||||
# done
|
done
|
||||||
|
|
||||||
# if [ $usegit = False ] ; then
|
if [ $usegit = False ] ; then
|
||||||
# # start django project in the project directory
|
# start django project in the project directory
|
||||||
# echo -e "\tStarting django project"
|
echo -e "\tStarting django project"
|
||||||
# django-admin startproject config . 1>> $djalogloc 2>> $djalogloc 3>> $djalogloc
|
django-admin startproject config . 1>> $djalogloc 2>> $djalogloc 3>> $djalogloc
|
||||||
# if [ $? -ne 0 ] ; then
|
if [ $? -ne 0 ] ; then
|
||||||
# echo -e "Failed to start project $projectname with django-admin. $djamsg"
|
echo -e "Failed to start project $projectname with django-admin. $djamsg"
|
||||||
# exit 1
|
exit 1
|
||||||
# fi
|
fi
|
||||||
|
|
||||||
# # update allowed hosts
|
echo -e "echo -e STATIC_ROOT = os.path.join(BASE_DIR, 'static') >> config//settings.py" >> $djalogloc
|
||||||
# echo -e "echo -e sed -i 's/ALLOWED_HOSTS = []/ALLOWED_HOSTS = ['localhost', os.environ.get('HOST')'] config/settings.py" >> $djalogloc
|
echo -e "STATIC_ROOT = os.path.join(BASE_DIR, 'static')" >> config/settings.py
|
||||||
# # | FROM | TO |
|
if [ $? -ne 0 ] ; then
|
||||||
# sed -i "s/ALLOWED_HOSTS = \[\]/ALLOWED_HOSTS = \['localhost', os.environ.get('HOST')\]/" config/settings.py
|
echo -e "Failed to append STATIC_ROOT. $djamsg"
|
||||||
# if [ $? -ne 0 ] ; then
|
exit 1
|
||||||
# echo -e "Failed to change ALLOWED_HOSTS. $djamsg"
|
fi
|
||||||
# exit 1
|
fi
|
||||||
# fi
|
|
||||||
# echo -e "echo -e STATIC_ROOT = os.path.join(BASE_DIR, 'static') >> config//settings.py" >> $djalogloc
|
|
||||||
# echo -e "STATIC_ROOT = os.path.join(BASE_DIR, 'static')" >> config/settings.py
|
|
||||||
# if [ $? -ne 0 ] ; then
|
|
||||||
# echo -e "Failed to append STATIC_ROOT. $djamsg"
|
|
||||||
# exit 1
|
|
||||||
# fi
|
|
||||||
# fi
|
|
||||||
|
|
||||||
# if [ $usegit = True ] ; then
|
if [ $usegit = True ] ; then
|
||||||
# echo -e "\tCloning django project"
|
echo -e "\tCloning django project"
|
||||||
# git init 1>> $gitlogloc 2>> $gitlogloc 3>> $gitlogloc;
|
git init 1>> $gitlogloc 2>> $gitlogloc 3>> $gitlogloc;
|
||||||
# git remote add origin $giturl 1>> $gitlogloc 2>> $gitlogloc 3>> $gitlogloc;
|
git remote add origin $giturl 1>> $gitlogloc 2>> $gitlogloc 3>> $gitlogloc;
|
||||||
# ssh-agent bash -c 'ssh-add $gitkey 1>> $gitlogloc 2>> $gitlogloc 3>> $gitlogloc;
|
ssh-agent bash -c 'ssh-add $gitkey 1>> $gitlogloc 2>> $gitlogloc 3>> $gitlogloc;
|
||||||
# git pull origin master 1>> $gitlogloc 2>> $gitlogloc 3>> $gitlogloc;'
|
git pull origin master 1>> $gitlogloc 2>> $gitlogloc 3>> $gitlogloc;'
|
||||||
# echo -e "\tInstalling pip requirements"
|
echo -e "\tInstalling pip requirements"
|
||||||
# pip install -r requirements.txt 1>> $gitlogloc 2>> $gitlogloc 3>> $gitlogloc
|
pip install -r requirements.txt 1>> $gitlogloc 2>> $gitlogloc 3>> $gitlogloc
|
||||||
# fi
|
fi
|
||||||
|
|
||||||
# # collect static, migrate
|
# update allowed hosts
|
||||||
# echo -e "\tCollecting static"
|
echo -e "echo -e sed -i 's/ALLOWED_HOSTS = []/ALLOWED_HOSTS = ['localhost', os.environ.get('HOST')'] config/settings.py" >> $djalogloc
|
||||||
# python manage.py collectstatic 1>> $djalogloc 2>> $djalogloc 3>> $djalogloc
|
# | FROM | TO |
|
||||||
# if [ $? -ne 0 ] ; then
|
sed -i "s/ALLOWED_HOSTS = \[\]/ALLOWED_HOSTS = \['localhost', os.environ.get('HOST')\]/" config/settings.py
|
||||||
# echo -e "Failed to collect static files. $djamsg"
|
if [ $? -ne 0 ] ; then
|
||||||
# exit 1
|
echo -e "Failed to change ALLOWED_HOSTS. $djamsg"
|
||||||
# fi
|
exit 1
|
||||||
# echo -e "\tMaking migrations"
|
fi
|
||||||
# python manage.py makemigrations 1>> $djalogloc 2>> $djalogloc 3>> $djalogloc
|
|
||||||
# if [ $? -ne 0 ] ; then
|
|
||||||
# echo -e "Failed to make migrations. $djamsg"
|
|
||||||
# exit 1
|
|
||||||
# fi
|
|
||||||
# echo -e "\tMigrating"
|
|
||||||
# python manage.py migrate 1>> $djalogloc 2>> $djalogloc 3>> $djalogloc
|
|
||||||
# if [ $? -ne 0 ] ; then
|
|
||||||
# echo -e "Failed to migrate. You do not survive the winter. $djamsg"
|
|
||||||
# exit 1
|
|
||||||
# fi
|
|
||||||
# deactivate
|
|
||||||
# if [ $? -ne 0 ] ; then
|
|
||||||
# echo -e "Failed to deactivate virtual environment, (this may not be an issue). $djamsg"
|
|
||||||
# fi
|
|
||||||
# chown -R $user:$user .
|
|
||||||
# if [ $? -ne 0 ] ; then
|
|
||||||
# echo -e "Failed to change permissions of $projectname. $djamsg"
|
|
||||||
# exit 1
|
|
||||||
# fi
|
|
||||||
|
|
||||||
# ################################################################################
|
# collect static, migrate
|
||||||
# # Gunicorn
|
echo -e "\tCollecting static"
|
||||||
# # configure gunicorn.conf file
|
python manage.py collectstatic --noinput 1>> $djalogloc 2>> $djalogloc 3>> $djalogloc
|
||||||
# ################################################################################
|
if [ $? -ne 0 ] ; then
|
||||||
# tput setaf 2
|
echo -e "Failed to collect static files. $djamsg"
|
||||||
# echo -e "Setting up gunicorn"
|
exit 1
|
||||||
# tput setaf 9
|
fi
|
||||||
# echo -e "
|
echo -e "\tMaking migrations"
|
||||||
# [Unit]
|
python manage.py makemigrations 1>> $djalogloc 2>> $djalogloc 3>> $djalogloc
|
||||||
# Description=gunicorn daemon
|
if [ $? -ne 0 ] ; then
|
||||||
# After=network.target
|
echo -e "Failed to make migrations. $djamsg"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo -e "\tMigrating"
|
||||||
|
python manage.py migrate 1>> $djalogloc 2>> $djalogloc 3>> $djalogloc
|
||||||
|
if [ $? -ne 0 ] ; then
|
||||||
|
echo -e "Failed to migrate. You do not survive the winter. $djamsg"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
deactivate
|
||||||
|
if [ $? -ne 0 ] ; then
|
||||||
|
echo -e "Failed to deactivate virtual environment, (this may not be an issue). $djamsg"
|
||||||
|
fi
|
||||||
|
chown -R $user:$user .
|
||||||
|
if [ $? -ne 0 ] ; then
|
||||||
|
echo -e "Failed to change permissions of $projectname. $djamsg"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# [Service]
|
################################################################################
|
||||||
# User=$user
|
# Gunicorn
|
||||||
# Group=www-data
|
# configure gunicorn.conf file
|
||||||
# WorkingDirectory=/home/$user/$projectname
|
################################################################################
|
||||||
# ExecStart=/home/$user/$projectname/venv/bin/gunicorn --workers 3 --bind unix:/home/$user/$projectname/$projectname.sock config.wsgi:application
|
tput setaf 2
|
||||||
# Environment=HOST=$hostname
|
echo -e "Setting up gunicorn"
|
||||||
|
tput setaf 9
|
||||||
|
echo -e "
|
||||||
|
[Unit]
|
||||||
|
Description=gunicorn daemon
|
||||||
|
After=network.target
|
||||||
|
|
||||||
# [Install]
|
[Service]
|
||||||
# WantedBy=multi-user.target" > /etc/systemd/system/gunicorn.service
|
User=$user
|
||||||
# echo -e "\tStarting gunicorn"
|
Group=nginx
|
||||||
# systemctl daemon-reload > $gunicornlogloc
|
WorkingDirectory=/home/$user/$projectname
|
||||||
# systemctl start gunicorn >> $gunicornlogloc
|
ExecStart=/home/$user/$projectname/venv/bin/gunicorn --workers 3 --bind unix:/home/$user/$projectname/$projectname.sock config.wsgi:application
|
||||||
# systemctl status gunicorn >> $gunicornlogloc
|
Environment=HOST=$hostname
|
||||||
# echo -e "\tEnabling gunicorn at startup"
|
|
||||||
# systemctl enable gunicorn 1>> $gunicornlogloc 2>> $gunicornlogloc
|
|
||||||
|
|
||||||
# ################################################################################
|
[Install]
|
||||||
# # Nginx
|
WantedBy=multi-user.target" > /etc/systemd/system/gunicorn.service
|
||||||
# # configure nginx
|
echo -e "\tStarting gunicorn"
|
||||||
# ################################################################################
|
systemctl daemon-reload > $gunicornlogloc
|
||||||
# tput setaf 2
|
systemctl start gunicorn >> $gunicornlogloc
|
||||||
# echo -e "Configuring Nginx"
|
systemctl status gunicorn >> $gunicornlogloc
|
||||||
# tput setaf 9
|
echo -e "\tEnabling gunicorn at startup"
|
||||||
# echo -e "
|
systemctl enable gunicorn 1>> $gunicornlogloc 2>> $gunicornlogloc
|
||||||
# server {
|
|
||||||
# listen 80;
|
|
||||||
# server_name $hostname;
|
|
||||||
|
|
||||||
# location = /favicon.ico { access_log off; log_not_found off; }
|
################################################################################
|
||||||
# location /static/ {
|
# Nginx
|
||||||
# root /home/$user/$projectname;
|
# configure nginx
|
||||||
# }
|
################################################################################
|
||||||
|
tput setaf 2
|
||||||
|
echo -e "Configuring Nginx"
|
||||||
|
tput setaf 9
|
||||||
|
echo -e "
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name $hostname;
|
||||||
|
|
||||||
# location / {
|
location = /favicon.ico { access_log off; log_not_found off; }
|
||||||
# proxy_set_header Host \$http_host;
|
location /static/ {
|
||||||
# proxy_set_header X-Real-IP \$remote_addr;
|
root /home/$user/$projectname;
|
||||||
# proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
}
|
||||||
# proxy_set_header X-Forwarded-Proto \$scheme;
|
|
||||||
# proxy_pass http://unix:/home/$user/$projectname/$projectname.sock;
|
|
||||||
# }
|
|
||||||
# }" > /etc/nginx/conf.d/$projectname.conf
|
|
||||||
# # set the nginx user
|
|
||||||
# if [ ! $user = "nginx" ] ; then
|
|
||||||
# sed -i "s/user nginx/user $user nginx/" /etc/nginx/nginx.conf
|
|
||||||
# fi
|
|
||||||
# echo -e "\tStarting nginx"
|
|
||||||
# systemctl restart nginx >> $nginxlogloc
|
|
||||||
# systemctl status nginx >> $nginxlogloc
|
|
||||||
# echo -e "\tEnabling nginx"
|
|
||||||
# systemctl enable nginx 1>> $nginxlogloc 2>> $nginxlogloc
|
|
||||||
|
|
||||||
# tput setaf 2
|
location / {
|
||||||
# echo -e "Done! Navigate to $hostname to access the site. Logs can be found in $logdir"
|
proxy_set_header Host \$http_host;
|
||||||
# tput setaf 9
|
proxy_set_header X-Real-IP \$remote_addr;
|
||||||
# exit 0
|
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto \$scheme;
|
||||||
|
proxy_pass http://unix:/home/$user/$projectname/$projectname.sock;
|
||||||
|
}
|
||||||
|
}" > /etc/nginx/conf.d/$projectname.conf
|
||||||
|
# set the nginx user
|
||||||
|
if [ ! $user = "nginx" ] ; then
|
||||||
|
sed -i "s/user nginx/user $user nginx/" /etc/nginx/nginx.conf
|
||||||
|
fi
|
||||||
|
echo -e "\tStarting nginx"
|
||||||
|
systemctl restart nginx >> $nginxlogloc
|
||||||
|
systemctl status nginx >> $nginxlogloc
|
||||||
|
echo -e "\tEnabling nginx"
|
||||||
|
systemctl enable nginx 1>> $nginxlogloc 2>> $nginxlogloc
|
||||||
|
|
||||||
|
tput setaf 2
|
||||||
|
echo -e "Done! Navigate to $hostname to access the site. Logs can be found in $logdir"
|
||||||
|
tput setaf 9
|
||||||
|
exit 0
|
||||||
8
reset.sh
8
reset.sh
@@ -7,7 +7,7 @@
|
|||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
# source vars
|
# source vars
|
||||||
source vars
|
source ./vars
|
||||||
|
|
||||||
# remove nginx conf
|
# remove nginx conf
|
||||||
tput setaf 2
|
tput setaf 2
|
||||||
@@ -24,3 +24,9 @@ tput setaf 9
|
|||||||
systemctl disable gunicorn 1> /dev/null 2> /dev/null
|
systemctl disable gunicorn 1> /dev/null 2> /dev/null
|
||||||
systemctl stop gunicorn 1> /dev/null 2> /dev/null
|
systemctl stop gunicorn 1> /dev/null 2> /dev/null
|
||||||
rm -f /etc/systemd/system/gunicorn.service
|
rm -f /etc/systemd/system/gunicorn.service
|
||||||
|
|
||||||
|
# remove project
|
||||||
|
tput setaf 2
|
||||||
|
echo "Removing Django project"
|
||||||
|
tput setaf 9
|
||||||
|
rm -rf /home/$user/$projectname
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
# source vars
|
# source vars
|
||||||
source vars
|
source ./vars
|
||||||
|
|
||||||
# remove nginx conf
|
# remove nginx conf
|
||||||
tput setaf 2
|
tput setaf 2
|
||||||
@@ -39,12 +39,12 @@ rm -rf $pyinstalldir
|
|||||||
tput setaf 2
|
tput setaf 2
|
||||||
echo "Uninstalling dependencies"
|
echo "Uninstalling dependencies"
|
||||||
tput setaf 9
|
tput setaf 9
|
||||||
packages=(gcc wget nginx ufw make sqlite3 bzip2 openssl libffi-dev libssl-dev libsqlite3-dev zlib1g-dev libbz2-dev)
|
packages=(gcc wget nginx libsqlite3x-devel.x86_64 postgresql-server postgresql-devel postgresql-contrib bzip2-devel zlib-devel libffi-devel openssl-devel policycoreutils-python.x86_64)
|
||||||
for package in ${packages[@]};
|
for package in ${packages[@]};
|
||||||
do
|
do
|
||||||
echo -e "\tRemoving $package"
|
echo -e "\tRemoving $package"
|
||||||
apt purge -y $package 1>> /dev/null 2>> /dev/null 3>> /dev/null
|
yum -y erase $package 1>> /dev/null 2>> /dev/null 3>> /dev/null
|
||||||
if [ $? -ne 0 ] ; then
|
if [ $? -ne 0 ] ; then
|
||||||
echo -e "\tapt failed to remove $package."
|
echo -e "\tyum failed to remove $package."
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
21
vars
Executable file → Normal file
21
vars
Executable file → Normal file
@@ -4,14 +4,19 @@
|
|||||||
export user=""
|
export user=""
|
||||||
export projectname=""
|
export projectname=""
|
||||||
export hostname=""
|
export hostname=""
|
||||||
export usegit=False # if you have a django git project
|
|
||||||
export giturl="" # url for git project
|
# MAKE SURE root HAS A DEPLOY KEY
|
||||||
export gitkey="" # IdentityFile
|
export usegit=False
|
||||||
|
export giturl=""
|
||||||
|
export gitbranch=""
|
||||||
|
export gitkey=""
|
||||||
|
|
||||||
|
export install_epel_release=False
|
||||||
|
|
||||||
# general install settings
|
# general install settings
|
||||||
export logdir="/var/log/djangosetup/"
|
export logdir="/var/log/djangosetup/"
|
||||||
export aptlogloc=$logdir"apt.log"
|
export yumlogloc=$logdir"yum.log"
|
||||||
export aptlogmsg="See $aptlogloc for more info."
|
export yumlogmsg="See $yumlogloc for more info."
|
||||||
export firelogloc=$logdir"firewall.log"
|
export firelogloc=$logdir"firewall.log"
|
||||||
export firelogmsg="See $firelogloc for more info."
|
export firelogmsg="See $firelogloc for more info."
|
||||||
export pylogloc=$logdir"python.log"
|
export pylogloc=$logdir"python.log"
|
||||||
@@ -24,9 +29,5 @@ export gitlogloc=$logdir"git.log"
|
|||||||
export gitlogmsg="See $gitlogloc for more info."
|
export gitlogmsg="See $gitlogloc for more info."
|
||||||
|
|
||||||
# python settings
|
# python settings
|
||||||
export pylink="https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz"
|
export pylink="https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz"
|
||||||
export sqlink="https://sqlite.org/2019/sqlite-autoconf-3280000.tar.gz"
|
|
||||||
export pyinstalldir="/usr/src/python37"
|
export pyinstalldir="/usr/src/python37"
|
||||||
|
|
||||||
# don't change this by hand
|
|
||||||
export packages=(gcc wget nginx make bzip2 openssl libffi-dev libssl-dev libsqlite3-dev zlib1g-dev libbz2-dev libpq-dev);
|
|
||||||
Reference in New Issue
Block a user