Commits

Anonymous committed 1cc750f

added dtach tool for proper background launch.

Comments (0)

Files changed (3)

recipes/mosaic-mos/receipt

 CATEGORY="mosaic-apps"
 SHORT_DESC="SliTaz mOS v0.7 - mOSAIC Project (www.mosaic-cloud.eu)"
 MAINTAINER="silviu@info.uvt.ro"
-DEPENDS="slitaz-base-files slitaz-boot-scripts busybox acpid"
+DEPENDS="slitaz-base-files slitaz-boot-scripts busybox acpid dtach"
 WEB_SITE="http://developers.mosaic-cloud.eu/"
 
 # Rules to gen a SliTaz package suitable for Tazpkg.

recipes/mosaic-mos/stuff/etc/init.d/mosaic

 
 HEADER="\e[1;32m[\e[0;34m mOS:boot \e[1;32m]\e[0m "
 
-trap "echo '[ mOS:trap ]  SIGNAL received ... ignoring ...'" INT EXIT TERM
-
 zeroconf_ip='169.254.169.254'
 regsrv_ip='mosaic.grid.info.uvt.ro'
 regsrv_domain='vms.mosaic.ieat.ro'
 DEPLOY_DIR=/mosaic
 LOG=$DEPLOY_DIR/mosaic.log
 
-if [ -d $DEPLOY_DIR ];then
-	echo -e "$HEADER Changing to deploy directory: $DEPLOY_DIR ..."		
-	cd $DEPLOY_DIR	
-else
-	echo -e "$HEADER Creating deploy directory: $DEPLOY_DIR ..." 
-	mkdir $DEPLOY_DIR
-	echo -e "$HEADER   -->> changing to $DEPLOY_DIR ..."
-	cd $DEPLOY_DIR
-fi
-
-if [ -e $LOG ];then
-	echo -e "$HEADER Log file exists. Backing up the file ..."
-	mv $LOG $LOG.`date +%d.%m.%Y-%H.%M.%s`
-fi
-
 #####################################################################################
 function zeroconf_update() {
 	if grep -q testbed /proc/cmdline;then
 }
 
 function pkg_daemon() {
-	echo -e "$HEADER starting tazpkg daemon ..."
-	/mosaic/bin/run-pkg-daemon &
-	sleep 3
+	echo -e "$HEADER Starting tazpkg daemon ..."
+	dtach -n /tmp/.run-pkg-daemon /mosaic/bin/run-pkg-daemon
 }
 
 ################################################################################
 ################################################################################
 
-echo -e "$HEADER"
+case "$1" in
+       	start)
+       		trap "echo '[ mOS:trap ]  SIGNAL received ... ignoring ...'" INT EXIT TERM
+			if [ -d $DEPLOY_DIR ];then
+				echo -e "$HEADER Changing to deploy directory: $DEPLOY_DIR ..."		
+				cd $DEPLOY_DIR	
+			else
+				echo -e "$HEADER Creating deploy directory: $DEPLOY_DIR ..." 
+				mkdir $DEPLOY_DIR
+				echo -e "$HEADER   -->> changing to $DEPLOY_DIR ..."
+				cd $DEPLOY_DIR
+			fi
+			
+			if [ -e $LOG ];then
+				echo -e "$HEADER Log file exists. Backing up the file ..."
+				mv $LOG $LOG.`date +%d.%m.%Y-%H.%M.%s`
+			fi
 
-TIMER=0
-if [ -e /tmp/mosaic-netup ];then
-	NET_UP=1
-else
-	while [ ! -e /tmp/mosaic-netup ];
-	do
-		echo -n -e "\r$HEADER Waiting for the network to come up ... [${TIMER} sec(s)] <<---"
-		let TIMER=TIMER+1
-		sleep 1
-		if [ ${TIMER} -gt 20 ];then
-			NET_UP=0
+			echo -e "$HEADER"
+			
+			TIMER=0
+			if [ -e /tmp/mosaic-netup ];then
+				NET_UP=1
+			else
+				while [ ! -e /tmp/mosaic-netup ];
+				do
+					echo -n -e "\r$HEADER Waiting for the network to come up ... [${TIMER} sec(s)] <<---"
+					let TIMER=TIMER+1
+					sleep 1
+					if [ ${TIMER} -gt 20 ];then
+						NET_UP=0
+						echo
+						break
+					fi
+					NET_UP=1
+					echo
+				done
+			fi
+			
+			zeroconf_update
+			
+			COUNTER=0
+			if [ $NET_UP -eq 1 -a "$testbed" == "no" ];then
+				while [ $COUNTER -lt 5 ];do
+					echo -n -e "\r$HEADER zeroconf: Trying if ${zeroconf_ip} is UP! [${COUNTER} time(s)] ..."
+					user_ssh_pubkey_add > /dev/null 2>&1
+				    if ! grep -q 'ssh-' /root/.ssh/authorized_keys;then
+				    	echo -n -e "\r$HEADER zeroconf: ${zeroconf_ip} is not up ... retrying ...                  " 
+				        let COUNTER=COUNTER+1
+				        NET_UP=0
+				        sleep 2
+				     else
+				     	echo -n -e "\r$HEADER zeroconf: ${zeroconf_ip} is up ... step over ...                     "
+				       	COUNTER=5
+				        NET_UP=1
+				     fi
+				done
+			fi
+			
 			echo
-			break
-		fi
-		NET_UP=1
-		echo
-	done
-fi
+			echo -e "$HEADER Applying mOS customizations ..."	
+			
+			pkg_daemon
+			
+			if [ ! -e /etc/mOS-installed ];then
+				echo -e "$HEADER First boot ... setting up mOS customizations ..." | tee -a $LOG
+				mosaic_repo_add
+				if [ $NET_UP -eq 1 -a $service_node == "no" ];then
+					echo -e "$HEADER Updating mOS data ..." | tee -a $LOG
+					if [ "$testbed" == "yes" ];then
+						regsrv_add_host
+					else
+						regsrv_add_host_cloud
+					fi
+					#user_ssh_pubkey_add
+					user_data_script
+				fi
+				# Mark HDD as being installed ...
+				echo "mOS-0.7" >/etc/mOS-installed
+			else
+				if [ $NET_UP -eq 1 -a $service_node == "no" ];then
+						echo -e "$HEADER Updating mOS data ..." | tee -a $LOG
+						#user_ssh_pubkey_add
+						user_data_script
+				fi
+			fi
+			echo -e "$HEADER"
+			echo -e "$HEADER Resuming mOS services startup ..." | tee -a $LOG
+			echo
+        ;;
+       	stop)
+      		echo -e "$HEADER stopping mosaic services ..."
+        ;;
+       	*)
+               	echo "Usage: $0 [start|stop]";
+               	exit 0;
+               	;;
+esac
 
-zeroconf_update
-
-COUNTER=0
-if [ $NET_UP -eq 1 -a "$testbed" == "no" ];then
-	while [ $COUNTER -lt 5 ];do
-		echo -n -e "\r$HEADER zeroconf: Trying if ${zeroconf_ip} is UP! [${COUNTER} time(s)] ..."
-		user_ssh_pubkey_add > /dev/null 2>&1
-	    if ! grep -q 'ssh-' /root/.ssh/authorized_keys;then
-	    	echo -n -e "\r$HEADER zeroconf: ${zeroconf_ip} is not up ... retrying ...                  " 
-	        let COUNTER=COUNTER+1
-	        NET_UP=0
-	        sleep 2
-	     else
-	     	echo -n -e "\r$HEADER zeroconf: ${zeroconf_ip} is up ... step over ...                     "
-	       	COUNTER=5
-	        NET_UP=1
-	     fi
-	done
-fi
-
-echo
-echo -e "$HEADER Applying mOS customizations ..."	
-
-pkg_daemon
-
-if [ ! -e /etc/mOS-installed ];then
-	echo -e "$HEADER First boot ... setting up mOS customizations ..." | tee -a $LOG
-	mosaic_repo_add
-	if [ $NET_UP -eq 1 -a $service_node == "no" ];then
-		echo -e "$HEADER Updating mOS data ..." | tee -a $LOG
-		if [ "$testbed" == "yes" ];then
-			regsrv_add_host
-		else
-			regsrv_add_host_cloud
-		fi
-		#user_ssh_pubkey_add
-		user_data_script
-	fi
-	# Mark HDD as being installed ...
-	echo "mOS-0.7" >/etc/mOS-installed
-else
-	if [ $NET_UP -eq 1 -a $service_node == "no" ];then
-			echo -e "$HEADER Updating mOS data ..." | tee -a $LOG
-			#user_ssh_pubkey_add
-			user_data_script
-	fi
-fi
-echo -e "$HEADER"
-echo -e "$HEADER Resuming mOS services startup ..." | tee -a $LOG
-echo

recipes/mosaic-mos/stuff/mosaic/bin/run-pkg-daemon

 
 work_dir=/opt/mosaic/bin
 
-trap 'echo "trapped!"; _run=1' INT TERM EXIT
-
 _run=0
-
-sleep 15
-
 while [ ${_run} -eq 0 ];do
-	nc -l -p 19999 -e ${work_dir}/run-pkg-add
-done
+	nc -l -p 19999 -e ${work_dir}/run-pkg-add > /dev/null 2>&1
+	if [ $? -ne 0 ];then
+		_run=1
+	fi
+done