Created
July 5, 2010 20:57
-
-
Save bdtomlin/464680 to your computer and use it in GitHub Desktop.
mongod ruby script
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
#!/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