deploy_saleor/deploy-saleor.sh

714 lines
24 KiB
Bash
Raw Normal View History

2021-01-29 01:28:49 +00:00
#########################################################################################
# deploy-saleor.sh
2021-01-29 01:28:49 +00:00
# Author: Aaron K. Nall http://github.com/thewhiterabbit
#########################################################################################
#!/bin/sh
set -e
#########################################################################################
# Get the actual user that logged in
#########################################################################################
UN="$(who am i | awk '{print $1}')"
if [[ "$UN" != "root" ]]; then
HD="/home/$UN"
else
HD="/root"
fi
2021-02-05 19:47:16 +00:00
cd $HD
2021-01-29 01:28:49 +00:00
#########################################################################################
#########################################################################################
# Get the operating system
#########################################################################################
IN=$(uname -a)
arrIN=(${IN// / })
IN2=${arrIN[3]}
arrIN2=(${IN2//-/ })
OS=${arrIN2[1]}
#########################################################################################
#########################################################################################
# Parse options
#########################################################################################
while [ -n "$1" ]; do # while loop starts
case "$1" in
-name)
DEPLOYED_NAME="$2"
shift
;;
-host)
2021-02-05 02:11:19 +00:00
HOST="$2"
shift
;;
-dashboard-uri)
2021-01-29 01:28:49 +00:00
APP_MOUNT_URI="$2"
shift
;;
2021-02-05 02:11:19 +00:00
-static-url)
2021-01-29 01:28:49 +00:00
STATIC_URL="$2"
shift
;;
2021-02-05 02:11:19 +00:00
-media-url)
MEDIA_URL="$2"
shift
;;
-admin-email)
ADMIN_EMAIL="$2"
shift
;;
-admin-pw)
ADMIN_PASS="$2"
shift
;;
2021-01-29 01:28:49 +00:00
-dbhost)
PGDBHOST="$2"
shift
;;
-dbport)
DBPORT="$2"
shift
;;
2021-02-05 02:11:19 +00:00
-graphql-port)
GQL_PORT="$2"
shift
;;
-graphql-uri)
APIURI="$2"
shift
;;
-email)
EMAIL="$2"
shift
;;
-email-pw)
EMAIL_PW="$2"
shift
;;
-email-host)
EMAIL_HOST="$2"
shift
;;
2021-01-29 01:28:49 +00:00
-repo)
REPO="$2"
shift
;;
-v)
vOPT="true"
VERSION="$2"
shift
;;
*)
echo "Option $1 is invalid."
echo "Exiting"
exit 1
;;
esac
shift
done
#########################################################################################
#########################################################################################
# Echo the detected operating system
#########################################################################################
echo ""
echo "$OS detected"
echo ""
sleep 3
#########################################################################################
#########################################################################################
# Select/run Operating System specific commands
#########################################################################################
# Tested working on Ubuntu Server 20.04
# Needs testing on the distributions listed below:
# Debian
# Fedora CoreOS
# Kubernetes
# SUSE CaaS
echo "Installing core dependencies..."
2021-02-05 19:47:16 +00:00
sleep 1
2021-01-29 01:28:49 +00:00
case "$OS" in
Debian)
sudo apt-get update
sudo apt-get install -y build-essential python3-dev python3-pip python3-cffi python3-venv gcc
sudo apt-get install -y libcairo2 libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf2.0-0 libffi-dev shared-mime-info
sudo apt-get install -y nodejs npm postgresql postgresql-contrib
;;
Fedora)
;;
Kubernetes)
;;
SUSE)
;;
Ubuntu)
sudo apt-get update
sudo apt-get install -y build-essential python3-dev python3-pip python3-cffi python3-venv gcc
sudo apt-get install -y libcairo2 libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf2.0-0 libffi-dev shared-mime-info
sudo apt-get install -y nodejs npm postgresql postgresql-contrib
;;
*)
# Unsupported distribution detected, exit
echo "Unsupported Linix distribution detected."
echo "Exiting"
exit 1
;;
esac
#########################################################################################
#########################################################################################
# Tell the user what's happening
#########################################################################################
echo ""
echo "Finished installing core dependencies"
echo ""
2021-02-05 19:47:16 +00:00
sleep 2
2021-01-29 01:28:49 +00:00
echo "Setting up security feature details..."
echo ""
2021-02-05 19:47:16 +00:00
sleep 2
2021-01-29 01:28:49 +00:00
#########################################################################################
#########################################################################################
# Generate a secret key file
#########################################################################################
# Does the key file directory exiet?
if [ ! -d "/etc/saleor" ]; then
sudo mkdir /etc/saleor
else
# Does the key file exist?
if [ -f "/etc/saleor/api_sk" ]; then
# Yes, remove it.
sudo rm /etc/saleor/api_sk
fi
fi
# Create randomized 2049 byte key file
sudo echo $(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 2048| head -n 1) > /etc/saleor/api_sk
#########################################################################################
#########################################################################################
# Set variables for the password, obfuscation string, and user/database names
#########################################################################################
# Generate an 8 byte obfuscation string for the database name & username
OBFSTR=$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 8| head -n 1)
# Append the database name for Saleor with the obfuscation string
PGSQLDBNAME="saleor_db_$OBFSTR"
# Append the database username for Saleor with the obfuscation string
PGSQLUSER="saleor_dbu_$OBFSTR"
# Generate a 128 byte password for the Saleor database user
# TODO: Add special characters once we know which ones won't crash the python script
PGSQLUSERPASS=$(cat /dev/urandom | tr -dc 'A-Za-z0-9' | fold -w 128 | head -n 1)
#########################################################################################
#########################################################################################
# Tell the user what's happening
#########################################################################################
echo "Finished setting up security feature details"
echo ""
2021-02-05 19:47:16 +00:00
sleep 2
2021-01-29 01:28:49 +00:00
echo "Creating database..."
echo ""
2021-02-05 19:47:16 +00:00
sleep 2
2021-01-29 01:28:49 +00:00
#########################################################################################
#########################################################################################
# Create a superuser for Saleor
#########################################################################################
# Create the role in the database and assign the generated password
sudo -i -u postgres psql -c "CREATE ROLE $PGSQLUSER PASSWORD '$PGSQLUSERPASS' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;"
# Create the database for Saleor
sudo -i -u postgres psql -c "CREATE DATABASE $PGSQLDBNAME;"
# TODO - Secure the postgers user account
#########################################################################################
#########################################################################################
# Tell the user what's happening
#########################################################################################
echo "Finished creating database"
echo ""
2021-02-05 19:47:16 +00:00
sleep 2
2021-01-29 01:28:49 +00:00
#########################################################################################
#########################################################################################
# Collect input from the user to assign required installation parameters
#########################################################################################
echo "Please provide details for your Saleor API instillation..."
echo ""
2021-02-05 02:51:51 +00:00
# Get the API host domain
2021-01-29 01:28:49 +00:00
while [ "$HOST" = "" ]
do
2021-02-05 02:51:51 +00:00
echo -n "Enter the API host domain:"
2021-01-29 01:28:49 +00:00
read HOST
done
# Get an optional custom Static URL
2021-02-05 02:51:51 +00:00
if [ "$STATIC_URL" = "" ]; then
2021-02-05 02:11:19 +00:00
echo -n "Enter a custom Static Files URI (optional):"
read STATIC_URL
2021-02-05 03:28:02 +00:00
if [ "$STATIC_URL" != "" ]; then
STATIC_URL="/$STATIC_URL/"
fi
2021-02-05 02:11:19 +00:00
else
STATIC_URL="/$STATIC_URL/"
fi
# Get an optional custom media URL
2021-02-05 02:51:51 +00:00
if [ "$MEDIA_URL" = "" ]; then
2021-02-05 02:11:19 +00:00
echo -n "Enter a custom Media Files URI (optional):"
read MEDIA_URL
2021-02-05 03:28:02 +00:00
if [ "$MEDIA_URL" != "" ]; then
MEDIA_URL="/$MEDIA_URL/"
fi
2021-02-05 02:11:19 +00:00
else
MEDIA_URL="/$MEDIA_URL/"
fi
2021-01-29 01:28:49 +00:00
# Get the Admin's email address
2021-01-29 23:44:35 +00:00
while [ "$ADMIN_EMAIL" = "" ]
2021-01-29 01:28:49 +00:00
do
echo ""
echo -n "Enter the Dashboard admin's email:"
2021-01-29 23:44:35 +00:00
read ADMIN_EMAIL
2021-01-29 01:28:49 +00:00
done
# Get the Admin's desired password
2021-01-29 23:44:35 +00:00
while [ "$ADMIN_PASS" = "" ]
2021-01-29 01:28:49 +00:00
do
echo ""
echo -n "Enter the Dashboard admin's desired password:"
2021-01-29 23:44:35 +00:00
read -s ADMIN_PASS
2021-01-29 01:28:49 +00:00
done
#########################################################################################
#########################################################################################
# Set default and optional parameters
#########################################################################################
if [ "$PGDBHOST" = "" ]; then
PGDBHOST="localhost"
fi
#
if [ "$DBPORT" = "" ]; then
DBPORT="5432"
fi
#
if [[ "$GQL_PORT" = "" ]]; then
GQL_PORT="9000"
fi
#
if [[ "$API_PORT" = "" ]]; then
API_PORT="8000"
fi
#
if [ "$APIURI" = "" ]; then
APIURI="graphql"
fi
#
if [ "$vOPT" = "true" ]; then
if [ "$VERSION" = "" ]; then
VERSION="2.11.1"
fi
2021-01-29 07:56:40 +00:00
else
VERSION="2.11.1"
fi
#
if [ "$STATIC_URL" = "" ]; then
2021-02-04 11:08:18 +00:00
STATIC_URL="/static/"
2021-01-29 07:56:40 +00:00
fi
#
if [ "$MEDIA_URL" = "" ]; then
2021-02-04 11:08:18 +00:00
MEDIA_URL="/media/"
2021-01-29 01:28:49 +00:00
fi
#########################################################################################
#########################################################################################
# Open the selected ports for the API and APP
#########################################################################################
# Open GraphQL port
sudo ufw allow $GQL_PORT
# Open API port
sudo ufw allow $API_PORT
#########################################################################################
2021-02-05 19:47:16 +00:00
#########################################################################################
# Create virtual environment directory
if [ ! -d "$HD/env" ]; then
sudo -u $UN mkdir $HD/env
wait
fi
# Does an old virtual environment for Saleor exist?
if [ ! -d "$HD/env/saleor" ]; then
# Create a new virtual environment for Saleor
sudo -u $UN python3 -m venv $HD/env/saleor
wait
fi
# Activate the virtual environment
2021-02-05 19:56:28 +00:00
source $HD/env/saleor/bin/activate
2021-02-05 19:47:16 +00:00
# Make sure pip is upgraded
2021-02-05 20:20:00 +00:00
python3 -m pip install --upgrade pip
2021-02-05 19:47:16 +00:00
wait
# Install Django
2021-02-05 20:20:00 +00:00
pip3 install Django
2021-02-05 19:47:16 +00:00
wait
# Create a Temporary directory to generate some files we need
#sudo -u $UN mkdir $HD/django
#cd django
# Create the project folder
#sudo -u $UN django-admin.py startproject saleor
# Install uwsgi
2021-02-05 20:20:00 +00:00
pip3 install uwsgi
2021-02-05 19:47:16 +00:00
wait
2021-02-05 20:20:00 +00:00
deactivate
2021-02-05 19:47:16 +00:00
#########################################################################################
2021-01-29 01:28:49 +00:00
#########################################################################################
# Clone the Saleor Git repository
#########################################################################################
# Make sure we're in the user's home directory
cd $HD
# Does the Saleor Dashboard already exist?
2021-01-29 06:31:40 +00:00
if [ -d "$HD/saleor" ]; then
2021-01-29 06:23:42 +00:00
# Remove /saleor directory
2021-01-29 01:28:49 +00:00
sudo rm -R $HD/saleor
2021-01-29 06:23:42 +00:00
wait
2021-01-29 01:28:49 +00:00
fi
2021-01-29 06:23:42 +00:00
#
echo "Cloning Saleor from github..."
echo ""
2021-01-29 01:28:49 +00:00
# Check if the -v (version) option was used
if [ "$vOPT" = "true" ]; then
# Get the Mirumee repo
2021-02-05 19:47:16 +00:00
sudo -u $UN git clone https://github.com/mirumee/saleor.git
2021-01-29 01:28:49 +00:00
else
# Was a repo specified?
if [ "$REPO" = "mirumee" ]; then
# Get the Mirumee repo
2021-02-05 19:47:16 +00:00
sudo -u $UN git clone https://github.com/mirumee/saleor.git
2021-01-29 01:28:49 +00:00
else
2021-01-29 06:58:32 +00:00
# Get the Mirumee repo
2021-02-05 19:47:16 +00:00
sudo -u $UN git clone https://github.com/mirumee/saleor.git
2021-01-29 06:58:32 +00:00
###### For possible later use ######
2021-01-29 01:28:49 +00:00
# Get the forked repo from thewhiterabbit
2021-01-29 06:58:32 +00:00
#git clone https://github.com/mirumee/saleor.git
###### For possible later use ######
2021-01-29 01:28:49 +00:00
fi
fi
wait
2021-02-05 19:47:16 +00:00
#sudo -u $UN cp $HD/django/saleor/asgi.py $HD/saleor/saleor/
#sudo -u $UN cp $HD/django/saleor/wsgi.py $HD/saleor/saleor/
2021-02-06 04:47:52 +00:00
#sudo -u $UN cp $HD/saleor/saleor/wsgi/__init__.py $HD/saleor/saleor/wsgi.py
2021-02-06 03:02:55 +00:00
if [ ! -d "$HD/run" ]; then
sudo -u $UN mkdir $HD/run
else
if [ -f "$HD/run/saleor.sock" ]; then
sudo rm $HD/run/saleor.sock
fi
fi
2021-01-29 01:28:49 +00:00
#########################################################################################
2021-02-05 19:47:16 +00:00
#########################################################################################
# Tell the user what's happening
#########################################################################################
2021-01-29 06:23:42 +00:00
echo "Github cloning complete"
echo ""
2021-02-05 19:47:16 +00:00
sleep 2
#########################################################################################
2021-01-29 06:23:42 +00:00
2021-01-29 01:28:49 +00:00
#########################################################################################
# Replace any parameter slugs in the template files with real paramaters & write them to
# the production files
#########################################################################################
2021-01-29 23:44:35 +00:00
# Replace the settings.py with the production version
if [ -f "$HD/saleor/saleor/settings.py" ]; then
sudo rm $HD/saleor/saleor/settings.py
fi
sudo cp $HD/Deploy_Saleor/resources/saleor/settings.py $HD/saleor/saleor/
# Replace the populatedb.py file with the production version
if [ -f "$HD/saleor/saleor/core/management/commands/populatedb.py" ]; then
sudo rm $HD/saleor/saleor/core/management/commands/populatedb.py
fi
sudo cp $HD/Deploy_Saleor/resources/saleor/populatedb.py $HD/saleor/saleor/core/management/commands/
# Replace the test_core.py file with the production version
2021-01-29 23:50:42 +00:00
#if [ -f "$HD/saleor/saleor/core/tests/test_core.py" ]; then
# sudo rm $HD/saleor/saleor/core/tests/test_core.py
#fi
#sudo cp $HD/Deploy_Saleor/resources/saleor/test_core.py $HD/saleor/saleor/core/tests/
2021-01-29 23:44:35 +00:00
wait
2021-01-29 06:23:42 +00:00
# Does an old saleor.service file exist?
if [ -f "/etc/systemd/system/saleor.service" ]; then
# Remove the old service file
sudo rm /etc/systemd/system/saleor.service
fi
2021-01-29 23:44:35 +00:00
###### This following section is for future use and will be modified to allow an alternative repo clone ######
2021-01-29 01:28:49 +00:00
# Was the -v (version) option used or Mirumee repo specified?
if [ "vOPT" = "true" ] || [ "$REPO" = "mirumee" ]; then
2021-02-05 02:11:19 +00:00
# Create the saleor service file
2021-01-29 01:28:49 +00:00
sudo sed "s/{un}/$UN/
2021-02-05 17:36:43 +00:00
s|{hd}|$HD|g" $HD/Deploy_Saleor/resources/saleor/template.service > /etc/systemd/system/saleor.service
2021-01-29 01:28:49 +00:00
wait
# Does an old server block exist?
if [ -f "/etc/nginx/sites-available/saleor" ]; then
# Remove the old service file
sudo rm /etc/nginx/sites-available/saleor
fi
2021-02-05 02:11:19 +00:00
# Create the saleor server block
2021-01-29 01:28:49 +00:00
sudo sed "s|{hd}|$HD|g
s/{host}/$HOST/g
2021-02-05 02:11:19 +00:00
s|{static}|$STATIC_URL|g
2021-02-06 02:47:14 +00:00
s|{media}|$MEDIA_URL|g" $HD/Deploy_Saleor/resources/saleor/server_block > /etc/nginx/sites-available/saleor
2021-01-29 01:28:49 +00:00
wait
else
# Create the new service file
sudo sed "s/{un}/$UN/
2021-02-05 17:36:43 +00:00
s|{hd}|$HD|g" $HD/Deploy_Saleor/resources/saleor/template.service > /etc/systemd/system/saleor.service
2021-01-29 01:28:49 +00:00
wait
# Does an old server block exist?
if [ -f "/etc/nginx/sites-available/saleor" ]; then
# Remove the old service file
sudo rm /etc/nginx/sites-available/saleor
fi
# Create the new server block
2021-01-29 06:58:32 +00:00
sudo sed "s|{hd}|$HD|g
2021-01-29 01:28:49 +00:00
s/{api_host}/$API_HOST/
s/{host}/$HOST/g
2021-02-05 02:11:19 +00:00
s|{static}|$STATIC_URL|g
s|{media}|$MEDIA_URL|g
s/{api_port}/$API_PORT/" $HD/Deploy_Saleor/resources/saleor/server_block > /etc/nginx/sites-available/saleor
2021-01-29 01:28:49 +00:00
wait
fi
2021-02-05 05:57:04 +00:00
# Create the production uwsgi initialization file
sudo sed "s|{hd}|$HD|g
s/{un}/$UN/" $HD/Deploy_Saleor/resources/saleor/template.uwsgi > $HD/saleor/saleor/wsgi/prod.ini
2021-02-05 02:59:55 +00:00
if [ -d "/var/www/$HOST" ]; then
sudo rm -R /var/www/$HOST
wait
fi
2021-02-05 02:11:19 +00:00
# Create the host directory in /var/www/
sudo mkdir /var/www/$HOST
wait
# Create the media directory
2021-02-05 03:28:02 +00:00
sudo mkdir /var/www/$HOST$MEDIA_URL
2021-02-05 02:11:19 +00:00
# Static directory will be moved into /var/www/$HOST/ after collectstatic is performed
2021-01-29 01:28:49 +00:00
#########################################################################################
#########################################################################################
# Tell the user what's happening
echo "Creating production deployment packages for Saleor API & GraphQL..."
echo ""
#########################################################################################
#########################################################################################
# Setup the environment variables for Saleor API
#########################################################################################
# Build the database URL
DB_URL="postgres://$PGSQLUSER:$PGSQLUSERPASS@$PGDBHOST:$DBPORT/$PGSQLDBNAME"
EMAIL_URL="smtp://$EMAIL:$EMAIL_PW@$EMAIL_HOST:/?ssl=True"
2021-02-06 04:47:52 +00:00
API_HOST=$(hostname -i);
2021-01-29 01:28:49 +00:00
# Build the chosts and ahosts lists
C_HOSTS="$HOST,$API_HOST,localhost,127.0.0.1"
A_HOSTS="$HOST,$API_HOST,localhost,127.0.0.1"
QL_ORIGINS="$HOST,$API_HOST,localhost,127.0.0.1"
# Write the production .env file from template.env
sudo sed "s|{dburl}|$DB_URL|
s|{emailurl}|$EMAIL_URL|
s/{chosts}/$C_HOSTS/
s/{ahosts}/$A_HOSTS/
2021-02-05 02:11:19 +00:00
s/{host}/$HOST/g
s|{static}|$STATIC_URL|g
s|{media}|$MEDIA_URL|g
2021-01-29 23:44:35 +00:00
s/{adminemail}/$ADMIN_EMAIL/
2021-01-29 01:28:49 +00:00
s/{gqlorigins}/$QL_ORIGINS/" $HD/Deploy_Saleor/resources/saleor/template.env > $HD/saleor/.env
wait
#########################################################################################
#########################################################################################
# Copy the uwsgi_params file to /saleor/uwsgi_params
#########################################################################################
2021-01-29 07:03:04 +00:00
sudo cp $HD/Deploy_Saleor/resources/saleor/uwsgi_params $HD/saleor/uwsgi_params
2021-01-29 01:28:49 +00:00
#########################################################################################
#########################################################################################
# Install Saleor for production
#########################################################################################
2021-02-05 05:57:04 +00:00
# Does an old virtual environment vassals for Saleor exist?
if [ -d "$HD/env/saleor/vassals" ]; then
sudo rm -R $HD/env/saleor/vassals
2021-01-29 06:45:18 +00:00
wait
2021-01-29 01:28:49 +00:00
fi
2021-02-05 05:57:04 +00:00
# Create vassals directory in virtual environment
2021-02-05 19:47:16 +00:00
sudo -u $UN mkdir $HD/env/saleor/vassals
2021-02-05 05:57:04 +00:00
wait
# Simlink to the prod.ini
sudo ln -s $HD/saleor/saleor/wsgi/prod.ini $HD/env/saleor/vassals
2021-01-29 06:45:18 +00:00
wait
2021-02-05 20:20:00 +00:00
source $HD/env/saleor/bin/activate
2021-02-05 19:47:16 +00:00
# Make sure we're in the project root directory for Saleor
cd $HD/saleor
# Was the -v (version) option used?
if [ "vOPT" = "true" || $VERSION != "" ]; then
# Checkout the specified version
2021-02-05 20:20:00 +00:00
git checkout $VERSION
2021-02-05 19:47:16 +00:00
wait
fi
2021-01-29 01:28:49 +00:00
# Install the project requirements
2021-02-05 20:20:00 +00:00
pip3 install -r requirements.txt
2021-01-29 01:28:49 +00:00
wait
2021-01-29 23:44:35 +00:00
# Install the decoupler for .env file
2021-02-05 20:20:00 +00:00
pip3 install python-decouple
2021-01-29 23:44:35 +00:00
wait
# Set any secret Environment Variables
2021-02-05 20:20:00 +00:00
export ADMIN_PASS="$ADMIN_PASS"
2021-01-29 01:28:49 +00:00
# Install the project
2021-02-05 20:20:00 +00:00
npm install
2021-01-29 23:44:35 +00:00
wait
2021-01-29 01:28:49 +00:00
# Run an audit to fix any vulnerabilities
2021-02-05 19:47:16 +00:00
#sudo -u $UN npm audit fix
#wait
2021-01-29 01:28:49 +00:00
# Establish the database
2021-02-05 20:20:00 +00:00
python3 manage.py migrate
2021-02-04 10:39:52 +00:00
wait
2021-02-06 02:47:14 +00:00
python3 manage.py populatedb --createsuperuser --sampledata
2021-01-29 23:44:35 +00:00
wait
2021-01-29 01:28:49 +00:00
# Collect the static elemants
2021-02-05 20:20:00 +00:00
python3 manage.py collectstatic
2021-01-29 23:44:35 +00:00
wait
2021-01-29 01:28:49 +00:00
# Build the schema
2021-02-05 20:20:00 +00:00
npm run build-schema
2021-01-29 23:44:35 +00:00
wait
2021-01-29 01:28:49 +00:00
# Build the emails
2021-02-05 20:20:00 +00:00
npm run build-emails
2021-01-29 23:44:35 +00:00
wait
2021-02-05 20:20:00 +00:00
# Exit the virtual environment here? _#_
2021-02-05 20:26:44 +00:00
deactivate
2021-02-05 05:15:44 +00:00
# Set ownership of the app directory to $UN:www-data
sudo chown -R $UN:www-data $HD/saleor
2021-02-05 02:11:19 +00:00
wait
2021-02-05 05:15:44 +00:00
# Run the uwsgi socket and create it for the first time
2021-02-05 05:33:51 +00:00
#sudo uwsgi --ini $HD/saleor/saleor/wsgi/uwsgi.ini --uid www-data --gid www-data --pidfile $HD/saleortemp.pid
#sleep 5
2021-02-05 02:11:19 +00:00
# Stop the uwsgi processes
2021-02-05 05:33:51 +00:00
#uwsgi --stop $HD/saleortemp.pid
2021-02-05 02:11:19 +00:00
# Move static files to /var/www/$HOST
2021-02-06 02:47:14 +00:00
sudo mv $HD/saleor/static /var/www/${HOST}${STATIC_URL}
2021-02-05 02:11:19 +00:00
sudo chown -R www-data:www-data /var/www/$HOST
2021-02-06 02:47:14 +00:00
#sudo chmod -R 776 /var/www/$HOST
2021-01-29 01:28:49 +00:00
#########################################################################################
#########################################################################################
# Tell the user what's happening
#########################################################################################
echo ""
echo "Finished creating production deployment packages for Saleor API & GraphQL"
echo ""
2021-01-29 23:44:35 +00:00
#########################################################################################
2021-02-05 02:11:19 +00:00
2021-01-29 23:44:35 +00:00
#########################################################################################
# Call the dashboard deployment script
#########################################################################################
2021-02-05 02:11:19 +00:00
source $HD/Deploy_Saleor/deploy-dashboard.sh
#########################################################################################
2021-02-07 00:44:29 +00:00
#########################################################################################
# Enable the Saleor service
#########################################################################################
# Enable
sudo systemctl enable saleor.service
# Reload the daemon
sudo systemctl daemon-reload
# Start the service
sudo systemctl start saleor.service
#########################################################################################
#########################################################################################
# Tell the user what's happening
echo "Creating undeploy.sh for undeployment scenario..."
#########################################################################################
if [ "$SAME_HOST" = "no" ]; then
sed "s|{rm_app_host}|sudo rm -R /var/www/$APP_HOST|g
s|{host}|$HOST|
s|{gql_port}|$GQL_PORT|
s|{api_port}|$API_PORT|" $HD/Deploy_Saleor/template.undeploy > $HD/Deploy_Saleor/undeploy.sh
wait
else
BLANK=""
sed "s|{rm_app_host}|$BLANK|g
s|{host}|$HOST|
s|{gql_port}|$GQL_PORT|
s|{api_port}|$API_PORT|" $HD/Deploy_Saleor/template.undeploy > $HD/Deploy_Saleor/undeploy.sh
wait
fi
#########################################################################################
2021-02-05 02:11:19 +00:00
#########################################################################################
# Tell the user what's happening
#########################################################################################
echo "I think we're done here."
echo "Test the installation."
2021-01-29 01:28:49 +00:00
#########################################################################################