Created
March 23, 2012 14:40
-
-
Save morsik/2171277 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
e="echo -e" | |
en="echo -en" | |
function i { | |
if [[ $1 == "ok" ]] | |
then | |
$e "\033[1;32mok\033[G * \033[0m" | |
elif [[ $1 == "fail" ]] | |
then | |
$e "\033[1;31mfailed\033[G * \033[0m" | |
else | |
$en "\033[1;36m * \033[0m$1...\033[0m " | |
fi | |
} | |
function print { | |
$e "\033[1;32m * \033[0m$1\033[0m" | |
} | |
function critical { | |
$e "\033[1;31m ! \033[1;37m$1\033[0m" | |
} | |
function warn { | |
$e "\033[1;33m * \033[0m$1\033[0m" | |
} |
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 | |
PROJECT=${1} | |
# Replace these three settings. | |
PROJDIR="${HOME}/sites-django/${PROJECT}" | |
SOCKDIR="/var/lib/darkadmin/django" | |
SOCKFILE="${SOCKDIR}/`whoami`-${PROJECT}.sock" | |
PIDFILE="${SOCKDIR}/`whoami`-${PROJECT}.pid" | |
VENVDIR="${HOME}/virtualenv" | |
. /opt/mng/functions.sh | |
if test -z ${1}; then | |
echo "usage: ${0} <project> [<venv>]" | |
echo "put your venvs in ~/virtualenv" | |
echo "if no venv is specified, 'default' will be used, so please create basic venv in ~/virtualenv/default" | |
exit | |
fi | |
if [ ! -d "${PROJDIR}" ]; then | |
critical "Project '${PROJECT}' does not exists" | |
exit | |
fi | |
cd ${PROJDIR} | |
i "Stopping ${PROJECT}" | |
ret=1 | |
if [ -f ${PIDFILE} ]; then | |
kill `cat -- ${PIDFILE}` | |
ret=$? | |
rm -f -- ${PIDFILE} | |
fi | |
if [ ${ret} == 0 ]; then | |
i ok | |
else | |
i fail | |
fi | |
export HTTPS=on | |
VENV="default" | |
if ! test -z ${2}; then | |
if [ -e ${VENVDIR}/${2} ]; then | |
VENV=${2} | |
else | |
warn "Python virtulenv '\033[1;37m${2}\033[0m' doesn't exists. Using default" | |
fi | |
fi | |
. ${VENVDIR}/${VENV}/bin/activate --no-site-packages | |
if [ -e ${PROJDIR}/requirements.txt ]; then | |
print "Installing and updating packages in virtualenv" | |
pip install -r ${PROJDIR}/requirements.txt | |
fi | |
i "Starting ${PROJECT}" | |
out=$(python manage.py runfcgi socket=${SOCKFILE} pidfile=${PIDFILE} minspare=1 maxspare=1 maxchildren=2 2>&1) | |
if [ $? == 0 ]; then | |
i ok | |
chmod 777 ${SOCKFILE} | |
else | |
i fail | |
echo "${out}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment