diff options
Diffstat (limited to 'bitbake/bin/toaster')
-rwxr-xr-x | bitbake/bin/toaster | 145 |
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 | |||
25 | function 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 | |||
40 | function 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 | |||
55 | if [ -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 | ||
58 | fi | ||
59 | |||
60 | if [ -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 | ||
63 | fi | ||
64 | |||
65 | BBBASEDIR=`dirname ${BASH_SOURCE}`/.. | ||
66 | |||
67 | |||
68 | # Verify prerequisites | ||
69 | |||
70 | if ! 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 | ||
73 | fi | ||
74 | |||
75 | |||
76 | |||
77 | # Determine the action. If specified by arguments, fine, if not, toggle it | ||
78 | if [ "x$1" == "xstart" ] || [ "x$1" == "xstop" ]; then | ||
79 | CMD="$1" | ||
80 | else | ||
81 | if [ -z "$BBSERVER" ]; then | ||
82 | CMD="start" | ||
83 | else | ||
84 | CMD="stop" | ||
85 | fi; | ||
86 | fi | ||
87 | |||
88 | NOTOASTERUI=0 | ||
89 | if [ "x$2" == "xnoui" ]; then | ||
90 | NOTOASTERUI=1 | ||
91 | fi | ||
92 | |||
93 | echo "The system will $CMD." | ||
94 | |||
95 | # Make sure it's safe to run by checking bitbake lock | ||
96 | |||
97 | lock=1 | ||
98 | if [ -e $BUILDDIR/bitbake.lock ]; then | ||
99 | (flock -n 200 ) 200<$BUILDDIR/bitbake.lock || lock=0 | ||
100 | fi | ||
101 | |||
102 | if [ ${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 | ||
105 | elif [ ${CMD} == "stop" ] && ( [ $lock -eq 1 ] || ! [ -e $BUILDDIR/.toastermain.pid ] ) ; then | ||
106 | echo "Error: bitbake lock state error. Trying to stop a stopped system ? | ||
107 | If 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 | |||
111 | and | ||
112 | |||
113 | # webserverKillAll | ||
114 | " 2>&1 | ||
115 | return 3 | ||
116 | fi | ||
117 | |||
118 | |||
119 | # Execute the commands | ||
120 | |||
121 | case $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 | ;; | ||
142 | esac | ||
143 | |||
144 | echo "Successful ${CMD}." | ||
145 | |||