-
-
Save dohvis/e7668543dc24873190e7728ebfe8aaf0 to your computer and use it in GitHub Desktop.
Install uWSGI and nginx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# uWSGI & nginx installation script | |
# Created at 2017-06-27 by Frank Yang (https://github.com/puilp0502) | |
# Tested on Ubuntu Server 16.04 LTS | |
# Check if user is root | |
if [[ $UID -ne '0' ]]; then | |
echo "This script needs to be run as root; exiting..." | |
exit 0 | |
fi | |
if [[ $#argv < 1 ]]; then | |
echo "Usage: $0 [Service-Name](username)" | |
exit 0 | |
fi | |
username=$1 | |
# Install python and devtools (required to install uwsgi) | |
apt-get update --qq | |
echo "" | |
echo "##################################################" | |
echo "# Installing python & devtools #" | |
echo "##################################################" | |
echo "" | |
apt-get install -qq -y python3 python3-dev gcc | |
# Install pip the pythonic way | |
echo "" | |
echo "##################################################" | |
echo "# Installing pip #" | |
echo "##################################################" | |
echo "" | |
curl https://bootstrap.pypa.io/get-pip.py > get-pip.py | |
python3 get-pip.py -q | |
rm get-pip.py | |
# Install virtualenv | |
echo "" | |
echo "##################################################" | |
echo "# Installing virtualenv & virtualenvwrapper #" | |
echo "##################################################" | |
echo "" | |
pip install -q virtualenv virtualenvwrapper | |
cat <<EOF >> ~/.bashrc | |
# Virtualenvwrapper config | |
export WORKON_HOME=$HOME/.venv | |
export VIRTUALENVWRAPPER_SCRIPT=/usr/local/bin/virtualenvwrapper.sh | |
source /usr/local/bin/virtualenvwrapper.sh | |
EOF | |
# Install uwsgi | |
echo "" | |
echo "##################################################" | |
echo "# Installing uWSGI #" | |
echo "##################################################" | |
echo "" | |
pip install -q uwsgi | |
# Configure uWSGI systemd daemon | |
cat <<EOF > /etc/systemd/system/uwsgi.service | |
[Unit] | |
Description=uWSGI $username service | |
[Service] | |
RuntimeDirectory=uwsgi | |
RuntimeDirectoryMode=755 | |
User=$username | |
Group=www-data | |
ExecStart=/usr/local/bin/uwsgi --$username /etc/uwsgi/sites | |
Restart=always | |
KillSignal=SIGQUIT | |
Type=notify | |
NotifyAccess=all | |
[Install] | |
WantedBy=multi-user.target | |
EOF | |
systemctl enable uwsgi | |
# Install nginx | |
echo "" | |
echo "##################################################" | |
echo "# Installing nginx #" | |
echo "##################################################" | |
echo "" | |
apt-get install -y -qq nginx | |
adduser -q --gecos "" --shell /bin/false --no-create-home --ingroup www-data --disabled-password --disabled-login $username | |
mkdir -p /etc/uwsgi/sites | |
chown -R $username:www-data /etc/uwsgi | |
# Start service | |
echo "" | |
echo "##################################################" | |
echo "# Starting service #" | |
echo "##################################################" | |
echo "" | |
echo -n "Starting nginx..." | |
systemctl start nginx | |
if [[ $? == '0' ]]; then | |
echo ' [OK]' | |
else | |
echo ' [FAILED]' | |
fi | |
echo -n "Starting uWSGI..." | |
systemctl start uwsgi | |
if [[ $? == '0' ]]; then | |
echo ' [OK]' | |
else | |
echo ' [FAILED]' | |
fi | |
if [[ $1 == '--shutup' ]]; then | |
exit 0; | |
else | |
echo "" | |
echo "##################################################" | |
echo "# Installation Completed #" | |
echo "##################################################" | |
echo "" | |
echo "Installation has been completed!" | |
echo "source ~/.bashrc to enable virtualenvwrapper." | |
echo "" | |
sleep 1 | |
echo "Now you need to actually configure your site." | |
echo "https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-uwsgi-and-nginx-on-ubuntu-16-04#install-and-configure-nginx-as-a-reverse-proxy" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment