summaryrefslogtreecommitdiffstats
path: root/bitbake/bin/toaster
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/bin/toaster')
-rwxr-xr-xbitbake/bin/toaster145
1 files changed, 145 insertions, 0 deletions
diff --git a/bitbake/bin/toaster b/bitbake/bin/toaster
new file mode 100755
index 0000000000..16de52b115
--- /dev/null
+++ b/bitbake/bin/toaster
@@ -0,0 +1,145 @@
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
39
40function webserverStartAll()
41{
42 retval=0
43 python $BBBASEDIR/lib/toaster/manage.py syncdb || retval=1
44 if [ $retval -eq 1 ]; then
45 echo "Failed db sync, stopping system start" 1>&2
46 else
47 python $BBBASEDIR/lib/toaster/manage.py runserver 0.0.0.0:8000 </dev/null >${BUILDDIR}/toaster_web.log 2>&1 & echo $! >${BUILDDIR}/.toastermain.pid
48 fi
49 return $retval
50}
51
52
53# We make sure we're running in the current shell and in a good environment
54
55if [ -z "$ZSH_NAME" ] && [ `basename \"$0\"` = `basename \"$BASH_SOURCE\"` ]; then
56 echo "Error: This script needs to be sourced. Please run as 'source toaster [start|stop]'" 1>&2;
57 exit 1
58fi
59
60if [ -z "$BUILDDIR" ] || [ -z `which bitbake` ]; then
61 echo "Error: Build environment is not setup or bitbake is not in path." 1>&2;
62 return 2
63fi
64
65BBBASEDIR=`dirname ${BASH_SOURCE}`/..
66
67
68# Verify prerequisites
69
70if ! echo "import django; print (1,4,5) == django.VERSION[0:3]" | python 2>/dev/null | grep True >/dev/null; then
71 echo -e "This program needs Django 1.4.5. Please install with\n\nsudo pip install django==1.4.5"
72 return 2
73fi
74
75
76
77# Determine the action. If specified by arguments, fine, if not, toggle it
78if [ "x$1" == "xstart" ] || [ "x$1" == "xstop" ]; then
79 CMD="$1"
80else
81 if [ -z "$BBSERVER" ]; then
82 CMD="start"
83 else
84 CMD="stop"
85 fi;
86fi
87
88NOTOASTERUI=0
89if [ "x$2" == "xnoui" ]; then
90 NOTOASTERUI=1
91fi
92
93echo "The system will $CMD."
94
95# Make sure it's safe to run by checking bitbake lock
96
97lock=1
98if [ -e $BUILDDIR/bitbake.lock ]; then
99 (flock -n 200 ) 200<$BUILDDIR/bitbake.lock || lock=0
100fi
101
102if [ ${CMD} == "start" ] && ( [ $lock -eq 0 ] || [ -e $BUILDDIR/.toastermain.pid ] ); then
103 echo "Error: bitbake lock state error. System is already on." 2>&1
104 return 3
105elif [ ${CMD} == "stop" ] && ( [ $lock -eq 1 ] || ! [ -e $BUILDDIR/.toastermain.pid ] ) ; then
106 echo "Error: bitbake lock state error. Trying to stop a stopped system ?
107If you think the system is hanged up, you can try to manually stop system with the commands
108
109# BBSERVER=localhost:8200 bitbake -m
110
111and
112
113# webserverKillAll
114" 2>&1
115 return 3
116fi
117
118
119# Execute the commands
120
121case $CMD in
122 start )
123 webserverStartAll || return 4
124 unset BBSERVER
125 bitbake --server-only -t xmlrpc -B localhost:8200
126 export BBSERVER=localhost:8200
127 if [ $NOTOASTERUI == 0 ]; then # we start the TOASTERUI only if not inhibited
128 bitbake --observe-only -u toasterui >${BUILDDIR}/toaster_ui.log 2>&1 & echo $! >${BUILDDIR}/.toasterui.pid
129 fi
130 ;;
131 stop )
132 if [ -f ${BUILDDIR}/.toasterui.pid ]; then
133 kill $(< ${BUILDDIR}/.toasterui.pid )
134 rm ${BUILDDIR}/.toasterui.pid
135 fi
136 bitbake -m
137 unset BBSERVER
138 webserverKillAll
139 # force stop any misbehaving bitbake server
140 lsof bitbake.lock | awk '{print $2}' | grep "[0-9]\+" | xargs -n1 -r kill
141 ;;
142esac
143
144echo "Successful ${CMD}."
145