diff options
Diffstat (limited to 'bitbake/bin/toaster')
-rwxr-xr-x | bitbake/bin/toaster | 173 |
1 files changed, 123 insertions, 50 deletions
diff --git a/bitbake/bin/toaster b/bitbake/bin/toaster index 75c7a076b1..04f2e99378 100755 --- a/bitbake/bin/toaster +++ b/bitbake/bin/toaster @@ -37,7 +37,7 @@ function webserverKillAll() kill -SIGTERM -$(< ${pidfile}) 2>/dev/null sleep 1; # Kill processes if they are still running - may happen in interactive shells - ps fux | grep "python.*manage.py" | awk '{print $2}' | xargs kill + ps fux | grep "python.*manage.py runserver" | awk '{print $2}' | xargs kill done; rm ${pidfile} fi @@ -68,12 +68,14 @@ function webserverStartAll() python $BBBASEDIR/lib/toaster/manage.py checksettings --traceback || retval=1 fi if [ $retval -eq 0 ]; then - echo "Starting webserver" - python $BBBASEDIR/lib/toaster/manage.py runserver 0.0.0.0:8000 </dev/null >${BUILDDIR}/toaster_web.log 2>&1 & echo $! >${BUILDDIR}/.toastermain.pid + echo "Starting webserver..." + python $BBBASEDIR/lib/toaster/manage.py runserver "0.0.0.0:$WEB_PORT" </dev/null >>${BUILDDIR}/toaster_web.log 2>&1 & echo $! >${BUILDDIR}/.toastermain.pid sleep 1 if ! cat "${BUILDDIR}/.toastermain.pid" | xargs -I{} kill -0 {} ; then retval=1 rm "${BUILDDIR}/.toastermain.pid" + else + echo "Webserver address: http://0.0.0.0:$WEB_PORT/" fi fi return $retval @@ -83,8 +85,10 @@ function webserverStartAll() function addtoConfiguration() { - echo "#Created by toaster start script" > ${BUILDDIR}/conf/$2 - echo $1 >> ${BUILDDIR}/conf/$2 + file=$1 + shift + echo "#Created by toaster start script" > ${BUILDDIR}/conf/$file + for var in "$@"; do echo $var >> ${BUILDDIR}/conf/$file; done } INSTOPSYSTEM=0 @@ -99,7 +103,7 @@ function stop_system() kill $(< ${BUILDDIR}/.toasterui.pid ) 2>/dev/null rm ${BUILDDIR}/.toasterui.pid fi - BBSERVER=0.0.0.0:8200 bitbake -m + BBSERVER=0.0.0.0:-1 bitbake -m unset BBSERVER webserverKillAll # force stop any misbehaving bitbake server @@ -122,67 +126,137 @@ function notify_chldexit() { } +function verify_prereq() { + # Verify prerequisites + + if ! echo "import django; print (1,) == django.VERSION[0:1] and django.VERSION[1:2][0] in (5,6)" | python 2>/dev/null | grep True >/dev/null; then + echo -e "This program needs Django 1.5 or 1.6. Please install with\n\npip install django==1.6\n" + return 2 + fi + + if ! echo "import south; print reduce(lambda x, y: 2 if x==2 else 0 if x == 0 else y, map(lambda x: 1+cmp(x[1]-x[0],0), zip([0,8,4], map(int,south.__version__.split(\".\"))))) > 0" | python 2>/dev/null | grep True >/dev/null; then + echo -e "This program needs South 0.8.4. Please install with\n\npip install south==0.8.4\n" + return 2 + fi + return 0 +} + + +# read command line parameters + BBBASEDIR=`dirname ${BASH_SOURCE}`/.. RUNNING=0 +NOTOASTERUI=0 +WEBSERVER=1 +TOASTER_BRBE="" +WEB_PORT="8000" + +for param in $*; do + case $param in + noui ) + NOTOASTERUI=1 + ;; + noweb ) + WEBSERVER=0 + ;; + brbe=* ) + TOASTER_BRBE=$'\n'"TOASTER_BRBE=\""${param#*=}"\"" + ;; + webport=*) + WEB_PORT="${param#*=}" + esac +done + + if [ -z "$ZSH_NAME" ] && [ `basename \"$0\"` = `basename \"$BASH_SOURCE\"` ]; then # We are called as standalone. We refuse to run in a build environment - we need the interactive mode for that. # Start just the web server, point the web browser to the interface, and start any Django services. + if ! verify_prereq; then + echo -e "Error: Could not verify that the needed dependencies are installed. Please use virtualenv and pip to install dependencies listed in toaster-requirements.txt" 1>&2; + exit 1; + fi + if [ -n "$BUILDDIR" ]; then - echo -e "Error: build/ directory detected. Toaster will not start in managed mode if a build environment is detected.\nUse a clean terminal to start Toaster." 1>&2; + echo -e "Error: It looks like you sourced oe-init-build-env. Toaster cannot start in build mode from an oe-core build environment.\n You should be starting Toaster from a new terminal window." 1>&2; exit 1; fi + if [ "x`which daemon`" == "x" ]; then + echo -e "Failed dependency; toaster needs the 'daemon' program in order to be able to start builds'. Please install the 'daemon' program from your distribution repositories or http://www.libslack.org/daemon/" 1>&2; + exit 1; + fi + # Define a fake builddir where only the pid files are actually created. No real builds will take place here. - BUILDDIR=/tmp + BUILDDIR=/tmp/toaster_$$ + if [ -d "$BUILDDIR" ]; then + echo -e "Previous toaster run directory $BUILDDIR found, cowardly refusing to start. Please remove the directory when that toaster instance is over" 2>&1 + exit 1; + fi + + mkdir -p "$BUILDDIR" + RUNNING=1 function trap_ctrlc() { echo "** Stopping system" webserverKillAll RUNNING=0 } + + function do_cleanup() { + find "$BUILDDIR" -type f | xargs rm + rmdir "$BUILDDIR" + } + function cleanup() { + if grep -ir error "$BUILDDIR" >/dev/null; then + if grep -irn "That port is already in use" "$BUILDDIR"; then + echo "You can use the \"webport=PORTNUMBER\" parameter to start Toaster on a different port (port $WEB_PORT is already in use)" + do_cleanup + else + echo -e "\nErrors found in the Toaster log files present in '$BUILDDIR'. Directory will not be cleaned.\n Please review the errors and notify toaster@yoctoproject.org or submit a bug https://bugzilla.yoctoproject.org/enter_bug.cgi?product=Toaster" + fi + else + echo "No errors found, removing the run directory '$BUILDDIR'" + do_cleanup + fi; + } TOASTER_MANAGED=1 export TOASTER_MANAGED=1 - if ! webserverStartAll; then + if [ $WEBSERVER -gt 0 ] && ! webserverStartAll; then echo "Failed to start the web server, stopping" 1>&2; + cleanup exit 1; fi - xdg-open http://0.0.0.0:8000/ >/dev/null 2>&1 & + if [ $WEBSERVER -gt 0 ]; then + echo "Starting browser..." + xdg-open http://127.0.0.1:$WEB_PORT/ >/dev/null 2>&1 & + fi trap trap_ctrlc SIGINT - echo "Running. Stop with Ctrl-C" + echo "Toaster is now running. You can stop it with Ctrl-C" while [ $RUNNING -gt 0 ]; do - python $BBBASEDIR/lib/toaster/manage.py runbuilds - sleep 1 + python $BBBASEDIR/lib/toaster/manage.py runbuilds 2>&1 | tee -a "$BUILDDIR/toaster.log" + sleep 1 done + cleanup echo "**** Exit" exit 0 fi -# We make sure we're running in the current shell and in a good environment -if [ -z "$BUILDDIR" ] || [ -z `which bitbake` ]; then - echo "Error: Build environment is not setup or bitbake is not in path." 1>&2; - return 2 -fi - - -# Verify prerequisites - -if ! echo "import django; print (1,) == django.VERSION[0:1] and django.VERSION[1:2][0] in (5,6)" | python 2>/dev/null | grep True >/dev/null; then - echo -e "This program needs Django 1.5 or 1.6. Please install with\n\npip install django==1.6" - return 2 +if ! verify_prereq; then + echo -e "Error: Could not verify that the needed dependencies are installed. Please use virtualenv and pip to install dependencies listed in toaster-requirements.txt" 1>&2; + return 1; fi -if ! echo "import south; print [0,8,4] == map(int,south.__version__.split(\".\"))" | python 2>/dev/null | grep True >/dev/null; then - echo -e "This program needs South 0.8.4. Please install with\n\npip install south==0.8.4" + +# We make sure we're running in the current shell and in a good environment +if [ -z "$BUILDDIR" ] || [ -z `which bitbake` ]; then + echo "Error: Build environment is not setup or bitbake is not in path." 1>&2; return 2 fi - - - # Determine the action. If specified by arguments, fine, if not, toggle it if [ "x$1" == "xstart" ] || [ "x$1" == "xstop" ]; then CMD="$1" @@ -194,19 +268,6 @@ else fi; fi -NOTOASTERUI=0 -WEBSERVER=1 -for param in $*; do - case $param in - noui ) - NOTOASTERUI=1 - ;; - noweb ) - WEBSERVER=0 - ;; - esac -done - echo "The system will $CMD." # Make sure it's safe to run by checking bitbake lock @@ -216,42 +277,54 @@ if [ -e $BUILDDIR/bitbake.lock ]; then (flock -n 200 ) 200<$BUILDDIR/bitbake.lock || lock=0 fi -if [ ${CMD} == "start" ] && ( [ $lock -eq 0 ] || [ -e $BUILDDIR/.toastermain.pid ] ); then - echo "Error: bitbake lock state error. File locks show that the system is on." 2>&1 - echo "If you see problems, stop and then start the system again." 2>&1 +if [ ${CMD} == "start" ] && [ $lock -eq 0 ]; then + echo "Error: bitbake lock state error. File locks show that the system is on." 1>&2 + echo "Please wait for the current build to finish, stop and then start the system again." 1>&2 return 3 fi +if [ ${CMD} == "start" ] && [ -e $BUILDDIR/.toastermain.pid ] && kill -0 `cat $BUILDDIR/.toastermain.pid`; then + echo "Warning: bitbake appears to be dead, but the Toaster web server is running. Something fishy is going on." 1>&2 + echo "Cleaning up the web server to start from a clean slate." + webserverKillAll +fi + # Execute the commands case $CMD in start ) start_success=1 - addtoConfiguration "INHERIT+=\"toaster buildhistory\"" toaster.conf + addtoConfiguration toaster.conf "INHERIT+=\"toaster buildhistory\"" $TOASTER_BRBE if [ $WEBSERVER -gt 0 ] && ! webserverStartAll; then echo "Failed ${CMD}." return 4 fi unset BBSERVER - bitbake --postread conf/toaster.conf --server-only -t xmlrpc -B 0.0.0.0:8200 + PREREAD="" + if [ -e ${BUILDDIR}/conf/toaster-pre.conf ]; then + rm ${BUILDDIR}/conf/toaster-pre.conf + fi + bitbake $PREREAD --postread conf/toaster.conf --server-only -t xmlrpc -B 0.0.0.0:0 if [ $? -ne 0 ]; then start_success=0 echo "Bitbake server start failed" else - export BBSERVER=0.0.0.0:8200 + export BBSERVER=0.0.0.0:-1 if [ $NOTOASTERUI == 0 ]; then # we start the TOASTERUI only if not inhibited - bitbake --observe-only -u toasterui >${BUILDDIR}/toaster_ui.log 2>&1 & echo $! >${BUILDDIR}/.toasterui.pid + bitbake --observe-only -u toasterui >>${BUILDDIR}/toaster_ui.log 2>&1 & echo $! >${BUILDDIR}/.toasterui.pid fi fi if [ $start_success -eq 1 ]; then # set fail safe stop system on terminal exit trap stop_system SIGHUP echo "Successful ${CMD}." + return 0 else # failed start, do stop stop_system echo "Failed ${CMD}." + return 1 fi # stop system on terminal exit set -o monitor |