separate vars

This commit is contained in:
ducoterra
2018-09-16 18:44:43 -04:00
parent 9bd38cd0c7
commit 4c27ac1b4d
3 changed files with 128 additions and 78 deletions

153
README.md
View File

@@ -1,30 +1,38 @@
# Django Setup for CentOS 7
## install.sh
### Variables
when you open install.sh you'll see these variables at the top:
## Quick Install
```bash
# vars
yumlogloc="/root/logs/yum.log"
yumlogmsg="See logs/yum.log for more info."
firelogloc="/root/logs/firewall.log"
firelogmsg="See logs/firewall.log for more info."
pylogloc="/root/logs/python.log"
pylogmsg="See logs/python.log for more info."
pylink="https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz"
# Django Project Settings
source vars
./install.sh
```
## A more detailed explanation
### vars
```bash
# django project settings
user="centos"
djalog="/root/logs/django.log"
djamsg="See logs/django.log for more info."
projectname="mysite"
hostname="centos.duco.net"
letsencrypt=False
# if you are doing this on a personal install you will prob need this.
# set True if CentOS minimal install
install_epel_release=False
# general install settings
logdir="/var/log/djangosetup/"
yumlogloc=$logdir"yum.log"
yumlogmsg="See $yumlogloc for more info."
firelogloc=$logdir"firewall.log"
firelogmsg="See $firelogloc for more info."
pylogloc=$logdir"python.log"
pylogmsg="See $pylogloc for more info."
djalogloc=$logdir"django.log"
djamsg="See $djalogloc for more info."
gunicornlogloc=$logdir"gunicorn.log"
nginxlogloc=$logdir"nginx.log"
# python settings
pylink="https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz"
```
These can (and should) be changed to match your configuration needs. For example: any of the "logloc" log location variables can be changed to log somewhere else. The "logmsg" log message variables can be changed to reflect different log locations or output a custom message.
These variables can (and should) be changed to match your configuration needs. For example: any of the "logloc" log location variables can be changed to log somewhere else. The "logmsg" log message variables can be changed to reflect different log locations or output a custom message.
The Django Project Settings variables should be changed to match your configuration. You have (essentially) 3 options for user configuration:
1. user = "[primary (sudo) user here]"
@@ -35,63 +43,110 @@ 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 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.
### Dependencies
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. There are a few measures you can take to prevent this. One of those is understanding exactly what this script does.
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 includes, among other things, nginx. Kinda hard to run the site without that.
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.sh
### Dependencies
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
# check if root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
echo -e "This script must be run as root"
exit 1
fi
cd /root/
echo "Installing dependencies..."
tput setaf 2
echo -e "Installing dependencies"
tput setaf 0
# create necessary dirs
if [ ! -d "/root/scripts" ] ; then
mkdir scripts
fi
if [ ! -d "/root/logs" ] ; then
mkdir logs
if [ ! -d $logdir ] ; then
mkdir $logdir
fi
if [ $install_epel_release = True ] ; then
yum -y install epel-release
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, the installer can't use yum and won't work. It then creates the necessary directories to prevent future complaints and installs the aforementioned epel-release package if you want it.
```bash
yum -y install 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 >> $yumlogloc
firewall-cmd --zone=public --add-port=80/tcp --permanent >> logs/firewall.log
firewall-cmd --zone=public --add-port=443/tcp --permanent >> logs/firewall.log
firewall-cmd --reload >> logs/firewall.log
semanage permissive -a httpd_t >> logs/firewall.log
# install dependencies
echo -e "\tInstalling gcc"
yum -y install gcc 1>> $yumlogloc 2>> $yumlogloc 3>> $yumlogloc
if [ $? -ne 0 ] ; then
echo -e "yum failed to install gcc. $yumlogmsg"
exit 1
fi
```
These are the 5 commands the script runs next (without all the error checking and logging). If there were any commands I would recommend you run manually: it's these. Definitely read through the yum install logs to make sure everything went smoothly. Like I mentioned earlier: yum doesn't like to behave.
The next part of the script installs yum dependencies. Each install will check if it was successful and stop everything it it wasn't.
The firewall commands are specific to a CentOS 7 minimal install. You may not need them. They may not work at all. 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.
```bash
# set firewall
echo -e "firewall-cmd --zone=public --add-port=80/tcp --permanent" > $firelogloc
firewall-cmd --zone=public --add-port=80/tcp --permanent >> $firelogloc
if [ $? -ne 0 ] ; then
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
fi
```
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 causing 502 errors and loud swearing.
```bash
wget $pylink > $pylogloc
tar xf Python-3.7.0.tar.xz >> $pylogloc
cd Python-3.7.0
./configure --prefix /usr/src/python37 >> $pylogloc
make >> $pylogloc
make altinstall >> $pylogloc
/usr/src/python37/bin/python3.7 -m pip install --upgrade pip >> $pylogloc
/usr/src/python37/bin/python3.7 -m pip install virtualenv >> $pylogloc
cd /root/
rm Python-3.7.0.tar.xz >> $pylogloc
wget $pylink 1> $pylogloc 2>> $pylogloc
if [ $? -ne 0 ] ; then
echo -e "Failed to fetch python, make sure wget is installed and $pylink is what you're after. $pylogmsg"
exit 1
fi
```
After configuring the firewall the script will fetch python from the link provided.
```bash
echo -e "\tConfigure"
./configure --prefix /usr/src/python37 1>> $pylogloc 2>> $pylogloc
if [ $? -ne 0 ] ; then
echo -e "./configure failed. $pylogmsg"
exit 1
fi
echo -e "\tMake"
make 1>> $pylogloc 2>> $pylogloc
if [ $? -ne 0 ] ; then
echo -e "make failed. $pylogmsg"
exit 1
fi
echo -e "\tMake altinstall"
make altinstall 1>> $pylogloc 2>> $pylogloc
if [ $? -ne 0 ] ; then
echo -e "make altinstall failed. $pylogmsg"
exit 1
fi
```
If you've ever installed Python from source this part should look familiar. Right now it grabs the latest version of Python 3.7 and installs it to /usr/src/python37/. It uses alt install to prevent conflict with previous versions of python (I've been told CentOS will break if it can't find python 2, a real problem if you use make install).

View File

@@ -1,32 +1,3 @@
# vars
user="centos"
projectname="mysite"
hostname="centos.duco.net"
letsencrypt=False
pylink="https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz"
# if you are doing this on a personal install you will prob need this.
install_epel_release=False
logdir="/var/log/djangosetup/"
scriptdir="/root/scripts"
yumlogloc=$logdir"yum.log"
yumlogmsg="See $yumlogloc for more info."
firelogloc=$logdir"firewall.log"
firelogmsg="See $firelogloc for more info."
pylogloc=$logdir"python.log"
pylogmsg="See $pylogloc for more info."
djalogloc=$logdir"django.log"
djamsg="See $djalogloc for more info."
gunicornlogloc=$logdir"gunicorn.log"
nginxlogloc=$logdir"nginx.log"
################################################################################
# Dependencies
# Installs Dependencies automatically

24
vars Normal file
View File

@@ -0,0 +1,24 @@
# django project settings
user="centos"
projectname="mysite"
hostname="centos.duco.net"
letsencrypt=False
# set True if CentOS minimal install
install_epel_release=False
# general install settings
logdir="/var/log/djangosetup/"
yumlogloc=$logdir"yum.log"
yumlogmsg="See $yumlogloc for more info."
firelogloc=$logdir"firewall.log"
firelogmsg="See $firelogloc for more info."
pylogloc=$logdir"python.log"
pylogmsg="See $pylogloc for more info."
djalogloc=$logdir"django.log"
djamsg="See $djalogloc for more info."
gunicornlogloc=$logdir"gunicorn.log"
nginxlogloc=$logdir"nginx.log"
# python settings
pylink="https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz"