Skip to content

Instantly share code, notes, and snippets.

@bdtomlin
Created July 5, 2010 20:57
Show Gist options
  • Save bdtomlin/464680 to your computer and use it in GitHub Desktop.
Save bdtomlin/464680 to your computer and use it in GitHub Desktop.
mongod ruby script
#!/usr/bin/env ruby
USAGE = %{
Usage:
Put this script somewhere in your path, I use ~/bin
chmod +x to make it executable
mongod start (starts mongod)
mongod stop (stops mongod)
mongod stat (calls ps aux|grep ... to see if mongod is running)
}
def pid
File.read('/data/db/mongod.lock').chomp
end
def start
begin
if pid.length > 1
raise "mongod appears to be running with pid #{pid}"
else
exec '/data/mongodb/bin/mongod --fork --logpath /data/log/mongo.log'
end
rescue Exception => e
puts e
end
end
def stop
exec "kill #{pid}"
end
def stat
puts "mongod pid: #{pid}"
exec "ps aux |grep /bin/mongod|grep -v grep"
end
if %w{start stop stat}.include?(ARGV.first)
send ARGV.first
else
puts USAGE
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment