summaryrefslogtreecommitdiffstats
path: root/bitbake/bin/toaster
diff options
context:
space:
mode:
authorTudor Florea <tudor.florea@enea.com>2014-10-16 03:05:19 +0200
committerTudor Florea <tudor.florea@enea.com>2014-10-16 03:05:19 +0200
commitc527fd1f14c27855a37f2e8ac5346ce8d940ced2 (patch)
treebb002c1fdf011c41dbd2f0927bed23ecb5f83c97 /bitbake/bin/toaster
downloadpoky-daisy-140929.tar.gz
initial commit for Enea Linux 4.0-140929daisy-140929
Migrated from the internal git server on the daisy-enea-point-release branch Signed-off-by: Tudor Florea <tudor.florea@enea.com>
Diffstat (limited to 'bitbake/bin/toaster')
-rwxr-xr-xbitbake/bin/toaster214
1 files changed, 214 insertions, 0 deletions
diff --git a/bitbake/bin/toaster b/bitbake/bin/toaster
new file mode 100755
index 0000000000..dea69a4652
--- /dev/null
+++ b/bitbake/bin/toaster
@@ -0,0 +1,214 @@
1#!/bin/bash
2# (c) 2013 Intel Corp.
3
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 2 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18
19# This script enables toaster event logging and
20# starts bitbake resident server
21# use as: source toaster [start|stop]
22
23# Helper function to kill a background toaster development server
24
25function webserverKillAll()
26{
27 local pidfile
28 for pidfile in ${BUILDDIR}/.toastermain.pid; do
29 if [ -f ${pidfile} ]; then
30 while kill -0 $(< ${pidfile}) 2>/dev/null; do
31 kill -SIGTERM -$(< ${pidfile}) 2>/dev/null
32 sleep 1;
33 done;
34 rm ${pidfile}
35 fi
36 done
37}
38
39function webserverStartAll()
40{
41 retval=0
42 python $BBBASEDIR/lib/toaster/manage.py syncdb || retval=1
43 python $BBBASEDIR/lib/toaster/manage.py migrate orm || retval=2
44 if [ $retval -eq 1 ]; then
45 echo "Failed db sync, stopping system start" 1>&2
46 elif [ $retval -eq 2 ]; then
47 echo -e "\nError on migration, trying to recover... \n"
48 python $BBBASEDIR/lib/toaster/manage.py migrate orm 0001_initial --fake
49 retval=0
50 python $BBBASEDIR/lib/toaster/manage.py migrate orm || retval=1
51 fi
52 if [ $retval -eq 0 ]; then
53 python $BBBASEDIR/lib/toaster/manage.py runserver 0.0.0.0:8000 </dev/null >${BUILDDIR}/toaster_web.log 2>&1 & echo $! >${BUILDDIR}/.toastermain.pid
54 sleep 1
55 if ! cat "${BUILDDIR}/.toastermain.pid" | xargs -I{} kill -0 {} ; then
56 retval=1
57 rm "${BUILDDIR}/.toastermain.pid"
58 fi
59 fi
60 return $retval
61}
62
63# Helper functions to add a special configuration file
64
65function addtoConfiguration()
66{
67 echo "#Created by toaster start script" > ${BUILDDIR}/conf/$2
68 echo $1 >> ${BUILDDIR}/conf/$2
69}
70
71INSTOPSYSTEM=0
72
73# define the stop command
74function stop_system()
75{
76 # prevent reentry
77 if [ $INSTOPSYSTEM == 1 ]; then return; fi
78 INSTOPSYSTEM=1
79 if [ -f ${BUILDDIR}/.toasterui.pid ]; then
80 kill $(< ${BUILDDIR}/.toasterui.pid ) 2>/dev/null
81 rm ${BUILDDIR}/.toasterui.pid
82 fi
83 BBSERVER=localhost:8200 bitbake -m
84 unset BBSERVER
85 webserverKillAll
86 # force stop any misbehaving bitbake server
87 lsof bitbake.lock | awk '{print $2}' | grep "[0-9]\+" | xargs -n1 -r kill
88 trap - SIGHUP
89 #trap - SIGCHLD
90 INSTOPSYSTEM=0
91}
92
93function check_pidbyfile() {
94 [ -e $1 ] && kill -0 $(< $1) 2>/dev/null
95}
96
97
98function notify_chldexit() {
99 if [ $NOTOASTERUI == 0 ]; then
100 check_pidbyfile ${BUILDDIR}/.toasterui.pid && return
101 stop_system
102 fi
103}
104
105
106# We make sure we're running in the current shell and in a good environment
107
108if [ -z "$ZSH_NAME" ] && [ `basename \"$0\"` = `basename \"$BASH_SOURCE\"` ]; then
109 echo "Error: This script needs to be sourced. Please run as 'source toaster [start|stop]'" 1>&2;
110 exit 1
111fi
112
113if [ -z "$BUILDDIR" ] || [ -z `which bitbake` ]; then
114 echo "Error: Build environment is not setup or bitbake is not in path." 1>&2;
115 return 2
116fi
117
118BBBASEDIR=`dirname ${BASH_SOURCE}`/..
119
120
121# Verify prerequisites
122
123if ! echo "import django; print (1,5) == django.VERSION[0:2]" | python 2>/dev/null | grep True >/dev/null; then
124 echo -e "This program needs Django 1.5. Please install with\n\nsudo pip install django==1.5"
125 return 2
126fi
127
128if ! echo "import south; print [0,8,4] == map(int,south.__version__.split(\".\"))" | python 2>/dev/null | grep True >/dev/null; then
129 echo -e "This program needs South 0.8.4. Please install with\n\nsudo pip install south==0.8.4"
130 return 2
131fi
132
133
134
135
136
137# Determine the action. If specified by arguments, fine, if not, toggle it
138if [ "x$1" == "xstart" ] || [ "x$1" == "xstop" ]; then
139 CMD="$1"
140else
141 if [ -z "$BBSERVER" ]; then
142 CMD="start"
143 else
144 CMD="stop"
145 fi;
146fi
147
148NOTOASTERUI=0
149for param in $*; do
150 case $param in
151 noui )
152 NOTOASTERUI=1
153 ;;
154 esac
155done
156
157echo "The system will $CMD."
158
159# Make sure it's safe to run by checking bitbake lock
160
161lock=1
162if [ -e $BUILDDIR/bitbake.lock ]; then
163 (flock -n 200 ) 200<$BUILDDIR/bitbake.lock || lock=0
164fi
165
166if [ ${CMD} == "start" ] && ( [ $lock -eq 0 ] || [ -e $BUILDDIR/.toastermain.pid ] ); then
167 echo "Error: bitbake lock state error. File locks show that the system is on." 2>&1
168 echo "If you see problems, stop and then start the system again." 2>&1
169 return 3
170fi
171
172
173# Execute the commands
174
175case $CMD in
176 start )
177 start_success=1
178 addtoConfiguration "INHERIT+=\"toaster buildhistory\"" toaster.conf
179 if ! webserverStartAll; then
180 echo "Failed ${CMD}."
181 return 4
182 fi
183 unset BBSERVER
184 bitbake --postread conf/toaster.conf --server-only -t xmlrpc -B localhost:8200
185 if [ $? -ne 0 ]; then
186 start_success=0
187 echo "Bitbake server start failed"
188 else
189 export BBSERVER=localhost:8200
190 if [ $NOTOASTERUI == 0 ]; then # we start the TOASTERUI only if not inhibited
191 bitbake --observe-only -u toasterui >${BUILDDIR}/toaster_ui.log 2>&1 & echo $! >${BUILDDIR}/.toasterui.pid
192 fi
193 fi
194 if [ $start_success -eq 1 ]; then
195 # set fail safe stop system on terminal exit
196 trap stop_system SIGHUP
197 echo "Successful ${CMD}."
198 else
199 # failed start, do stop
200 stop_system
201 echo "Failed ${CMD}."
202 fi
203 # stop system on terminal exit
204 set -o monitor
205 trap stop_system SIGHUP
206 #trap notify_chldexit SIGCHLD
207 ;;
208 stop )
209 stop_system
210 echo "Successful ${CMD}."
211 ;;
212esac
213
214