Browse Source

first commit

Nicolo' Palazzini 5 years ago
parent
commit
6b6ffbdc31
2 changed files with 115 additions and 12 deletions
  1. 58 12
      functions
  2. 57 0
      sleepctl

+ 58 - 12
functions

@@ -1,6 +1,6 @@
 print_usage(){
 	echo
-	echo "script usage: $(basename $0) [-n node] [-a] [-1] [-2] [-h] " >&2
+	echo "script usage: $(basename $0) [-s node] [-k node] [-m] [-h] " >&2
 	echo "type: '$(basename $0) -h' for help"
 	return 0
 }
@@ -10,10 +10,9 @@ print_help(){
 	echo "$(basename $0): a useless script"
 	echo
 	echo "options:"
-	echo "  -n Print the hostname of the specified node"
-	echo "  -a Print the hostname of all nodes"
-	echo "  -1 Print the hostname of all nodes in LCM1"
-	echo "  -2 Print the hostname of all nodes in LCM2"
+	echo "  -s <node>  Start the service on the specified node"
+	echo "  -k <node>  Kill the service on the specified node"
+	echo "  -m  Monitor function: display all the nodes on which the service is runnig"
 	echo "  -h  Print this help message"
 	command_parsed=1
 
@@ -21,27 +20,74 @@ print_help(){
 	return 0
 }
 
-call_node(){
-	printf "$1 says: "
-	ssh $1 'hostname' #come si fa a non mostrare il messaggio?
+start_node(){
 	
+	ssh $1 'sleep 300 &> /dev/null &' #come si fa a non mostrare il messaggio?
+	echo "Service started on $1"
 		
 	command_parsed=1
 
 }
 
-call_1(){
+start_1(){
 	for i in {0..12}
 		do
-  	 		call_node ${LCM1[i]}
+  	 		start_node ${LCM1[i]}
 		done
 	command_parsed=1
 }
 
-call_2(){
+start_2(){
 	for i in {0..14}
 		do
-			call_node ${LCM2[i]}
+			start_node ${LCM2[i]}
 		done
 	command_parsed=1	
 }
+
+monitor(){
+
+	echo "Service running on:"
+	for i in {0..12}
+		do
+			#printf "${LCM1[i]}: "
+ 	 		ssh ${LCM1[i]} 'ps aux | grep "sleep 300" | grep -v grep' > /dev/null
+			if [ $? -eq 0 ]; then
+				echo ${LCM1[i]}
+			fi
+		done
+	for i in {0..14}
+		do
+			ssh ${LCM2[i]} 'ps aux | grep "sleep 300" | grep -v grep' > /dev/null
+			if [ $? -eq 0 ]; then
+				echo ${LCM1[i]}
+			fi
+		done
+
+	command_parsed=1
+
+}
+
+kill_process(){
+	
+	ssh $1 'pkill sleep' #pericoloso (testato e funzionante con pkill xfreerdp)
+
+	command_parsed=1
+
+}
+
+kill_1(){
+	for i in {0..12}
+		do
+			kill_process ${LCM1[i]}
+		done
+
+}
+
+kill_2(){
+	for i in {0..14}
+		do
+			kill_process ${LCM2[i]}
+		done
+
+}

+ 57 - 0
sleepctl

@@ -0,0 +1,57 @@
+#!/bin/bash
+
+#set -e #problemi con la funzione monitor! DOCUMENTARSI!!!!!
+set -u
+set -o pipefail
+
+command_parsed=0
+
+. functions
+. conf
+
+while getopts 'hms:k:' OPTION; do
+  case "$OPTION" in
+
+    m) #monitor
+		monitor
+		;;
+	s) #start
+		node=$OPTARG
+		if [ $node == '1' ];then
+  			start_1
+		elif [ $node == '2' ];then
+			start_2
+		else
+  		 	start_node $node
+		fi
+		;;
+	k)  #kill
+		node=$OPTARG
+		if [ $node == '1' ];then
+  			kill_1
+		elif [ $node == '2' ];then
+			kill_2
+		else
+  		 	kill_process $node
+		fi
+		;;
+	h)
+		print_help      
+		;;
+    ?)
+		print_usage
+		exit 1
+ 		command_parsed=1
+	    ;;
+    :)
+      	echo "cosa fa?"
+      	;;
+  esac
+done
+
+if [ $command_parsed -eq 0 ]
+then
+    print_usage
+fi
+
+#shift "$(($OPTIND -1))"