comparison scripts/launcher/launch.sh @ 3:73d3b94b7364

added DNS SRV configuration script + move launching script to scripts/launcher/launch.sh
author souliane <souliane@mailoo.org>
date Fri, 27 Jun 2014 19:17:18 +0200
parents scripts/launch.sh@3ec5808e3b53
children 19448ad3a7d9
comparison
equal deleted inserted replaced
2:3ec5808e3b53 3:73d3b94b7364
1 #!/bin/bash
2
3 # This is a helping script to do some tasks like installing, cleaning, starting sat and/or libervia.
4
5 # Python dist-packages where project are installed
6 PACKAGES=/usr/local/lib/python2.7/dist-packages
7
8 # Paths to the projects
9 WORKSPACE=~/workspace
10 SAT=$WORKSPACE/sat
11 PYJS=$WORKSPACE/pyjamas
12 LIBERVIA=$WORKSPACE/libervia
13 PROSODY=$WORKSPACE/prosody-hg
14 SATPUBSUB=$WORKSPACE/sat_pubsub
15 URWID_SATEXT=$WORKSPACE/urwid_satext
16
17 # PIDs of the processes
18 LOCAL_DIR=~/.local/share/sat
19 SAT_PID=$LOCAL_DIR/sat.pid
20 LIB_PID=$LOCAL_DIR/libervia.pid
21 SER_PID=$PROSODY/prosody.pid
22 SPS_PID=$SATPUBSUB/twistd.pid
23
24 # Connection information for sat_pubsub
25 SPS_JID=sat-pubsub.souliane.org
26 SPS_PWD=password
27
28 # Informations for a concurrent sat instance
29 # For this to work, you have to follow the instructions in:
30 # http://wiki.goffi.org/wiki/Howto_launch_several_S%C3%A0T_instances
31 # Also:
32 # - modify const_INT_PREFIX in the two DBus.py files
33 # - set DAEMON="" in the sat.sh to launch sat as a daemon
34 SAT_MAIN=$WORKSPACE/sat_main
35 SAT_MAIN_PID=~/.sat_main/sat.pid
36
37 # 4 Firefox profiles names for testing
38 FF_PROFILES=(test1 test2 test3 test4)
39 # 4 SąT profiles names for testing
40 SAT_PROFILES=(Peter Steven Dave Dino)
41 # Passwords for these profiles
42 SAT_PROFILES_PASSWD=(xxxxxx xxxxxx xxxxxx xxxxxx)
43
44 # Launch sat in debug mode?
45 SAT_DEBUG=1
46 # Launch sat pubsub in debug mode?
47 SPS_DEBUG=0
48 # Launch libervia in debug mode?
49 LIB_DEBUG=1
50 # Force killing processes?
51 KILL_FORCE=1
52
53 kill_process() {
54 # $1 is the file containing the PID to kill
55 if [ -f $1 ]; then
56 PID=`cat $1`
57 if ps -p $PID > /dev/null; then
58 if [[ $KILL_FORCE = 1 ]]; then
59 kill -9 $PID
60 else
61 kill -INT $PID
62 fi
63 fi
64 rm -f $1
65 fi
66 }
67
68 stop_lib() {
69 echo "############ Stopping libervia ############"
70 libervia stop
71 kill_process $LIB_PID
72 }
73 stop_sat() {
74 echo "############### Stopping sat ##############"
75 sat stop
76 kill_process $SAT_PID
77 }
78 stop_ser() {
79 echo "############# Stopping Prosody ############"
80 cd $PROSODY && if [[ -f $SER_PID ]]; then ./prosodyctl stop; fi
81 kill_process $SER_PID
82 echo "########### Stopping sat_pubsub ###########"
83 kill_process $SPS_PID
84 }
85 start_ser() {
86 echo "############# Starting Prosody ############"
87 cd $PROSODY && ./prosodyctl start
88 echo "########## Installing sat_pubsub ##########"
89 cd $SATPUBSUB && sudo python setup.py install
90 echo "########### Starting sat-pubsub ###########"
91 if [[ $SPS_DEBUG = 1 ]]; then
92 mate-terminal -e "twistd -n -b sat_pubsub --jid=$SPS_JID --secret=$SPS_PWD" &
93 else
94 twistd sat_pubsub --jid=$SPS_JID --secret=$SPS_PWD
95 fi
96 }
97 start_sat() {
98 echo "############## Installing sat #############"
99 cd $SAT && sudo python setup.py install
100 echo "############### Starting sat ##############"
101 if [[ $SAT_DEBUG = 1 ]]; then
102 mate-terminal -e "sat debug" &
103 else
104 sat
105 fi
106 }
107 start_lib() {
108 echo "########### Installing libervia ###########"
109 cd $LIBERVIA && sudo python setup.py install
110 echo "############ Starting libervia ############"
111 cd src
112 if [[ $LIB_DEBUG = 1 ]]; then
113 mate-terminal -e "libervia debug" &
114 else
115 libervia
116 fi
117 }
118 4foxes() {
119 # Starts 4 instances of firefox and connect SąT profiles with Libervia
120 # Assumes the HTTPS port for local server is 8443
121 echo "####### Starting 4 libervia clients #######"
122 for I in `seq 0 3`; do
123 URL="https://localhost:8443/libervia.html?login=${SAT_PROFILES[$I]}&passwd=${SAT_PROFILES_PASSWD[$I]}"
124 firefox -no-remote -P ${FF_PROFILES[$I]} "$URL" &
125 done
126 }
127 clean() {
128 echo "############ Cleaning log files ###########"
129 rm -f $LOCAL_DIR/*.log*
130 rm -f $SATPUBSUB/twistd.log*
131 rm -f $PROSODY/prosody.log* $PROSODY/prosody.err*
132 }
133 purge() {
134 echo "######## Purging installed packages #######"
135 rm -rf $PACKAGES/sat
136 rm -rf $PACKAGES/sat_frontends
137 rm -rf $PACKAGES/libervia
138 rm -rf $PACKAGES/libervia_server
139 }
140 main() {
141 echo "######## Starting SąT main instance #######"
142 export PYTHONPATH=$SAT_MAIN/lib
143 cd $SAT_MAIN/lib/sat && hg pull -u && ./sat.sh
144 echo "#### Starting primitivus main instance ####"
145 cd $SAT_MAIN/lib/sat_frontends/primitivus && ./primitivus
146 }
147 bridge() {
148 echo "######### Generating DBus.py files ########"
149 cd $SAT/src/bridge/bridge_constructor
150 ./bridge_constructor.py --force && cp generated/DBus.py ../DBus.py
151 ./bridge_constructor.py -s frontend --force && cp generated/DBus.py ../../../frontends/src/bridge/DBus.py
152 cd $SAT_MAIN/src/bridge/bridge_constructor
153 SAT_BRIDGE_CONST_INT_PREFIX='"org.goffi.sat_main"' ./bridge_constructor.py --force && cp generated/DBus.py ../DBus.py
154 SAT_BRIDGE_CONST_INT_PREFIX='"org.goffi.sat_main"' ./bridge_constructor.py -s frontend --force && cp generated/DBus.py ../../../frontends/src/bridge/DBus.py
155 }
156 monitor() {
157 echo "## Monitoring DBus for SąT main instance ##"
158 killall -q dbus-monitor
159 nohup dbus-monitor "sender='org.goffi.sat_main', interface='org.goffi.sat_main.core'" >> /tmp/sat_xml_core_`date +%y.%m.%d`&
160 nohup dbus-monitor "sender='org.goffi.sat_main', interface='org.goffi.sat_main.plugin'" >> /tmp/sat_xml_plugin_`date +%y.%m.%d`&
161 }
162 case "$1" in
163 stop_lib) stop_lib ;;
164 stop_sat) stop_sat ;;
165 stop_ser) stop_ser ;;
166 start_ser) start_ser ;;
167 start_sat) start_sat ;;
168 start_lib) start_lib ;;
169 stop) stop_lib && stop_sat && stop_ser ;;
170 start) start_ser && start_sat && start_lib;;
171 restart_sat) stop_sat && stop_ser && start_ser && start_sat ;;
172 restart_lib) stop_lib && start_lib ;;
173 4foxes) 4foxes ;;
174 clean) clean ;;
175 purge) clean && purge;;
176 main) main ;;
177 bridge) bridge;;
178 monitor) monitor;;
179 *)
180 # default: reinstall and restart all
181 stop_lib && stop_sat && stop_ser
182 clean
183 start_ser && start_sat && start_lib
184 ;;
185 esac
186
187 echo "Done."