summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbitbake/bin/toaster55
1 files changed, 28 insertions, 27 deletions
diff --git a/bitbake/bin/toaster b/bitbake/bin/toaster
index ee199374e3..0fa8b60142 100755
--- a/bitbake/bin/toaster
+++ b/bitbake/bin/toaster
@@ -28,23 +28,24 @@
28 28
29# Helper function to kill a background toaster development server 29# Helper function to kill a background toaster development server
30 30
31function webserverKillAll() 31webserverKillAll()
32{ 32{
33 local pidfile 33 local pidfile
34 for pidfile in ${BUILDDIR}/.toastermain.pid; do 34 for pidfile in ${BUILDDIR}/.toastermain.pid; do
35 if [ -f ${pidfile} ]; then 35 if [ -f ${pidfile} ]; then
36 while kill -0 $(< ${pidfile}) 2>/dev/null; do 36 pid=`cat ${pidfile}`
37 kill -SIGTERM -$(< ${pidfile}) 2>/dev/null 37 while kill -0 $pid 2>/dev/null; do
38 sleep 1 38 kill -SIGTERM -$pid 2>/dev/null
39 # Kill processes if they are still running - may happen in interactive shells 39 sleep 1
40 pkill -U $UID -f "python.*manage.py runserver" 40 # Kill processes if they are still running - may happen in interactive shells
41 done; 41 ps fux | grep "python.*manage.py runserver" | awk '{print $2}' | xargs kill
42 rm ${pidfile} 42 done
43 rm ${pidfile}
43 fi 44 fi
44 done 45 done
45} 46}
46 47
47function webserverStartAll() 48webserverStartAll()
48{ 49{
49 # do not start if toastermain points to a valid process 50 # do not start if toastermain points to a valid process
50 if ! cat "${BUILDDIR}/.toastermain.pid" 2>/dev/null | xargs -I{} kill -0 {} ; then 51 if ! cat "${BUILDDIR}/.toastermain.pid" 2>/dev/null | xargs -I{} kill -0 {} ; then
@@ -62,7 +63,7 @@ function webserverStartAll()
62 if [ $retval -eq 1 ]; then 63 if [ $retval -eq 1 ]; then
63 echo "Failed db sync, stopping system start" 1>&2 64 echo "Failed db sync, stopping system start" 1>&2
64 elif [ $retval -eq 2 ]; then 65 elif [ $retval -eq 2 ]; then
65 echo -e "\nError on migration, trying to recover... \n" 66 printf "\nError on migration, trying to recover... \n"
66 python $BBBASEDIR/lib/toaster/manage.py migrate orm 0001_initial --fake 67 python $BBBASEDIR/lib/toaster/manage.py migrate orm 0001_initial --fake
67 retval=0 68 retval=0
68 python $BBBASEDIR/lib/toaster/manage.py migrate orm || retval=1 69 python $BBBASEDIR/lib/toaster/manage.py migrate orm || retval=1
@@ -87,7 +88,7 @@ function webserverStartAll()
87 88
88# Helper functions to add a special configuration file 89# Helper functions to add a special configuration file
89 90
90function addtoConfiguration() 91addtoConfiguration()
91{ 92{
92 file=$1 93 file=$1
93 shift 94 shift
@@ -98,13 +99,13 @@ function addtoConfiguration()
98INSTOPSYSTEM=0 99INSTOPSYSTEM=0
99 100
100# define the stop command 101# define the stop command
101function stop_system() 102stop_system()
102{ 103{
103 # prevent reentry 104 # prevent reentry
104 if [ $INSTOPSYSTEM -eq 1 ]; then return; fi 105 if [ $INSTOPSYSTEM -eq 1 ]; then return; fi
105 INSTOPSYSTEM=1 106 INSTOPSYSTEM=1
106 if [ -f ${BUILDDIR}/.toasterui.pid ]; then 107 if [ -f ${BUILDDIR}/.toasterui.pid ]; then
107 kill $(< ${BUILDDIR}/.toasterui.pid ) 2>/dev/null 108 kill `cat ${BUILDDIR}/.toasterui.pid` 2>/dev/null
108 rm ${BUILDDIR}/.toasterui.pid 109 rm ${BUILDDIR}/.toasterui.pid
109 fi 110 fi
110 BBSERVER=0.0.0.0:-1 bitbake -m 111 BBSERVER=0.0.0.0:-1 bitbake -m
@@ -117,12 +118,12 @@ function stop_system()
117 INSTOPSYSTEM=0 118 INSTOPSYSTEM=0
118} 119}
119 120
120function check_pidbyfile() { 121check_pidbyfile() {
121 [ -e $1 ] && kill -0 $(< $1) 2>/dev/null 122 [ -e $1 ] && kill -0 `cat $1` 2>/dev/null
122} 123}
123 124
124 125
125function notify_chldexit() { 126notify_chldexit() {
126 if [ $NOTOASTERUI -eq 0 ]; then 127 if [ $NOTOASTERUI -eq 0 ]; then
127 check_pidbyfile ${BUILDDIR}/.toasterui.pid && return 128 check_pidbyfile ${BUILDDIR}/.toasterui.pid && return
128 stop_system 129 stop_system
@@ -130,16 +131,16 @@ function notify_chldexit() {
130} 131}
131 132
132 133
133function verify_prereq() { 134verify_prereq() {
134 # Verify prerequisites 135 # Verify prerequisites
135 136
136 if ! echo "import django; print (1,) == django.VERSION[0:1] and django.VERSION[1:2][0] in (6,)" | python 2>/dev/null | grep True >/dev/null; then 137 if ! echo "import django; print (1,) == django.VERSION[0:1] and django.VERSION[1:2][0] in (6,)" | python 2>/dev/null | grep True >/dev/null; then
137 echo -e "This program needs Django 1.6. Please install with\n\npip install django==1.6\n" 138 printf "This program needs Django 1.6. Please install with\n\npip install django==1.6\n"
138 return 2 139 return 2
139 fi 140 fi
140 141
141 if ! echo "import south; print reduce(lambda x, y: 2 if x==2 else 0 if x == 0 else y, map(lambda x: 1+cmp(x[1]-x[0],0), zip([0,8,4], map(int,south.__version__.split(\".\"))))) > 0" | python 2>/dev/null | grep True >/dev/null; then 142 if ! echo "import south; print reduce(lambda x, y: 2 if x==2 else 0 if x == 0 else y, map(lambda x: 1+cmp(x[1]-x[0],0), zip([0,8,4], map(int,south.__version__.split(\".\"))))) > 0" | python 2>/dev/null | grep True >/dev/null; then
142 echo -e "This program needs South 0.8.4. Please install with\n\npip install south==0.8.4\n" 143 printf "This program needs South 0.8.4. Please install with\n\npip install south==0.8.4\n"
143 return 2 144 return 2
144 fi 145 fi
145 return 0 146 return 0
@@ -182,42 +183,42 @@ if [ `basename \"$0\"` = `basename \"${SRCFILE}\"` ]; then
182 # Start just the web server, point the web browser to the interface, and start any Django services. 183 # Start just the web server, point the web browser to the interface, and start any Django services.
183 184
184 if ! verify_prereq; then 185 if ! verify_prereq; then
185 echo -e "Error: Could not verify that the needed dependencies are installed. Please use virtualenv and pip to install dependencies listed in toaster-requirements.txt" 1>&2 186 echo "Error: Could not verify that the needed dependencies are installed. Please use virtualenv and pip to install dependencies listed in toaster-requirements.txt" 1>&2
186 exit 1 187 exit 1
187 fi 188 fi
188 189
189 if [ -n "$BUILDDIR" ]; then 190 if [ -n "$BUILDDIR" ]; then
190 echo -e "Error: It looks like you sourced oe-init-build-env. Toaster cannot start in build mode from an oe-core build environment.\n You should be starting Toaster from a new terminal window." 1>&2 191 printf "Error: It looks like you sourced oe-init-build-env. Toaster cannot start in build mode from an oe-core build environment.\n You should be starting Toaster from a new terminal window." 1>&2
191 exit 1 192 exit 1
192 fi 193 fi
193 194
194 # Define a fake builddir where only the pid files are actually created. No real builds will take place here. 195 # Define a fake builddir where only the pid files are actually created. No real builds will take place here.
195 BUILDDIR=/tmp/toaster_$$ 196 BUILDDIR=/tmp/toaster_$$
196 if [ -d "$BUILDDIR" ]; then 197 if [ -d "$BUILDDIR" ]; then
197 echo -e "Previous toaster run directory $BUILDDIR found, cowardly refusing to start. Please remove the directory when that toaster instance is over" 2>&1 198 echo "Previous toaster run directory $BUILDDIR found, cowardly refusing to start. Please remove the directory when that toaster instance is over" 2>&1
198 exit 1 199 exit 1
199 fi 200 fi
200 201
201 mkdir -p "$BUILDDIR" 202 mkdir -p "$BUILDDIR"
202 203
203 RUNNING=1 204 RUNNING=1
204 function trap_ctrlc() { 205 trap_ctrlc() {
205 echo "** Stopping system" 206 echo "** Stopping system"
206 webserverKillAll 207 webserverKillAll
207 RUNNING=0 208 RUNNING=0
208 } 209 }
209 210
210 function do_cleanup() { 211 do_cleanup() {
211 find "$BUILDDIR" -type f | xargs rm 212 find "$BUILDDIR" -type f | xargs rm
212 rmdir "$BUILDDIR" 213 rmdir "$BUILDDIR"
213 } 214 }
214 function cleanup() { 215 cleanup() {
215 if grep -ir error "$BUILDDIR" >/dev/null; then 216 if grep -ir error "$BUILDDIR" >/dev/null; then
216 if grep -irn "That port is already in use" "$BUILDDIR"; then 217 if grep -irn "That port is already in use" "$BUILDDIR"; then
217 echo "You can use the \"webport=PORTNUMBER\" parameter to start Toaster on a different port (port $WEB_PORT is already in use)" 218 echo "You can use the \"webport=PORTNUMBER\" parameter to start Toaster on a different port (port $WEB_PORT is already in use)"
218 do_cleanup 219 do_cleanup
219 else 220 else
220 echo -e "\nErrors found in the Toaster log files present in '$BUILDDIR'. Directory will not be cleaned.\n Please review the errors and notify toaster@yoctoproject.org or submit a bug https://bugzilla.yoctoproject.org/enter_bug.cgi?product=Toaster" 221 printf "\nErrors found in the Toaster log files present in '$BUILDDIR'. Directory will not be cleaned.\n Please review the errors and notify toaster@yoctoproject.org or submit a bug https://bugzilla.yoctoproject.org/enter_bug.cgi?product=Toaster"
221 fi 222 fi
222 else 223 else
223 echo "No errors found, removing the run directory '$BUILDDIR'" 224 echo "No errors found, removing the run directory '$BUILDDIR'"
@@ -248,7 +249,7 @@ fi
248 249
249 250
250if ! verify_prereq; then 251if ! verify_prereq; then
251 echo -e "Error: Could not verify that the needed dependencies are installed. Please use virtualenv and pip to install dependencies listed in toaster-requirements.txt" 1>&2 252 echo "Error: Could not verify that the needed dependencies are installed. Please use virtualenv and pip to install dependencies listed in toaster-requirements.txt" 1>&2
252 return 1 253 return 1
253fi 254fi
254 255