2015-12-02 18:02:33 +00:00
|
|
|
#!/bin/echo ERROR: This script needs to be sourced. Please run as .
|
2015-12-17 16:48:51 +00:00
|
|
|
|
|
|
|
# toaster - shell script to start Toaster
|
|
|
|
|
|
|
|
# Copyright (C) 2013-2015 Intel Corp.
|
2013-10-11 12:46:23 +00:00
|
|
|
|
|
|
|
# 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
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# 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
|
2015-12-17 16:48:51 +00:00
|
|
|
# along with this program. If not, see http://www.gnu.org/licenses/.
|
2014-06-03 15:26:15 +00:00
|
|
|
|
2015-12-17 16:48:51 +00:00
|
|
|
# Usage: source toaster [start|stop|restart-bitbake] [webport=<port>]
|
|
|
|
# [noui] [noweb] [nobrowser] [brbe=<BRBE>]
|
2013-10-11 12:46:23 +00:00
|
|
|
|
|
|
|
# Helper function to kill a background toaster development server
|
|
|
|
|
2015-05-04 10:38:50 +00:00
|
|
|
webserverKillAll()
|
2013-10-11 12:46:23 +00:00
|
|
|
{
|
2015-05-04 10:03:59 +00:00
|
|
|
local pidfile
|
2015-12-02 18:02:41 +00:00
|
|
|
for pidfile in ${BUILDDIR}/.toastermain.pid ${BUILDDIR}/.runbuilds.pid; do
|
2015-05-04 10:03:59 +00:00
|
|
|
if [ -f ${pidfile} ]; then
|
2015-05-04 10:38:50 +00:00
|
|
|
pid=`cat ${pidfile}`
|
|
|
|
while kill -0 $pid 2>/dev/null; do
|
|
|
|
kill -SIGTERM -$pid 2>/dev/null
|
|
|
|
sleep 1
|
2015-12-17 16:48:48 +00:00
|
|
|
# Kill processes if they are still running - may happen
|
|
|
|
# in interactive shells
|
2015-05-04 10:38:50 +00:00
|
|
|
ps fux | grep "python.*manage.py runserver" | awk '{print $2}' | xargs kill
|
|
|
|
done
|
|
|
|
rm ${pidfile}
|
2015-05-04 10:03:59 +00:00
|
|
|
fi
|
|
|
|
done
|
2013-10-11 12:46:23 +00:00
|
|
|
}
|
|
|
|
|
2015-05-04 10:38:50 +00:00
|
|
|
webserverStartAll()
|
2013-10-11 12:46:23 +00:00
|
|
|
{
|
2015-05-04 10:03:59 +00:00
|
|
|
# do not start if toastermain points to a valid process
|
|
|
|
if ! cat "${BUILDDIR}/.toastermain.pid" 2>/dev/null | xargs -I{} kill -0 {} ; then
|
|
|
|
retval=1
|
|
|
|
rm "${BUILDDIR}/.toastermain.pid"
|
|
|
|
fi
|
2014-06-03 15:26:15 +00:00
|
|
|
|
2015-05-04 10:03:59 +00:00
|
|
|
retval=0
|
2015-10-07 12:17:32 +00:00
|
|
|
# you can always add a superuser later via
|
2015-12-17 16:48:48 +00:00
|
|
|
# ../bitbake/lib/toaster/manage.py createsuperuser --username=<ME>
|
2015-12-17 16:48:50 +00:00
|
|
|
$MANAGE migrate --noinput || retval=1
|
2015-10-07 12:17:32 +00:00
|
|
|
|
2015-10-14 14:43:43 +00:00
|
|
|
if [ $retval -eq 1 ]; then
|
2015-12-10 03:56:41 +00:00
|
|
|
echo "Failed migrations, aborting system start" 1>&2
|
2015-10-14 14:43:43 +00:00
|
|
|
return $retval
|
|
|
|
fi
|
|
|
|
|
2015-12-17 16:48:50 +00:00
|
|
|
$MANAGE checksettings --traceback || retval=1
|
2015-10-14 14:43:43 +00:00
|
|
|
|
|
|
|
if [ $retval -eq 1 ]; then
|
|
|
|
printf "\nError while checking settings; aborting\n"
|
|
|
|
return $retval
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Starting webserver..."
|
|
|
|
|
2015-12-17 16:48:50 +00:00
|
|
|
$MANAGE runserver "0.0.0.0:$WEB_PORT" \
|
2015-12-17 16:48:48 +00:00
|
|
|
</dev/null >>${BUILDDIR}/toaster_web.log 2>&1 \
|
|
|
|
& echo $! >${BUILDDIR}/.toastermain.pid
|
2015-10-14 14:43:43 +00:00
|
|
|
|
|
|
|
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/"
|
2015-05-04 10:03:59 +00:00
|
|
|
fi
|
2015-10-14 14:43:43 +00:00
|
|
|
|
2015-05-04 10:03:59 +00:00
|
|
|
return $retval
|
2013-10-11 12:46:23 +00:00
|
|
|
}
|
|
|
|
|
2014-01-09 15:11:59 +00:00
|
|
|
INSTOPSYSTEM=0
|
|
|
|
|
2013-11-01 15:58:33 +00:00
|
|
|
# define the stop command
|
2015-05-04 10:38:50 +00:00
|
|
|
stop_system()
|
2013-11-01 15:58:33 +00:00
|
|
|
{
|
2014-01-09 15:11:59 +00:00
|
|
|
# prevent reentry
|
2015-05-04 09:16:48 +00:00
|
|
|
if [ $INSTOPSYSTEM -eq 1 ]; then return; fi
|
2014-01-09 15:11:59 +00:00
|
|
|
INSTOPSYSTEM=1
|
2013-11-01 15:58:33 +00:00
|
|
|
if [ -f ${BUILDDIR}/.toasterui.pid ]; then
|
2015-05-04 10:38:50 +00:00
|
|
|
kill `cat ${BUILDDIR}/.toasterui.pid` 2>/dev/null
|
2013-11-01 15:58:33 +00:00
|
|
|
rm ${BUILDDIR}/.toasterui.pid
|
|
|
|
fi
|
2015-12-02 18:02:43 +00:00
|
|
|
stop_bitbake
|
2013-11-01 15:58:33 +00:00
|
|
|
webserverKillAll
|
2015-12-02 18:02:59 +00:00
|
|
|
# unset exported variables
|
|
|
|
unset DATABASE_URL
|
|
|
|
unset TOASTER_CONF
|
|
|
|
unset TOASTER_DIR
|
2014-01-09 15:11:59 +00:00
|
|
|
trap - SIGHUP
|
2014-03-28 15:30:35 +00:00
|
|
|
#trap - SIGCHLD
|
2014-01-09 15:11:59 +00:00
|
|
|
INSTOPSYSTEM=0
|
|
|
|
}
|
|
|
|
|
2015-12-02 18:02:44 +00:00
|
|
|
start_bitbake() {
|
|
|
|
unset BBSERVER
|
2015-12-02 18:02:56 +00:00
|
|
|
bitbake --postread conf/toaster.conf --server-only -t xmlrpc -B 0.0.0.0:0
|
2015-12-02 18:02:44 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Bitbake server start failed"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
export BBSERVER=0.0.0.0:-1
|
2015-12-17 16:48:50 +00:00
|
|
|
export DATABASE_URL=`$MANAGE get-dburl`
|
2015-12-17 16:48:48 +00:00
|
|
|
# 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 \
|
2015-12-02 18:02:44 +00:00
|
|
|
& echo $! >${BUILDDIR}/.toasterui.pid
|
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2015-12-02 18:02:43 +00:00
|
|
|
stop_bitbake() {
|
|
|
|
BBSERVER=0.0.0.0:-1 bitbake -m
|
|
|
|
unset BBSERVER
|
|
|
|
# force stop any misbehaving bitbake server
|
|
|
|
lsof bitbake.lock | awk '{print $2}' | grep "[0-9]\+" | xargs -n1 -r kill
|
|
|
|
}
|
|
|
|
|
2015-05-04 10:38:50 +00:00
|
|
|
verify_prereq() {
|
2015-12-10 03:56:43 +00:00
|
|
|
# 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"
|
2015-02-05 12:07:44 +00:00
|
|
|
return 2
|
|
|
|
fi
|
2014-11-03 13:47:16 +00:00
|
|
|
|
2015-02-05 12:07:44 +00:00
|
|
|
return 0
|
|
|
|
}
|
2014-11-03 13:47:16 +00:00
|
|
|
|
|
|
|
# read command line parameters
|
2015-05-21 15:00:41 +00:00
|
|
|
if [ -n "$BASH_SOURCE" ] ; then
|
|
|
|
TOASTER=${BASH_SOURCE}
|
|
|
|
elif [ -n "$ZSH_NAME" ] ; then
|
|
|
|
TOASTER=${(%):-%x}
|
|
|
|
else
|
|
|
|
TOASTER=$0
|
|
|
|
fi
|
|
|
|
|
|
|
|
BBBASEDIR=`dirname $TOASTER`/..
|
2015-12-17 16:48:50 +00:00
|
|
|
MANAGE=$BBBASEDIR/lib/toaster/manage.py
|
2015-11-20 18:29:34 +00:00
|
|
|
OEROOT=`dirname $TOASTER`/../..
|
2015-12-17 16:48:55 +00:00
|
|
|
|
2015-10-07 12:17:33 +00:00
|
|
|
# this is the configuraton file we are using for toaster
|
2015-11-20 18:29:34 +00:00
|
|
|
# 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"
|
2015-12-17 16:48:48 +00:00
|
|
|
[ "$TOASTER_MANAGED" = '1' ] && exit 1 || return 1
|
2015-11-20 18:29:34 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2015-10-07 12:17:36 +00:00
|
|
|
if [ "$TOASTER_CONF" = "" ]; then
|
2015-11-20 18:29:34 +00:00
|
|
|
TOASTER_CONF="$TEMPLATECONF/toasterconf.json"
|
2015-10-15 16:34:14 +00:00
|
|
|
export TOASTER_CONF=$(python -c "import os; print os.path.realpath('$TOASTER_CONF')")
|
2015-10-07 12:17:34 +00:00
|
|
|
fi
|
2015-12-17 16:48:48 +00:00
|
|
|
|
2015-10-07 12:17:34 +00:00
|
|
|
if [ ! -f $TOASTER_CONF ]; then
|
2015-11-20 18:29:34 +00:00
|
|
|
echo "$TOASTER_CONF configuration file not found. Set TOASTER_CONF to specify file or fix .templateconf"
|
2015-10-15 16:34:17 +00:00
|
|
|
[ "$TOASTER_MANAGED" = '1' ] && exit 1 || return 1
|
2015-10-07 12:17:33 +00:00
|
|
|
fi
|
2015-12-17 16:48:48 +00:00
|
|
|
|
2015-10-07 12:17:33 +00:00
|
|
|
# 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=`pwd`
|
|
|
|
|
2015-12-17 16:48:55 +00:00
|
|
|
NOTOASTERUI=0
|
|
|
|
WEBSERVER=1
|
2015-05-18 13:13:15 +00:00
|
|
|
NOBROWSER=0
|
2015-12-17 16:48:55 +00:00
|
|
|
TOASTER_BRBE=""
|
|
|
|
WEB_PORT="8000"
|
2014-11-03 13:47:16 +00:00
|
|
|
|
|
|
|
for param in $*; do
|
|
|
|
case $param in
|
|
|
|
noui )
|
|
|
|
NOTOASTERUI=1
|
|
|
|
;;
|
|
|
|
noweb )
|
|
|
|
WEBSERVER=0
|
|
|
|
;;
|
2015-05-18 13:13:15 +00:00
|
|
|
nobrowser )
|
|
|
|
NOBROWSER=1
|
|
|
|
;;
|
2014-11-03 13:47:16 +00:00
|
|
|
brbe=* )
|
|
|
|
TOASTER_BRBE=$'\n'"TOASTER_BRBE=\""${param#*=}"\""
|
|
|
|
;;
|
|
|
|
webport=*)
|
|
|
|
WEB_PORT="${param#*=}"
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2015-12-02 18:02:33 +00:00
|
|
|
if [ `basename \"$0\"` = `basename \"${TOASTER}\"` ]; then
|
|
|
|
echo "Error: This script needs to be sourced. Please run as . $TOASTER"
|
|
|
|
exit 1
|
2013-10-11 12:46:23 +00:00
|
|
|
fi
|
|
|
|
|
2015-12-02 18:02:45 +00:00
|
|
|
if [ "$1" = 'restart-bitbake' ] ; then
|
|
|
|
stop_bitbake
|
|
|
|
sleep 1
|
|
|
|
start_bitbake
|
|
|
|
rc=$?
|
|
|
|
sleep 1
|
|
|
|
return $rc
|
|
|
|
fi
|
|
|
|
|
2015-12-10 03:56:43 +00:00
|
|
|
verify_prereq || return 1
|
2015-02-05 12:07:44 +00:00
|
|
|
|
2014-06-03 15:26:15 +00:00
|
|
|
# We make sure we're running in the current shell and in a good environment
|
2015-05-04 09:16:48 +00:00
|
|
|
if [ -z "$BUILDDIR" ] || ! which bitbake >/dev/null 2>&1 ; then
|
2015-05-04 10:03:59 +00:00
|
|
|
echo "Error: Build environment is not setup or bitbake is not in path." 1>&2
|
2013-10-11 12:46:23 +00:00
|
|
|
return 2
|
|
|
|
fi
|
|
|
|
|
2015-12-02 18:02:38 +00:00
|
|
|
# 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
|
|
|
|
if [ "$TOASTER_CONF" = "" ]; then
|
|
|
|
TOASTER_CONF="$(dirname $TOASTER)/../../meta-yocto/conf/toasterconf.json"
|
|
|
|
export TOASTER_CONF=$(python -c "import os; print os.path.realpath('$TOASTER_CONF')")
|
|
|
|
fi
|
|
|
|
if [ ! -f $TOASTER_CONF ]; then
|
2015-12-17 16:48:48 +00:00
|
|
|
echo "$TOASTER_CONF configuration file not found."
|
|
|
|
echo " set TOASTER_CONF to specify a path"
|
2015-12-02 18:02:38 +00:00
|
|
|
return 1
|
|
|
|
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
|
2015-12-17 16:48:48 +00:00
|
|
|
# make sure that the toaster.sqlite file doesn't default to `pwd`
|
|
|
|
# like it currently does.
|
2015-12-02 18:02:39 +00:00
|
|
|
export TOASTER_DIR=`dirname $BUILDDIR`
|
2015-12-02 18:02:38 +00:00
|
|
|
|
2013-10-11 12:46:23 +00:00
|
|
|
# Determine the action. If specified by arguments, fine, if not, toggle it
|
2015-05-21 15:00:41 +00:00
|
|
|
if [ "$1" = 'start' ] || [ "$1" = 'stop' ]; then
|
2013-10-11 12:46:23 +00:00
|
|
|
CMD="$1"
|
|
|
|
else
|
|
|
|
if [ -z "$BBSERVER" ]; then
|
|
|
|
CMD="start"
|
|
|
|
else
|
|
|
|
CMD="stop"
|
2015-05-04 10:03:59 +00:00
|
|
|
fi
|
2013-10-11 12:46:23 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "The system will $CMD."
|
|
|
|
|
|
|
|
# Execute the commands
|
|
|
|
|
|
|
|
case $CMD in
|
|
|
|
start )
|
2015-12-17 16:48:54 +00:00
|
|
|
# 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
|
|
|
|
|
2015-12-17 16:48:52 +00:00
|
|
|
# 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
|
|
|
|
|
2014-06-03 15:26:14 +00:00
|
|
|
if [ $WEBSERVER -gt 0 ] && ! webserverStartAll; then
|
2013-12-10 18:24:18 +00:00
|
|
|
echo "Failed ${CMD}."
|
|
|
|
return 4
|
|
|
|
fi
|
2015-12-02 18:02:44 +00:00
|
|
|
start_bitbake
|
|
|
|
if [ $? -eq 0 ]; then
|
2015-12-17 16:48:50 +00:00
|
|
|
$MANAGE runbuilds & echo $! >${BUILDDIR}/.runbuilds.pid
|
2013-12-10 18:24:18 +00:00
|
|
|
# set fail safe stop system on terminal exit
|
|
|
|
trap stop_system SIGHUP
|
|
|
|
echo "Successful ${CMD}."
|
2014-10-13 16:10:39 +00:00
|
|
|
return 0
|
2013-12-10 18:24:18 +00:00
|
|
|
else
|
|
|
|
# failed start, do stop
|
|
|
|
stop_system
|
|
|
|
echo "Failed ${CMD}."
|
2014-10-13 16:10:39 +00:00
|
|
|
return 1
|
2013-10-11 12:46:23 +00:00
|
|
|
fi
|
2014-01-09 15:11:59 +00:00
|
|
|
# stop system on terminal exit
|
|
|
|
set -o monitor
|
|
|
|
trap stop_system SIGHUP
|
2013-10-11 12:46:23 +00:00
|
|
|
;;
|
|
|
|
stop )
|
2013-11-01 15:58:33 +00:00
|
|
|
stop_system
|
2013-12-10 18:24:18 +00:00
|
|
|
echo "Successful ${CMD}."
|
2013-10-11 12:46:23 +00:00
|
|
|
;;
|
|
|
|
esac
|