Fixes on deployment

This commit is contained in:
Marc Aymerich 2015-10-02 12:09:05 +00:00
parent 06a6a78d77
commit 5a2fd3b4ad
1 changed files with 82 additions and 51 deletions

View File

@ -3,83 +3,113 @@
set -ue set -ue
# bash <( curl https://raw.githubusercontent.com/glic3rinu/django-orchestra/master/scripts/containers/deploy.sh ) # bash <( curl https://raw.githubusercontent.com/glic3rinu/django-orchestra/master/scripts/containers/deploy.sh ) [--noinput username]
function main () { function main () {
bold=$(tput -T ${TERM:-xterm} bold) run_ () {
normal=$(tput -T ${TERM:-xterm} sgr0)
[ $(whoami) == 'root' ] && {
echo -e "\nErr. This script should run as a regular user\n" >&2
exit 1
}
run () {
echo " ${bold}\$ ${@}${normal}" echo " ${bold}\$ ${@}${normal}"
${@} ${@}
} }
# Test sudo privileges surun_ () {
sudo true echo " ${bold}\$ su $USER -c \"${@}\"${normal}"
su $USER -c "${@}"
while true; do }
read -p "Enter a project name [panel]: " project_name
if [[ "$project_name" == "" ]]; then if [[ $# -eq 3 ]]; then
project_name="panel" if [[ $1 != '--noinput' ]]; then
break echo "What argument is $1?" >&2
elif [[ ! $(echo "$project_name" | grep '^[_a-zA-Z]\w*$') ]]; then exit 2
if [[ ! $(echo "$project_name" | grep '^[_a-zA-Z]') ]]; then elif ! id $2; then
message='make sure the name begins with a letter or underscore' echo "User $2 does not exist" >&2
else exit 3
message='use only numbers, letters and underscores' fi
fi run=surun_
echo "'$project_name' is not a valid %s name. Please $message." sudorun=run_
elif [[ $# -eq 2 ]]; then
if [[ $1 != '--noinput' ]]; then
echo "What argument is $1?" >&2
else else
break echo "--noinput should provide a username" >&2
fi exit 1
done else
[ $(whoami) == 'root' ] && {
echo -e "\nErr. This script should run as a regular user\n" >&2
exit 1
}
run=run_
sudorun=run_ sudo
# Test sudo privileges
sudo true
fi
bold=$(tput -T ${TERM:-xterm} bold)
normal=$(tput -T ${TERM:-xterm} sgr0)
project_name="panel"
if [[ $1 != '--noinput' ]]; then
while true; do
read -p "Enter a project name [panel]: " project_name
if [[ "$project_name" == "" ]]; then
project_name="panel"
break
elif [[ ! $(echo "$project_name" | grep '^[_a-zA-Z]\w*$') ]]; then
if [[ ! $(echo "$project_name" | grep '^[_a-zA-Z]') ]]; then
message='make sure the name begins with a letter or underscore'
else
message='use only numbers, letters and underscores'
fi
echo "'$project_name' is not a valid %s name. Please $message."
else
break
fi
done
fi
# TODO detect if already installed and don't ask stupid question # TODO detect if already installed and don't ask stupid question
while true; do task=cronbeat
read -p "Do you want to use celery or cronbeat (orchestra.contrib.tasks) for task execution [cronbeat]? " task if [[ $1 != '--noinput' ]]; then
case $task in while true; do
'celery' ) task=celery; break;; read -p "Do you want to use celery or cronbeat (orchestra.contrib.tasks) for task execution [cronbeat]? " task
'cronbeat' ) task=orchestra.contrib.tasks; break;; case $task in
'' ) task=orchestra.contrib.tasks; break;; 'celery' ) task=celery; break;;
* ) echo "Please answer celery or cronbeat.";; 'cronbeat' ) task=cronbeat; break;;
esac '' ) task=cronbeat; break;;
done * ) echo "Please answer celery or cronbeat.";;
esac
done
fi
run sudo pip3 install django-orchestra==dev \ sudorun pip3 install django-orchestra==dev \
--allow-external django-orchestra \ --allow-external django-orchestra \
--allow-unverified django-orchestra --allow-unverified django-orchestra
run sudo orchestra-admin install_requirements sudorun orchestra-admin install_requirements
run cd $(eval echo ~$USER) run cd $(eval echo ~$USER)
run orchestra-admin startproject $project_name run orchestra-admin startproject $project_name
run cd $project_name run cd $project_name
sudo service postgresql start sudorun service postgresql start
run sudo python3 -W ignore manage.py setuppostgres sudorun python3 -W ignore manage.py setuppostgres $1
run python3 -W ignore manage.py migrate run python3 -W ignore manage.py migrate
if [[ "$task" == "celery" ]]; then if [[ "$task" == "celery" ]]; then
run sudo apt-get install rabbitmq-server sudorun apt-get install rabbitmq-server
run sudo python3 -W ignore manage.py setupcelery --username $USER sudorun python3 -W ignore manage.py setupcelery --username $USER
else else
run python3 -W ignore manage.py setupcronbeat run python3 -W ignore manage.py setupcronbeat
run python3 -W ignore manage.py syncperiodictasks run python3 -W ignore manage.py syncperiodictasks
fi fi
run sudo python3 -W ignore manage.py setuplog --noinput sudorun python3 -W ignore manage.py setuplog --noinput
run python3 -W ignore manage.py collectstatic --noinput run python3 -W ignore manage.py collectstatic --noinput
run sudo apt-get install nginx-full uwsgi uwsgi-plugin-python3 sudorun apt-get install nginx-full uwsgi uwsgi-plugin-python3
run sudo python3 -W ignore manage.py setupnginx --user $USER sudorun python3 -W ignore manage.py setupnginx --user $USER
run sudo python3 -W ignore manage.py restartservices sudorun python3 -W ignore manage.py restartservices
run sudo python3 -W ignore manage.py startservices sudorun python3 -W ignore manage.py startservices
run python3 -W ignore manage.py check --deploy run python3 -W ignore manage.py check --deploy
ip_addr=$(ip addr show eth0 | grep 'inet ' | sed -r "s/.*inet ([^\s]*).*/\1/" | cut -d'/' -f1) ip_addr=$(ip addr show eth0 | grep 'inet ' | sed -r "s/.*inet ([^\s]*).*/\1/" | cut -d'/' -f1)
@ -87,11 +117,12 @@ function main () {
ip_addr=127.0.0.1 ip_addr=127.0.0.1
fi fi
echo echo
echo -e "${bold}Checking if Orchestra is working at https://${ip_addr}/admin/${normal} ...\n" echo
echo "${bold}> Checking if Orchestra is serving at https://${ip_addr}/admin/${normal} ..."
if [[ $(curl https://$ip_addr/admin/ -I -k -s | grep 'HTTP/1.1 302 FOUND') ]]; then if [[ $(curl https://$ip_addr/admin/ -I -k -s | grep 'HTTP/1.1 302 FOUND') ]]; then
echo -e "${bold}Orchestra appears to be working!\n" echo -e "${bold} ** Orchestra appears to be working!${normal}\n"
else else
echo -e "${bold}Err. Orchestra is not responding responding at https://${ip_addr}/admin/${normal}\n" >&2 echo -e "${bold} ** Err. Orchestra is not responding responding at https://${ip_addr}/admin/${normal}\n" >&2
fi fi
} }