summaryrefslogtreecommitdiffstats
path: root/yocto-poky/bitbake/bin/toaster
diff options
context:
space:
mode:
Diffstat (limited to 'yocto-poky/bitbake/bin/toaster')
-rwxr-xr-xyocto-poky/bitbake/bin/toaster344
1 files changed, 111 insertions, 233 deletions
diff --git a/yocto-poky/bitbake/bin/toaster b/yocto-poky/bitbake/bin/toaster
index 2c3432c24..70c66d2c2 100755
--- a/yocto-poky/bitbake/bin/toaster
+++ b/yocto-poky/bitbake/bin/toaster
@@ -1,5 +1,8 @@
-#!/bin/sh
-# (c) 2013 Intel Corp.
+#!/bin/echo ERROR: This script needs to be sourced. Please run as .
+
+# toaster - shell script to start Toaster
+
+# Copyright (C) 2013-2015 Intel Corp.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -12,32 +15,24 @@
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
+# along with this program. If not, see http://www.gnu.org/licenses/.
-# This script can be run in two modes.
-
-# When used with "source", from a build directory,
-# it enables toaster event logging and starts the bitbake resident server.
-# use as: source toaster [start|stop] [noweb] [noui]
-
-# When it is called as a stand-alone script, it starts just the
-# web server, and the building shall be done through the web interface.
-# As script, it will not return to the command prompt. Stop with Ctrl-C.
+# Usage: source toaster [start|stop]
+# [webport=<port>] [noui] [noweb]
# Helper function to kill a background toaster development server
webserverKillAll()
{
local pidfile
- for pidfile in ${BUILDDIR}/.toastermain.pid; do
+ for pidfile in ${BUILDDIR}/.toastermain.pid ${BUILDDIR}/.runbuilds.pid; do
if [ -f ${pidfile} ]; then
pid=`cat ${pidfile}`
while kill -0 $pid 2>/dev/null; do
kill -SIGTERM -$pid 2>/dev/null
sleep 1
- # Kill processes if they are still running - may happen in interactive shells
+ # Kill processes if they are still running - may happen
+ # in interactive shells
ps fux | grep "python.*manage.py runserver" | awk '{print $2}' | xargs kill
done
rm ${pidfile}
@@ -55,35 +50,15 @@ webserverStartAll()
retval=0
# you can always add a superuser later via
- # python bitbake/lib/toaster/manage.py python manage.py createsuperuser --username=<ME>
- python $BBBASEDIR/lib/toaster/manage.py syncdb --noinput || retval=1
-
- python $BBBASEDIR/lib/toaster/manage.py migrate orm || retval=2
-
- if [ $retval -eq 1 ]; then
- echo "Failed db sync, aborting system start" 1>&2
- return $retval
- fi
-
- python $BBBASEDIR/lib/toaster/manage.py migrate orm || retval=1
-
- if [ $retval -eq 1 ]; then
- printf "\nError on orm migration, rolling back...\n"
- python $BBBASEDIR/lib/toaster/manage.py migrate orm 0001_initial --fake
- return $retval
- fi
-
- python $BBBASEDIR/lib/toaster/manage.py migrate bldcontrol || retval=1
+ # ../bitbake/lib/toaster/manage.py createsuperuser --username=<ME>
+ $MANAGE migrate --noinput || retval=1
if [ $retval -eq 1 ]; then
- printf "\nError on bldcontrol migration, rolling back...\n"
- python $BBBASEDIR/lib/toaster/manage.py migrate bldcontrol 0001_initial --fake
+ echo "Failed migrations, aborting system start" 1>&2
return $retval
fi
- if [ "$TOASTER_MANAGED" = '1' ]; then
- python $BBBASEDIR/lib/toaster/manage.py checksettings --traceback || retval=1
- fi
+ $MANAGE checksettings --traceback || retval=1
if [ $retval -eq 1 ]; then
printf "\nError while checking settings; aborting\n"
@@ -92,7 +67,9 @@ webserverStartAll()
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
+ $MANAGE runserver "0.0.0.0:$WEB_PORT" \
+ </dev/null >>${BUILDDIR}/toaster_web.log 2>&1 \
+ & echo $! >${BUILDDIR}/.toastermain.pid
sleep 1
@@ -106,16 +83,6 @@ webserverStartAll()
return $retval
}
-# Helper functions to add a special configuration file
-
-addtoConfiguration()
-{
- file=$1
- shift
- echo "#Created by toaster start script" > ${BUILDDIR}/conf/$file
- for var in "$@"; do echo $var >> ${BUILDDIR}/conf/$file; done
-}
-
INSTOPSYSTEM=0
# define the stop command
@@ -128,45 +95,34 @@ stop_system()
kill `cat ${BUILDDIR}/.toasterui.pid` 2>/dev/null
rm ${BUILDDIR}/.toasterui.pid
fi
- BBSERVER=0.0.0.0:-1 bitbake -m
- unset BBSERVER
webserverKillAll
- # force stop any misbehaving bitbake server
- lsof bitbake.lock | awk '{print $2}' | grep "[0-9]\+" | xargs -n1 -r kill
+ # unset exported variables
+ unset DATABASE_URL
+ unset TOASTER_CONF
+ unset TOASTER_DIR
+ unset BITBAKE_UI
+ unset BBBASEDIR
trap - SIGHUP
#trap - SIGCHLD
INSTOPSYSTEM=0
}
-check_pidbyfile() {
- [ -e $1 ] && kill -0 `cat $1` 2>/dev/null
-}
-
-
-notify_chldexit() {
- if [ $NOTOASTERUI -eq 0 ]; then
- check_pidbyfile ${BUILDDIR}/.toasterui.pid && return
- stop_system
- fi
-}
-
-
verify_prereq() {
- # Verify prerequisites
-
- if ! echo "import django; print (1,) == django.VERSION[0:1] and django.VERSION[1:2][0] in (6,)" | python 2>/dev/null | grep True >/dev/null; then
- printf "This program needs Django 1.6. Please install with\n\npip install django==1.6\n"
+ # Verify Django version
+ reqfile=$(python -c "import os; print os.path.realpath('$BBBASEDIR/toaster-requirements.txt')")
+ exp='s/Django\([><=]\+\)\([^,]\+\),\([><=]\+\)\(.\+\)/'
+ exp=$exp'import sys,django;version=django.get_version().split(".");'
+ exp=$exp'sys.exit(not (version \1 "\2".split(".") and version \3 "\4".split(".")))/p'
+ if ! sed -n "$exp" $reqfile | python - ; then
+ req=`grep ^Django $reqfile`
+ echo "This program needs $req"
+ echo "Please install with pip install -r $reqfile"
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
- printf "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
if [ -n "$BASH_SOURCE" ] ; then
TOASTER=${BASH_SOURCE}
@@ -176,33 +132,42 @@ else
TOASTER=$0
fi
-[ `basename \"$0\"` = `basename \"${TOASTER}\"` ] && TOASTER_MANAGED=1
+export BBBASEDIR=`dirname $TOASTER`/..
+MANAGE=$BBBASEDIR/lib/toaster/manage.py
+OEROOT=`dirname $TOASTER`/../..
-BBBASEDIR=`dirname $TOASTER`/..
-
-RUNNING=0
-
-NOTOASTERUI=0
-WEBSERVER=1
-TOASTER_BRBE=""
-if [ "$WEB_PORT" = "" ]; then
- WEB_PORT="8000"
-fi
# this is the configuraton file we are using for toaster
-# note default is assuming yocto. Override this if you are
-# running in a pure OE environment and use the toasterconf.json
-# in meta/conf/toasterconf.json
-# note: for future there are a number of relative path assumptions
-# in the local layers that currently prevent using an arbitrary
-# toasterconf.json
+# we are using the same logic that oe-setup-builddir uses
+# (based on TEMPLATECONF and .templateconf) to determine
+# which toasterconf.json to use.
+# note: There are a number of relative path assumptions
+# in the local layers that currently make using an arbitrary
+# toasterconf.json difficult.
+
+. $OEROOT/.templateconf
+if [ -n "$TEMPLATECONF" ]; then
+ if [ ! -d "$TEMPLATECONF" ]; then
+ # Allow TEMPLATECONF=meta-xyz/conf as a shortcut
+ if [ -d "$OEROOT/$TEMPLATECONF" ]; then
+ TEMPLATECONF="$OEROOT/$TEMPLATECONF"
+ fi
+ if [ ! -d "$TEMPLATECONF" ]; then
+ echo >&2 "Error: '$TEMPLATECONF' must be a directory containing toasterconf.json"
+ return 1
+ fi
+ fi
+fi
+
if [ "$TOASTER_CONF" = "" ]; then
- TOASTER_CONF="$(dirname $TOASTER)/../../meta-yocto/conf/toasterconf.json"
+ TOASTER_CONF="$TEMPLATECONF/toasterconf.json"
export TOASTER_CONF=$(python -c "import os; print os.path.realpath('$TOASTER_CONF')")
fi
+
if [ ! -f $TOASTER_CONF ]; then
- echo "$TOASTER_CONF configuration file not found. set TOASTER_CONF to specify a path"
- [ "$TOASTER_MANAGED" = '1' ] && exit 1 || return 1
+ echo "$TOASTER_CONF configuration file not found. Set TOASTER_CONF to specify file or fix .templateconf"
+ return 1
fi
+
# this defines the dir toaster will use for
# 1) clones of layers (in _toaster_clones )
# 2) the build dir (in build)
@@ -212,102 +177,31 @@ fi
# make sure that the toaster.sqlite file doesn't default to `pwd` like it currently does.
export TOASTER_DIR=`pwd`
-
-NOBROWSER=0
-
+WEBSERVER=1
+WEB_PORT="8000"
+unset CMD
for param in $*; do
case $param in
- noui )
- NOTOASTERUI=1
- ;;
noweb )
WEBSERVER=0
;;
- nobrowser )
- NOBROWSER=1
+ start )
+ CMD=$param
;;
- brbe=* )
- TOASTER_BRBE=$'\n'"TOASTER_BRBE=\""${param#*=}"\""
+ stop )
+ CMD=$param
;;
webport=*)
WEB_PORT="${param#*=}"
esac
done
-if [ "$TOASTER_MANAGED" = '1' ]; 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 "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
- printf "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.\n" 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/toaster_$$
- if [ -d "$BUILDDIR" ]; then
- echo "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
- trap_ctrlc() {
- echo "** Stopping system"
- webserverKillAll
- RUNNING=0
- }
-
- do_cleanup() {
- find "$BUILDDIR" -type f | xargs rm
- rmdir "$BUILDDIR"
- }
- 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
- printf "\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
- }
- export TOASTER_MANAGED=1
- if [ $WEBSERVER -gt 0 ] && ! webserverStartAll; then
- echo "Failed to start the web server, stopping" 1>&2
- cleanup
- exit 1
- fi
- if [ $WEBSERVER -gt 0 ] && [ $NOBROWSER -eq 0 ] ; then
- echo "Starting browser..."
- xdg-open http://127.0.0.1:$WEB_PORT/ >/dev/null 2>&1 &
- fi
- trap trap_ctrlc 2
- echo "Toaster is now running. You can stop it with Ctrl-C"
- while [ $RUNNING -gt 0 ]; do
- python $BBBASEDIR/lib/toaster/manage.py runbuilds 2>&1 | tee -a "$BUILDDIR/toaster.log"
- sleep 1
- done
- cleanup
- echo "**** Exit"
- exit 0
-fi
-
-
-if ! verify_prereq; then
- echo "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
+if [ `basename \"$0\"` = `basename \"${TOASTER}\"` ]; then
+ echo "Error: This script needs to be sourced. Please run as . $TOASTER"
return 1
fi
+verify_prereq || return 1
# We make sure we're running in the current shell and in a good environment
if [ -z "$BUILDDIR" ] || ! which bitbake >/dev/null 2>&1 ; then
@@ -315,11 +209,23 @@ if [ -z "$BUILDDIR" ] || ! which bitbake >/dev/null 2>&1 ; then
return 2
fi
+# this defines the dir toaster will use for
+# 1) clones of layers (in _toaster_clones )
+# 2) the build dir (in build)
+# 3) the sqlite db if that is being used.
+# 4) pid's we need to clean up on exit/shutdown
+# note: for future. in order to make this an arbitrary directory, we need to
+# make sure that the toaster.sqlite file doesn't default to `pwd`
+# like it currently does.
+export TOASTER_DIR=`dirname $BUILDDIR`
# Determine the action. If specified by arguments, fine, if not, toggle it
-if [ "$1" = 'start' ] || [ "$1" = 'stop' ]; then
- CMD="$1"
-else
+if [ "$CMD" = "start" ] ; then
+ if [ -n "$BBSERVER" ]; then
+ echo " Toaster is already running. Exiting..."
+ return 1
+fi
+elif [ "$CMD" = "" ]; then
if [ -z "$BBSERVER" ]; then
CMD="start"
else
@@ -329,70 +235,42 @@ fi
echo "The system will $CMD."
-# Make sure it's safe to run by checking bitbake lock
-
-lock=1
-if [ -e $BUILDDIR/bitbake.lock ]; then
- python -c "import fcntl; fcntl.flock(open(\"$BUILDDIR/bitbake.lock\"), fcntl.LOCK_EX|fcntl.LOCK_NB)" 2>/dev/null || lock=0
-fi
-
-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 toaster.conf "INHERIT+=\"toaster buildhistory\"" $TOASTER_BRBE
- if [ $WEBSERVER -gt 0 ] && ! webserverStartAll; then
- echo "Failed ${CMD}."
- return 4
- fi
- unset BBSERVER
- PREREAD=""
- if [ -e ${BUILDDIR}/conf/toaster-pre.conf ]; then
- rm ${BUILDDIR}/conf/toaster-pre.conf
+ # check if addr:port is not in use
+ if [ "$CMD" == 'start' ]; then
+ $MANAGE checksocket "0.0.0.0:$WEB_PORT" || return 1
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:-1
- if [ $NOTOASTERUI -eq 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
- fi
+
+ # kill Toaster web server if it's alive
+ if [ -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." 1>&2
+ echo " Something fishy is going on." 1>&2
+ echo "Cleaning up the web server to start from a clean slate."
+ webserverKillAll
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
+
+ # Create configuration file
+ conf=${BUILDDIR}/conf/local.conf
+ line='INHERIT+="toaster buildhistory"'
+ grep -q "$line" $conf || echo $line >> $conf
+
+ if [ $WEBSERVER -gt 0 ] && ! webserverStartAll; then
echo "Failed ${CMD}."
- return 1
+ return 4
fi
- # stop system on terminal exit
- set -o monitor
+ export BITBAKE_UI='toasterui'
+ export DATABASE_URL=`$MANAGE get-dburl`
+ $MANAGE runbuilds & echo $! >${BUILDDIR}/.runbuilds.pid
+ # set fail safe stop system on terminal exit
trap stop_system SIGHUP
- #trap notify_chldexit SIGCHLD
+ echo "Successful ${CMD}."
+ return 0
;;
stop )
stop_system
echo "Successful ${CMD}."
;;
esac
-
OpenPOWER on IntegriCloud