Skip to content

Instantly share code, notes, and snippets.

@bonyiii
Created July 18, 2012 13:13
Show Gist options
  • Save bonyiii/3136142 to your computer and use it in GitHub Desktop.
Save bonyiii/3136142 to your computer and use it in GitHub Desktop.
checking if a process is running
#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