Skip to content

Instantly share code, notes, and snippets.

@oneman
Created September 7, 2009 16:43
Show Gist options
  • Save oneman/182438 to your computer and use it in GitHub Desktop.
Save oneman/182438 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# This is a wrapper script for beanstalkd to drop a .pid file so it can be used by monitoring programs ( like monit )
# customise to your needs below
# usage: beanstalkd {start|stop} (chmod +x the file )
# assumed file is placed in RAILS_ROOT/script
#RAILS_ROOT = "#{File.dirname(__FILE__)}/.."
# your choice
pid_path = "/var/run/beanstalkd"
beanstalkd = "/usr/bin/beanstalkd"
beanstalkd_opts = "-d"
if ["start", "stop"].include? ARGV[0]
case ARGV[0]
when "start"
`#{beanstalkd} #{beanstalkd_opts}` # start beanstalkd
`pgrep -n beanstalkd > #{pid_path}/beanstalkd.pid` # push beanstalks pid to a file
when "stop"
`killall -9 beanstalkd` # works everytime
`rm #{pid_path}/beanstalkd.pid` # remove the pidfile
end
else
puts "usage: beanstalkd {start|stop}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment