diff scripts/launcher/launch.sh @ 49:068252a37689

update launching script
author souliane <souliane@mailoo.org>
date Mon, 28 Sep 2015 09:40:33 +0200
parents 1eb3ec190ea1
children fe116a11199b
line wrap: on
line diff
--- a/scripts/launcher/launch.sh	Wed Jul 15 12:37:14 2015 +0200
+++ b/scripts/launcher/launch.sh	Mon Sep 28 09:40:33 2015 +0200
@@ -1,9 +1,11 @@
-#!/bin/bash
+cd #!/bin/bash
 
 # This is a helping script to do some tasks like installing, cleaning, starting sat and/or libervia.
 
-# Python dist-packages where project are installed
+# Python and resources paths
 PACKAGES=/usr/local/lib/python2.7/dist-packages
+SHARE=/usr/local/share
+TMP=~/workspace/tmp_packages
 
 # Paths to the projects
 WORKSPACE=~/workspace
@@ -41,17 +43,20 @@
 # 4 SàT profiles names for testing
 SAT_PROFILES=(pierre elisee louise buenaventura)
 # Common profile password for these profiles
-SAT_PROFILES_PASSWD=
+SAT_PROFILES_PASSWD=xxxxxx
 
 # Launch sat in debug mode?
 SAT_DEBUG=1
 # Launch sat pubsub in debug mode?
 SPS_DEBUG=0
+# Launch salut in debug mode?
+SALUT_DEBUG=0
 # Launch libervia in debug mode?
-LIB_DEBUG=0
+LIB_DEBUG=1
 # Force killing processes?
 KILL_FORCE=1
 
+
 kill_process() {
     # $1 is the file containing the PID to kill
     if [ -f $1 ]; then
@@ -67,59 +72,104 @@
     fi
 }
 
+debug_console() {
+    PYTHONPATH=$TMP:$PYTHONPATH x-terminal-emulator -e "$@" &
+}
+
+install() {
+    echo "########## Compiling prosody ##########"
+	cd $PROSODY && make
+    echo "########## Installing sat_pubsub ##########"
+    cd $SATPUBSUB && sudo python setup.py install
+    echo "############## Installing sat #############"
+    cd $SAT && sudo python setup.py install
+    echo "########### Installing libervia ###########"
+    cd $LIBERVIA && sudo python setup.py install
+}
+
 stop_lib() {
     echo "############ Stopping libervia ############"
     libervia stop
     kill_process $LIB_PID
 }
+
 stop_sat() {
     echo "############### Stopping sat ##############"
     sat stop
     kill_process $SAT_PID
 }
+
+stop_sps() {
+	kill_process $SPS_PID
+}
+
+stop_salut() {
+    kill_process $SALUT_PID
+}
+
 stop_ser() {
     echo "############# Stopping Prosody ############"
     cd $PROSODY && if [[ -f $SER_PID ]]; then ./prosodyctl stop; fi
     kill_process $SER_PID
     echo "####### Stopping Prosody components #######"
-    kill_process $SPS_PID
-    kill_process $SALUT_PID
+	stop_sps
+	stop_salut
+    echo "####### Stopping bind9 #######"
+    sudo /etc/init.d/bind9 stop
+    
 }
-start_ser() {
-    echo "############# Starting Prosody ############"
-    cd $PROSODY && ./prosodyctl start &
-    echo "########## Installing sat_pubsub ##########"
-    cd $SATPUBSUB && sudo python setup.py install
+
+start_sps() {
     echo "########### Starting sat-pubsub ###########"
+    cd $SATPUBSUB
     if [[ $SPS_DEBUG = 1 ]]; then
-        mate-terminal -e "twistd -n -b sat_pubsub --jid=$SPS_JID --secret=$SPS_PWD" &
+        debug_console twistd -n -b sat_pubsub --jid=$SPS_JID --secret=$SPS_PWD
     else
         twistd sat_pubsub --jid=$SPS_JID --secret=$SPS_PWD
     fi
+}
+
+start_salut() {
     echo "############## Starting salut #############"
-    cd $SALUT && twistd -y salut.tac
-}
-start_sat() {
-    echo "############## Installing sat #############"
-    cd $SAT && sudo python setup.py install
-    echo "############### Starting sat ##############"
-    if [[ $SAT_DEBUG = 1 ]]; then
-        mate-terminal -e "sat debug" &
+    cd $SALUT
+    if [[ $SALUT_DEBUG = 1 ]]; then
+        debug_console twistd -b -y salut.tac
     else
-        sat
+        twistd -y salut.tac
     fi
 }
-start_lib() {
-    echo "########### Installing libervia ###########"
-    cd $LIBERVIA && sudo python setup.py install
-    echo "############ Starting libervia ############"
-    cd src
-    if [[ $LIB_DEBUG = 1 ]]; then
-        mate-terminal -e "libervia debug" &
+
+start_ser() {
+    echo "############# Starting Prosody ############"
+    cd $PROSODY && ./prosodyctl start &
+    start_sps
+    start_salut
+    echo "############## Starting bind9 #############"
+    sudo /etc/init.d/bind9 restart
+}
+
+start_sat() {
+    echo "############### Starting sat ##############"
+    cd $SAT/src
+    if [[ $SAT_DEBUG = 1 ]]; then
+        debug_console ./sat.sh debug
     else
-        libervia
+        ./sat.sh
     fi
 }
+
+start_lib() {
+    echo "############ Starting libervia ############"
+    cd $LIBERVIA/src/browser
+    pyjsbuild libervia_main -d --no-compile-inplace --platforms=mozilla -I $TMP -o $LIBERVIA/html
+    cd $LIBERVIA/src
+    if [[ $LIB_DEBUG = 1 ]]; then
+		debug_console ./libervia.sh debug
+    else
+        ./libervia.sh
+    fi
+}
+
 4foxes() {
     # Starts 4 instances of firefox and connect SàT profiles with Libervia
     # Assumes the HTTPS port for local server is 8443
@@ -129,26 +179,36 @@
         firefox -no-remote -P ${FF_PROFILES[$I]} "$URL" &
     done
 }
+
 clean() {
     echo "############ Cleaning log files ###########"
     rm -f $LOCAL_DIR/*.log*
     rm -f $SATPUBSUB/twistd.log*
+    rm -f $SALUT/twistd.log*
     rm -f $PROSODY/prosody.log* $PROSODY/prosody.err*
 }
+
 purge() {
     echo "######## Purging installed packages #######"
     rm -rf $PACKAGES/sat
     rm -rf $PACKAGES/sat_frontends
     rm -rf $PACKAGES/libervia
     rm -rf $PACKAGES/libervia_server
+    rm -rf $SHARE/libervia
 }
-main() {
+
+sat_main() {
     echo "######## Starting SàT main instance #######"
-    export PYTHONPATH=$SAT_MAIN/lib
-    cd $SAT_MAIN/lib/sat && hg pull -u && ./sat.sh
+    cd $SAT_MAIN/lib/sat && hg pull -u && PYTHONPATH=$SAT_MAIN/lib:$PYTHONPATH ./sat.sh
     echo "#### Starting primitivus main instance ####"
-    cd $SAT_MAIN/lib/sat_frontends/primitivus && ./primitivus
+    cd $SAT_MAIN/lib/sat_frontends/primitivus && PYTHONPATH=$SAT_MAIN/lib:$PYTHONPATH ./primitivus -p souliane
 }
+
+primitivus_main() {
+    echo "#### Starting primitivus main instance ####"
+    cd $SAT_MAIN/lib/sat_frontends/primitivus && PYTHONPATH=$SAT_MAIN/lib:$PYTHONPATH ./primitivus
+}
+
 bridge() {
     echo "######### Generating DBus.py files ########"
     cd $SAT/src/bridge/bridge_constructor
@@ -158,21 +218,39 @@
     SAT_BRIDGE_CONST_INT_PREFIX='"org.goffi.sat_main"' ./bridge_constructor.py --force && cp generated/DBus.py ../DBus.py
     SAT_BRIDGE_CONST_INT_PREFIX='"org.goffi.sat_main"' ./bridge_constructor.py -s frontend  --force && cp generated/DBus.py ../../../frontends/src/bridge/DBus.py
 }
+
 monitor_core() {
     echo "## Monitoring DBus for SàT dev instance - core ##"
     dbus-monitor "sender='org.goffi.SAT', interface='org.goffi.SAT.core'"
 }
+
 monitor_plugin() {
     echo "## Monitoring DBus for SàT dev instance - plugin ##"
     dbus-monitor "sender='org.goffi.SAT', interface='org.goffi.SAT.plugin'"
 }
+
 monitor_main() {
     echo "## Monitoring DBus for SàT main instance (redirected to /tmp/...) ##"
     killall -q dbus-monitor
     nohup dbus-monitor "sender='org.goffi.sat_main', interface='org.goffi.sat_main.core'" >> /tmp/sat_xml_core_`date +%y.%m.%d`&
     nohup dbus-monitor "sender='org.goffi.sat_main', interface='org.goffi.sat_main.plugin'" >> /tmp/sat_xml_plugin_`date +%y.%m.%d`&
 }
+
+link_pkgs() {
+    echo "## Linking temporary packages directory ##"
+	rm -f $TMP/*  # avoid to create symlinks like $TMP/sat/src
+	mkdir -p $TMP
+	ln -s $SAT/src $TMP/sat
+	ln -s $SAT/frontends/src $TMP/sat_frontends
+	ln -s $LIBERVIA/src $TMP/libervia
+	ln -s $WORKSPACE/urwid_satext/urwid_satext $TMP/urwid_satext
+}
+
+echo "using temporary directory $TMP"
+export PYTHONPATH=$TMP:$PYTHONPATH
+
 case "$1" in
+    install) install ;;
     stop_lib) stop_lib ;;
     stop_sat) stop_sat ;;
     stop_ser) stop_ser ;;
@@ -181,22 +259,26 @@
     start_lib) start_lib ;;
     stop) stop_lib && stop_sat && stop_ser ;;
     start) start_ser && start_sat && start_lib;;
-    restart_sat) stop_sat && stop_ser && start_ser && start_sat ;;
+    restart_ser) stop_ser && start_ser ;;
+    restart_sat) stop_sat && start_sat ;;
     restart_lib) stop_lib && start_lib ;;
+    restart_all)
+    	stop_lib && stop_sat && stop_ser && clean
+		start_ser && start_sat && start_lib;;
+	restart_sps) stop_sps && start_sps;;
+	restart_salut) stop_salut && start_salut ;;
     4foxes) 4foxes ;;
     clean) clean ;;
     purge) clean && purge;;
-    main) main ;;
+    main) sat_main ;;
+    primitivus_main) primitivus_main ;;
     bridge) bridge ;;
     monitor_core) monitor_core ;;
     monitor_plugin) monitor_plugin ;;
     monitor_main) monitor_main ;;
+	link_pkgs) link_pkgs ;;
     *)
-        # default: reinstall and restart all
-        stop_lib && stop_sat && stop_ser
-        clean
-        start_ser && start_sat && start_lib
-        ;;
+        echo "Please specify a valid command."
 esac
 
 echo "Done."