Skip to content

Instantly share code, notes, and snippets.

@fronx
Created April 26, 2010 13:00
Show Gist options
  • Select an option

  • Save fronx/379294 to your computer and use it in GitHub Desktop.

Select an option

Save fronx/379294 to your computer and use it in GitHub Desktop.
def pid_path
"~/tmp/pid/"
end
def write_pid(name)
`echo "#{Process.pid}" > #{pid_path}#{name}.pid`
`echo "#{Process.ppid}" > #{pid_path}#{name}.ppid`
end
def delete_pid(name)
`rm -rf #{pid_path}#{name}.pid`
`rm -rf #{pid_path}#{name}.ppid`
end
def pid_task(*args, &block)
task *args do |t|
write_pid(t.name)
block.call
delete_pid(t.name)
end
end
namespace :foo do
pid_task :bar => :environment do
Bla.blub
end
end
#!/bin/bash
echo "${1} ${2}"
task=$1
cmd=$2
case $cmd in
start)
echo $$ > ~/tmp/pid/${task}.pid
rake ${task}
;;
stop)
kill `cat ~/tmp/pid/${task}.ppid`
kill `cat ~/tmp/pid/${task}.pid`
rm -rf ~/tmp/pid/${task}.*
;;
*)
echo "usage: rakectl.sh your:task {start|stop}" ;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment