Created
July 18, 2012 13:13
-
-
Save bonyiii/3136142 to your computer and use it in GitHub Desktop.
checking if a process is running
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://github.com/javan/whenever/ | |
##### Check if a process is running or not | |
#!/bin/bash | |
#http://stackoverflow.com/questions/9336596/rvm-installation-not-working-rvm-is-not-a-function | |
source ~/.rvm/scripts/rvm | |
# http://cazatech.wordpress.com/2007/07/07/shell-script-restart-process-if-not-found-running/ | |
ps x -o pid,pgid,args | grep -v 'grep' | grep 'whatever_task' | |
if [ $? -eq 1 ] | |
then | |
cd <work directory> && rvm use whatever_gemset && RAILS_ENV=development bundle exec rake whatewever_task >> <path_to_log_file> 2>&1 | |
else | |
echo 'Rake task runing' | |
fi | |
##### Kill process if runs | |
#!/bin/bash | |
pids=$(ps x -o pid,pgid,args | grep -v 'grep' | grep 'whatever_task' | cut -d' ' -f 1) | |
# http://www.cyberciti.biz/faq/finding-bash-shell-array-length-elements/ | |
if [ ${#pids} -eq 0 ] | |
then | |
echo "Nothing to kill!" | |
else | |
kill -INT $pids | |
echo 'Killing rake whatever_task' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment