Subversion Repositories My Stuff

Rev

View as "text/plain" | Blame | Last modification | View Log | RSS feed

#! /bin/bash

TEMPFILE=/tmp/screenlets.running.${USER}.tmp

if [ "${1}" = "stop" ]; then
        #Wrtie all curently running screnlets to temp file excluding screenlets deamon and manager

        ps aux | grep ${USER} | grep python | grep screenlets | sed '/screenlets-daemon.py/d; /screenlets-manager.py/d' | \
        awk '{printf $2","; n=10;while(++n<NF) printf $n " "; printf "%s\n",$NF}'> ${TEMPFILE}

        #Read all file lines and close all running screenlets

        echo "I'm closing all running screenlets"
        while read line
        do
                PID=$(echo $line | awk -F, '{print $1}')
                kill -9 $PID
        done < ${TEMPFILE}

elif [ "${1}" = "start" ]; then
        #Check if the temporary file exists
       
        if (test -r ${TEMPFILE}) then

                #Read the temporary file and lunch screenlets using their lunching cammand
               
                echo "Starting screelets using a temporary list file"
                while read line
                do
                        COMMAND=$(echo $line | awk -F, '{print $2}')
                        $COMMAND &> /dev/null &
                        sleep 10
                done < ${TEMPFILE}

                #Removing the temporary file

                rm ${TEMPFILE}

        else
                echo "Seems there is no temp file or you have no rights to access it"
        fi
else
        echo "Usage ./screnlets-restart.sh start | stop"
fi