Toaster startup script improvements
cover Toaster startup script improvements
This patchset includes a bunch of readability, usability and code style fixes for toaster script. It was started as a fix for #8775 and then I just couldn't stop and decided to make the script a bit better.
The following changes since commit d65cf4fe9d239169e2474b59bdce7fc59194de67 (poky-contrib, toaster-next):
toaster-manual: describe the way to start Toaster (2015-12-15 14:03:20 +0200)
are available in the git repository at:
git://git.yoctoproject.org/poky-contrib elliot/submit/ed/toaster/improve-toaster-script
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=elliot/submit/ed/toaster/improve-toaster-script
Ed Bartosh (11):
toaster: implement checksocket command
toaster: check if address:port is in use
toaster: split long lines, add/remove whitespace
toaster: remove unused variable
toaster: add MANAGE variable
toaster: updated header of the toaster script
toaster: remove addtoConfiguration function
toaster: remove 2 unused functions
toaster: move startup checks to a better place
toaster: move setting of default values
toaster: remove 2 confusing parameters
bin/toaster | 144 +++++++++------------ .../toastermain/management/commands/checksocket.py | 69 ++++++++++ 2 files changed, 129 insertions(+), 84 deletions(-) create mode 100644 bitbake/lib/toaster/toastermain/management/commands/checksocket.py
--
1.9.3
---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
PATCH 1/11 toaster: implement checksocket command
From: Ed Bartosh <[email protected]>
Implemented new management command to check if it's possible to listen on specified address:port.
[YOCTO #8775]
--- .../toastermain/management/commands/checksocket.py | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 bitbake/lib/toaster/toastermain/management/commands/checksocket.py
lib/toaster/toastermain/management/commands/checksocket.py new file +69 -0
@@ -0,0 +1,69 @@ +#!/usr/bin/env python +# ex:ts=4:sw=4:sts=4:et +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- +# +# BitBake Toaster Implementation +# +# Copyright (C) 2015 Intel Corporation +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# 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., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +"""Custom management command checksocket.""" + +import errno +import socket + +from django.core.management.base import BaseCommand, CommandError +from django.utils.encoding import force_text + +DEFAULT_ADDRPORT = "0.0.0.0:8000" + +class Command(BaseCommand): + """Custom management command.""" + + help = 'Check if Toaster can listen on address:port' + + def add_arguments(self, parser): + parser.add_argument('addrport', nargs='?', default=DEFAULT_ADDRPORT, + help='ipaddr:port to check, %s by default' % \ + DEFAULT_ADDRPORT) + + def handle(self, *args, **options): + addrport = options['addrport'] + if ':' not in addrport: + raise CommandError('Invalid addr:port specified: %s' % addrport) + splitted = addrport.split(':') + try: + splitted[1] = int(splitted[1]) + except ValueError: + raise CommandError('Invalid port specified: %s' % splitted[1]) + self.stdout.write('Check if toaster can listen on %s' % addrport) + try: + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + sock.bind(tuple(splitted)) + except (socket.error, OverflowError) as err: + errors = { + errno.EACCES: 'You don\'t have permission to access port %s' \ + % splitted[1], + errno.EADDRINUSE: 'Port %s is already in use' % splitted[1], + errno.EADDRNOTAVAIL: 'IP address can\'t be assigned to', + } + if hasattr(err, 'errno') and err.errno in errors: + errtext = errors[err.errno] + else: + errtext = force_text(err) + raise CommandError(errtext) + + self.stdout.write("OK")
Signature · 12 lines
1.9.3 --------------------------------------------------------------------- Intel Corporation (UK) Limited Registered No. 1134945 (England) Registered Office: Pipers Way, Swindon SN3 1RJ VAT No: 860 2173 47 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
PATCH 2/11 toaster: check if address:port is in use
From: Ed Bartosh <[email protected]>
Used new management command checksocket to check if Toaster can listen on address:port.
[YOCTO #8775]
--- bin/toaster | 5 +++++ 1 file changed, 5 insertions(+)
bin/toaster +5 -0
@@ -309,6 +309,11 @@ fi echo "The system will $CMD." +# check if addr:port is not in use +if [ "$CMD" == 'start' ]; then + python $BBBASEDIR/lib/toaster/manage.py checksocket "0.0.0.0:$WEB_PORT" || return 1 +fi + # Make sure it's safe to run by checking bitbake lock lock=1
Signature · 12 lines
1.9.3 --------------------------------------------------------------------- Intel Corporation (UK) Limited Registered No. 1134945 (England) Registered Office: Pipers Way, Swindon SN3 1RJ VAT No: 860 2173 47 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
PATCH 3/11 toaster: split long lines, add/remove whitespace
In reply to Elliot SmithFrom: Ed Bartosh <[email protected]>
Made toaster script more readable by splitting long lines and removing and adding whitespace.
--- bin/toaster | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-)
bin/toaster +19 -12
@@ -37,7 +37,8 @@ webserverKillAll() 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,7 +56,7 @@ webserverStartAll() retval=0 # you can always add a superuser later via - # python bitbake/lib/toaster/manage.py python manage.py createsuperuser --username=<ME> + # ../bitbake/lib/toaster/manage.py createsuperuser --username=<ME> python $BBBASEDIR/lib/toaster/manage.py migrate --noinput || retval=1 if [ $retval -eq 1 ]; then
@@ -72,7 +73,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 + 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
@@ -128,8 +131,10 @@ start_bitbake() { fi export BBSERVER=0.0.0.0:-1 export DATABASE_URL=`$BBBASEDIR/lib/toaster/manage.py get-dburl` - if [ $NOTOASTERUI -eq 0 ]; then # we start the TOASTERUI only if not inhibited - bitbake --observe-only -u toasterui --remote-server=$BBSERVER -t xmlrpc >>${BUILDDIR}/toaster_ui.log 2>&1 \ + # we start the TOASTERUI only if not inhibited + if [ $NOTOASTERUI -eq 0 ]; then + bitbake --observe-only -u toasterui --remote-server=$BBSERVER -t xmlrpc \ + >>${BUILDDIR}/toaster_ui.log 2>&1 \ & echo $! >${BUILDDIR}/.toasterui.pid fi return 0
@@ -146,7 +151,6 @@ check_pidbyfile() { [ -e $1 ] && kill -0 `cat $1` 2>/dev/null } - notify_chldexit() { if [ $NOTOASTERUI -eq 0 ]; then check_pidbyfile ${BUILDDIR}/.toasterui.pid && return
@@ -154,7 +158,6 @@ notify_chldexit() { fi } - verify_prereq() { # Verify Django version reqfile=$(python -c "import os; print os.path.realpath('$BBBASEDIR/toaster-requirements.txt')")
@@ -171,7 +174,6 @@ verify_prereq() { return 0 } - # read command line parameters if [ -n "$BASH_SOURCE" ] ; then TOASTER=${BASH_SOURCE}
@@ -207,7 +209,7 @@ if [ -n "$TEMPLATECONF" ]; then fi if [ ! -d "$TEMPLATECONF" ]; then echo >&2 "Error: '$TEMPLATECONF' must be a directory containing toasterconf.json" - [ "$TOASTER_MANAGED" = '1' ] && exit 1 || return 1 + [ "$TOASTER_MANAGED" = '1' ] && exit 1 || return 1 fi fi fi
@@ -216,10 +218,12 @@ if [ "$TOASTER_CONF" = "" ]; then 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 file or fix .templateconf" [ "$TOASTER_MANAGED" = '1' ] && exit 1 || return 1 fi + # this defines the dir toaster will use for # 1) clones of layers (in _toaster_clones ) # 2) the build dir (in build)
@@ -284,7 +288,8 @@ if [ "$TOASTER_CONF" = "" ]; then 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" + echo "$TOASTER_CONF configuration file not found." + echo " set TOASTER_CONF to specify a path" return 1 fi # this defines the dir toaster will use for
@@ -293,7 +298,8 @@ fi # 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. +# 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
@@ -328,7 +334,8 @@ if [ ${CMD} = 'start' ] && [ $lock -eq 0 ]; then 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 "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
Signature · 12 lines
1.9.3 --------------------------------------------------------------------- Intel Corporation (UK) Limited Registered No. 1134945 (England) Registered Office: Pipers Way, Swindon SN3 1RJ VAT No: 860 2173 47 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
Re: [PATCH 03/11] toaster: split long lines, add/remove whitespace
Quoted 43 lines
-----Original Message-----
From: [email protected] [mailto:bitbake- [email protected]] On Behalf Of Elliot Smith
Sent: den 17 december 2015 17:49
To: [email protected]
Subject: [bitbake-devel] [PATCH 03/11] toaster: split long lines, add/remove whitespaceFrom: Ed Bartosh <[email protected]>
Made toaster script more readable by splitting long lines and removing and adding whitespace.
Signed-off-by Ed Bartosh <[email protected]>Signed-off-by Elliot Smith <[email protected]>--- bin/toaster | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-)bin/toaster +3
-2@@ -37,7 +37,8 @@ webserverKillAll() 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,7 +56,7 @@ webserverStartAll() retval=0 # you can always add a superuser later via - # python bitbake/lib/toaster/manage.py python manage.py createsuperuser --username=<ME> + # ../bitbake/lib/toaster/manage.py createsuperuser --username=<ME> python $BBBASEDIR/lib/toaster/manage.py migrate --noinput || retval=1 if [ $retval -eq 1 ]; then
bin/toaster webserverStartAll() · line 78
Quoted 7 lines
bin/toaster +3
-1@@ -72,7 +73,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 + 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
I would reformat that as:
python $BBBASEDIR/lib/toaster/manage.py runserver "0.0.0.0:$WEB_PORT" \
</dev/null >>${BUILDDIR}/toaster_web.log 2>&1 &
echo $! >${BUILDDIR}/.toastermain.pidbin/toaster start_bitbake() { · line 138
Quoted 13 lines
bin/toaster +4
-2sleep 1@@ -128,8 +131,10 @@ start_bitbake() { fi export BBSERVER=0.0.0.0:-1 export DATABASE_URL=`$BBBASEDIR/lib/toaster/manage.py get-dburl` - if [ $NOTOASTERUI -eq 0 ]; then # we start the TOASTERUI only if not inhibited - bitbake --observe-only -u toasterui --remote-server=$BBSERVER -t xmlrpc >>${BUILDDIR}/toaster_ui.log 2>&1 \ + # we start the TOASTERUI only if not inhibited + if [ $NOTOASTERUI -eq 0 ]; then + bitbake --observe-only -u toasterui --remote-server=$BBSERVER -t xmlrpc \ + >>${BUILDDIR}/toaster_ui.log 2>&1 \ & echo $! >${BUILDDIR}/.toasterui.pid
Same here:
bitbake --observe-only -u toasterui --remote-server=$BBSERVER -t xmlrpc \
>>${BUILDDIR}/toaster_ui.log 2>&1 &
echo $! >${BUILDDIR}/.toasterui.pidQuoted 69 lines
bin/toaster +7
-6fi return 0@@ -146,7 +151,6 @@ check_pidbyfile() { [ -e $1 ] && kill -0 `cat $1` 2>/dev/null } - notify_chldexit() { if [ $NOTOASTERUI -eq 0 ]; then check_pidbyfile ${BUILDDIR}/.toasterui.pid && return@@ -154,7 +158,6 @@ notify_chldexit() { fi } - verify_prereq() { # Verify Django version reqfile=$(python -c "import os; print os.path.realpath('$BBBASEDIR/toaster-requirements.txt')")@@ -171,7 +174,6 @@ verify_prereq() { return 0 } - # read command line parameters if [ -n "$BASH_SOURCE" ] ; then TOASTER=${BASH_SOURCE}@@ -207,7 +209,7 @@ if [ -n "$TEMPLATECONF" ]; then fi if [ ! -d "$TEMPLATECONF" ]; then echo >&2 "Error: '$TEMPLATECONF' must be a directory containing toasterconf.json" - [ "$TOASTER_MANAGED" = '1' ] && exit 1 || return 1 + [ "$TOASTER_MANAGED" = '1' ] && exit 1 || return 1 fi fi fi@@ -216,10 +218,12 @@ if [ "$TOASTER_CONF" = "" ]; then 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 file or fix .templateconf" [ "$TOASTER_MANAGED" = '1' ] && exit 1 || return 1 fi + # this defines the dir toaster will use for # 1) clones of layers (in _toaster_clones ) # 2) the build dir (in build)@@ -284,7 +288,8 @@ if [ "$TOASTER_CONF" = "" ]; then 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" + echo "$TOASTER_CONF configuration file not found." + echo " set TOASTER_CONF to specify a path" return 1 fi # this defines the dir toaster will use for@@ -293,7 +298,8 @@ fi # 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. +# 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
bin/toaster if [ ${CMD} = 'start' ] && [ $lock -eq 0 ]; then · line 336
Quoted 3 lines
bin/toaster +0
-0@@ -328,7 +334,8 @@ if [ ${CMD} = 'start' ] && [ $lock -eq 0 ]; then fi if [ ${CMD} = 'start' ] && [ -e $BUILDDIR/.toastermain.pid ] && kill -0 `cat $BUILDDIR/.toastermain.pid`; then
You can break the above as:
if [ ${CMD} = 'start' ] && [ -e $BUILDDIR/.toastermain.pid ] &&
kill -0 cat $BUILDDIR/.toastermain.pid; then
Quoted 8 lines
bin/toaster +2
-2- echo "Warning: bitbake appears to be dead, but the Toaster web server is running. Something fishy is going on." 1>&2 + 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 --1.9.3
//Peter
PATCH 4/11 toaster: remove unused variable
In reply to Elliot SmithFrom: Ed Bartosh <[email protected]>
Removed unused variable RUNNING from the toaster script.
--- bin/toaster | 1 - 1 file changed, 1 deletion(-)
bin/toaster +0 -1
@@ -185,7 +185,6 @@ fi BBBASEDIR=`dirname $TOASTER`/.. OEROOT=`dirname $TOASTER`/../.. -RUNNING=0 NOTOASTERUI=0 WEBSERVER=1 TOASTER_BRBE=""
Signature · 12 lines
1.9.3 --------------------------------------------------------------------- Intel Corporation (UK) Limited Registered No. 1134945 (England) Registered Office: Pipers Way, Swindon SN3 1RJ VAT No: 860 2173 47 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
PATCH 5/11 toaster: add MANAGE variable
In reply to Elliot SmithFrom: Ed Bartosh <[email protected]>
Used MANAGE variable to avoid repeating path tomanage.py in many places in toaster script.
--- bin/toaster | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
bin/toaster +7 -6
@@ -57,14 +57,14 @@ webserverStartAll() retval=0 # you can always add a superuser later via # ../bitbake/lib/toaster/manage.py createsuperuser --username=<ME> - python $BBBASEDIR/lib/toaster/manage.py migrate --noinput || retval=1 + $MANAGE migrate --noinput || retval=1 if [ $retval -eq 1 ]; then echo "Failed migrations, aborting system start" 1>&2 return $retval fi - python $BBBASEDIR/lib/toaster/manage.py checksettings --traceback || retval=1 + $MANAGE checksettings --traceback || retval=1 if [ $retval -eq 1 ]; then printf "\nError while checking settings; aborting\n"
@@ -73,7 +73,7 @@ webserverStartAll() echo "Starting webserver..." - python $BBBASEDIR/lib/toaster/manage.py runserver "0.0.0.0:$WEB_PORT" \ + $MANAGE runserver "0.0.0.0:$WEB_PORT" \ </dev/null >>${BUILDDIR}/toaster_web.log 2>&1 \ & echo $! >${BUILDDIR}/.toastermain.pid
@@ -130,7 +130,7 @@ start_bitbake() { return 1 fi export BBSERVER=0.0.0.0:-1 - export DATABASE_URL=`$BBBASEDIR/lib/toaster/manage.py get-dburl` + export DATABASE_URL=`$MANAGE get-dburl` # we start the TOASTERUI only if not inhibited if [ $NOTOASTERUI -eq 0 ]; then bitbake --observe-only -u toasterui --remote-server=$BBSERVER -t xmlrpc \
@@ -184,6 +184,7 @@ else fi BBBASEDIR=`dirname $TOASTER`/.. +MANAGE=$BBBASEDIR/lib/toaster/manage.py OEROOT=`dirname $TOASTER`/../.. NOTOASTERUI=0 WEBSERVER=1
@@ -316,7 +317,7 @@ echo "The system will $CMD." # check if addr:port is not in use if [ "$CMD" == 'start' ]; then - python $BBBASEDIR/lib/toaster/manage.py checksocket "0.0.0.0:$WEB_PORT" || return 1 + $MANAGE checksocket "0.0.0.0:$WEB_PORT" || return 1 fi # Make sure it's safe to run by checking bitbake lock
@@ -351,7 +352,7 @@ case $CMD in fi start_bitbake if [ $? -eq 0 ]; then - python $BBBASEDIR/lib/toaster/manage.py runbuilds & echo $! >${BUILDDIR}/.runbuilds.pid + $MANAGE runbuilds & echo $! >${BUILDDIR}/.runbuilds.pid # set fail safe stop system on terminal exit trap stop_system SIGHUP echo "Successful ${CMD}."
Signature · 12 lines
1.9.3 --------------------------------------------------------------------- Intel Corporation (UK) Limited Registered No. 1134945 (England) Registered Office: Pipers Way, Swindon SN3 1RJ VAT No: 860 2173 47 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
PATCH 6/11 toaster: updated header of the toaster script
In reply to Elliot SmithFrom: Ed Bartosh <[email protected]>
Updated GPL information, years of development and usage information. Removed outdated information about 2 ways of starting Toaster.
--- bin/toaster | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-)
bin/toaster +7 -13
@@ -1,5 +1,8 @@ #!/bin/echo ERROR: This script needs to be sourced. Please run as . -# (c) 2013 Intel Corp. + +# 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,19 +15,10 @@ # 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 - - -# 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] +# along with this program. If not, see http://www.gnu.org/licenses/. -# 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|restart-bitbake] [webport=<port>] +# [noui] [noweb] [nobrowser] [brbe=<BRBE>] # Helper function to kill a background toaster development server
Signature · 12 lines
1.9.3 --------------------------------------------------------------------- Intel Corporation (UK) Limited Registered No. 1134945 (England) Registered Office: Pipers Way, Swindon SN3 1RJ VAT No: 860 2173 47 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
PATCH 7/11 toaster: remove addtoConfiguration function
In reply to Elliot SmithFrom: Ed Bartosh <[email protected]>
This function is useless as it's called just once
and makes code less readable.
--- bin/toaster | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)
bin/toaster +6 -11
@@ -83,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
@@ -339,7 +329,12 @@ fi case $CMD in start ) - addtoConfiguration toaster.conf "INHERIT+=\"toaster buildhistory\"" $TOASTER_BRBE + # Create configuration file + conf=${BUILDDIR}/conf/toaster.conf + echo "# Created by toaster start script" > $conf + echo "INHERIT+=\"toaster buildhistory\"" >> $conf + [ -n "$TOASTER_BRBE" ] && echo $TOASTER_BRBE >> $conf + if [ $WEBSERVER -gt 0 ] && ! webserverStartAll; then echo "Failed ${CMD}." return 4
Signature · 12 lines
1.9.3 --------------------------------------------------------------------- Intel Corporation (UK) Limited Registered No. 1134945 (England) Registered Office: Pipers Way, Swindon SN3 1RJ VAT No: 860 2173 47 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
PATCH 8/11 toaster: remove 2 unused functions
In reply to Elliot SmithFrom: Ed Bartosh <[email protected]>
Removed check_pidbyfile and notify_chldexit functions from toaster script as they're not called in the script.
--- bin/toaster | 12 ------------ 1 file changed, 12 deletions(-)
bin/toaster +0 -12
@@ -131,17 +131,6 @@ stop_bitbake() { lsof bitbake.lock | awk '{print $2}' | grep "[0-9]\+" | xargs -n1 -r kill } -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 Django version reqfile=$(python -c "import os; print os.path.realpath('$BBBASEDIR/toaster-requirements.txt')")
@@ -355,7 +344,6 @@ case $CMD in # stop system on terminal exit set -o monitor trap stop_system SIGHUP - #trap notify_chldexit SIGCHLD ;; stop ) stop_system
Signature · 12 lines
1.9.3 --------------------------------------------------------------------- Intel Corporation (UK) Limited Registered No. 1134945 (England) Registered Office: Pipers Way, Swindon SN3 1RJ VAT No: 860 2173 47 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
PATCH 9/11 toaster: move startup checks to a better place
In reply to Elliot SmithFrom: Ed Bartosh <[email protected]>
Moved addr:port, bitbake.lock and toastermain.pid checks to the place where the rest of Toaster starting happens.
--- bin/toaster | 49 +++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 26 deletions(-)
bin/toaster +23 -26
@@ -288,36 +288,33 @@ fi echo "The system will $CMD." -# check if addr:port is not in use -if [ "$CMD" == 'start' ]; then - $MANAGE checksocket "0.0.0.0:$WEB_PORT" || return 1 -fi - -# 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." 1>&2 - echo " 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 ) + # check if addr:port is not in use + if [ "$CMD" == 'start' ]; then + $MANAGE checksocket "0.0.0.0:$WEB_PORT" || return 1 + fi + + # Make sure it's safe to start by checking bitbake lock + 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 + if [ $? -ne 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 + 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 + # Create configuration file conf=${BUILDDIR}/conf/toaster.conf echo "# Created by toaster start script" > $conf
Signature · 12 lines
1.9.3 --------------------------------------------------------------------- Intel Corporation (UK) Limited Registered No. 1134945 (England) Registered Office: Pipers Way, Swindon SN3 1RJ VAT No: 860 2173 47 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
PATCH 10/11 toaster: move setting of default values
In reply to Elliot SmithFrom: Ed Bartosh <[email protected]>
Set default values of script parameters just before they are parsed to increase readability.
--- bin/toaster | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
bin/toaster +5 -6
@@ -159,12 +159,7 @@ fi BBBASEDIR=`dirname $TOASTER`/.. MANAGE=$BBBASEDIR/lib/toaster/manage.py OEROOT=`dirname $TOASTER`/../.. -NOTOASTERUI=0 -WEBSERVER=1 -TOASTER_BRBE="" -if [ "$WEB_PORT" = "" ]; then - WEB_PORT="8000" -fi + # this is the configuraton file we are using for toaster # we are using the same logic that oe-setup-builddir uses # (based on TEMPLATECONF and .templateconf) to determine
@@ -206,7 +201,11 @@ fi # make sure that the toaster.sqlite file doesn't default to `pwd` like it currently does. export TOASTER_DIR=`pwd` +NOTOASTERUI=0 +WEBSERVER=1 NOBROWSER=0 +TOASTER_BRBE="" +WEB_PORT="8000" for param in $*; do case $param in
Signature · 12 lines
1.9.3 --------------------------------------------------------------------- Intel Corporation (UK) Limited Registered No. 1134945 (England) Registered Office: Pipers Way, Swindon SN3 1RJ VAT No: 860 2173 47 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
PATCH 11/11 toaster: remove 2 confusing parameters
In reply to Elliot SmithFrom: Ed Bartosh <[email protected]>
Removed nobrowser and brbe script parameters as both are confusing and nobrowser is not used anywhere.
brbe parameter usage can only be justified if toaster doesn't work properly and user has to manually connect toaster to running bitbake server. Even in this scenario it's very unlikely to achieve as toaster script is not designed for this kind of usage.
--- bin/toaster | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)
bin/toaster +2 -11
@@ -17,8 +17,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/. -# Usage: source toaster [start|stop|restart-bitbake] [webport=<port>] -# [noui] [noweb] [nobrowser] [brbe=<BRBE>] +# Usage: source toaster [start|stop|restart-bitbake] +# [webport=<port>] [noui] [noweb] # Helper function to kill a background toaster development server
@@ -203,8 +203,6 @@ export TOASTER_DIR=`pwd` NOTOASTERUI=0 WEBSERVER=1 -NOBROWSER=0 -TOASTER_BRBE="" WEB_PORT="8000" for param in $*; do
@@ -215,12 +213,6 @@ for param in $*; do noweb ) WEBSERVER=0 ;; - nobrowser ) - NOBROWSER=1 - ;; - brbe=* ) - TOASTER_BRBE=$'\n'"TOASTER_BRBE=\""${param#*=}"\"" - ;; webport=*) WEB_PORT="${param#*=}" esac
@@ -318,7 +310,6 @@ case $CMD in conf=${BUILDDIR}/conf/toaster.conf echo "# Created by toaster start script" > $conf echo "INHERIT+=\"toaster buildhistory\"" >> $conf - [ -n "$TOASTER_BRBE" ] && echo $TOASTER_BRBE >> $conf if [ $WEBSERVER -gt 0 ] && ! webserverStartAll; then echo "Failed ${CMD}."
Signature · 12 lines
1.9.3 --------------------------------------------------------------------- Intel Corporation (UK) Limited Registered No. 1134945 (England) Registered Office: Pipers Way, Swindon SN3 1RJ VAT No: 860 2173 47 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.