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
2016-04-21 13:22:04 +00:00
HELP="
Usage: source toaster start|stop [webport=<address:port>] [noweb]
Optional arguments:
[noweb] Setup the environment for building with toaster but don't start the development server
[webport] Set the development server (default: localhost:8000)
"
2013-10-11 12:46:23 +00:00
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
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
2016-08-01 18:32:53 +00:00
# Make sure that checksettings can pick up any value for TEMPLATECONF
export TEMPLATECONF
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..."
2016-04-21 13:22:05 +00:00
$MANAGE runserver "$ADDR_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
2016-04-21 13:22:05 +00:00
echo "Toaster development webserver started at http://$ADDR_PORT"
echo -e "\nYou can now run 'bitbake <target>' on the command line and monitor your build in Toaster.\nYou can also use a Toaster project to configure and run a build.\n"
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
webserverKillAll
2015-12-02 18:02:59 +00:00
# unset exported variables
unset TOASTER_DIR
2016-04-06 16:46:13 +00:00
unset BITBAKE_UI
2016-04-06 16:46:45 +00:00
unset BBBASEDIR
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-05-04 10:38:50 +00:00
verify_prereq() {
2015-12-10 03:56:43 +00:00
# Verify Django version
2016-05-30 17:24:52 +00:00
reqfile=$(python3 -c "import os; print(os.path.realpath('$BBBASEDIR/toaster-requirements.txt'))")
2015-12-10 03:56:43 +00:00
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'
2016-06-10 10:01:10 +00:00
if ! sed -n "$exp" $reqfile | python3 - ; then
2015-12-10 03:56:43 +00:00
req=`grep ^Django $reqfile`
echo "This program needs $req"
2016-12-08 15:51:22 +00:00
echo "Please install with pip3 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
2016-04-06 16:46:45 +00:00
export BBBASEDIR=`dirname $TOASTER`/..
2016-05-30 17:24:52 +00:00
MANAGE="python3 $BBBASEDIR/lib/toaster/manage.py"
2016-09-27 15:16:52 +00:00
OE_ROOT=`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.
2016-09-27 15:16:52 +00:00
. $OE_ROOT/.templateconf
2015-11-20 18:29:34 +00:00
if [ -n "$TEMPLATECONF" ]; then
if [ ! -d "$TEMPLATECONF" ]; then
# Allow TEMPLATECONF=meta-xyz/conf as a shortcut
2016-09-27 15:16:52 +00:00
if [ -d "$OE_ROOT/$TEMPLATECONF" ]; then
TEMPLATECONF="$OE_ROOT/$TEMPLATECONF"
2015-11-20 18:29:34 +00:00
fi
fi
fi
2016-09-27 15:16:52 +00:00
unset OE_ROOT
2017-02-07 20:36:13 +00:00
2015-10-07 12:17:33 +00:00
2015-12-17 16:48:55 +00:00
WEBSERVER=1
2016-04-21 13:22:05 +00:00
ADDR_PORT="localhost:8000"
2016-03-01 11:40:55 +00:00
unset CMD
2014-11-03 13:47:16 +00:00
for param in $*; do
case $param in
noweb )
WEBSERVER=0
;;
2016-03-01 11:40:55 +00:00
start )
CMD=$param
;;
stop )
CMD=$param
;;
2014-11-03 13:47:16 +00:00
webport=*)
2016-04-21 13:22:05 +00:00
ADDR_PORT="${param#*=}"
# Split the addr:port string
ADDR=`echo $ADDR_PORT | cut -f 1 -d ':'`
PORT=`echo $ADDR_PORT | cut -f 2 -d ':'`
# If only a port has been speified then set address to localhost.
if [ $ADDR = $PORT ] ; then
ADDR_PORT="localhost:$PORT"
fi
2016-04-21 13:22:04 +00:00
;;
2016-08-02 23:43:54 +00:00
--help)
echo "$HELP"
return 0
;;
2016-04-21 13:22:04 +00:00
*)
echo "$HELP"
return 1
;;
2014-11-03 13:47:16 +00:00
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"
2016-03-01 11:40:55 +00:00
return 1
2013-10-11 12:46:23 +00:00
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 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
2015-12-02 18:02:39 +00:00
export TOASTER_DIR=`dirname $BUILDDIR`
2017-02-07 20:36:13 +00:00
export BB_ENV_EXTRAWHITE="$BB_ENV_EXTRAWHITE TOASTER_DIR"
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
2016-03-01 11:40:55 +00:00
if [ "$CMD" = "start" ] ; then
if [ -n "$BBSERVER" ]; then
echo " Toaster is already running. Exiting..."
return 1
fi
elif [ "$CMD" = "" ]; then
2016-04-21 13:22:04 +00:00
echo "No command specified"
echo "$HELP"
return 1
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
2016-04-21 13:22:06 +00:00
if [ $WEBSERVER -gt 0 ]; then
$MANAGE checksocket "$ADDR_PORT" || return 1
fi
2015-12-17 16:48:54 +00:00
fi
2015-12-17 16:48:52 +00:00
# Create configuration file
2016-04-06 16:46:25 +00:00
conf=${BUILDDIR}/conf/local.conf
line='INHERIT+="toaster buildhistory"'
grep -q "$line" $conf || echo $line >> $conf
2015-12-17 16:48:52 +00:00
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
2016-04-06 16:46:13 +00:00
export BITBAKE_UI='toasterui'
2017-02-07 20:36:13 +00:00
$MANAGE runbuilds \
</dev/null >>${BUILDDIR}/toaster_runbuilds.log 2>&1 \
& echo $! >${BUILDDIR}/.runbuilds.pid
2016-04-06 16:46:11 +00:00
# set fail safe stop system on terminal exit
2014-01-09 15:11:59 +00:00
trap stop_system SIGHUP
2016-04-06 16:46:11 +00:00
echo "Successful ${CMD}."
return 0
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