Skip to content

Instantly share code, notes, and snippets.

@schatteleyn
Forked from davidcornu/manager.rb
Created March 8, 2012 22:02
Show Gist options
  • Save schatteleyn/2003752 to your computer and use it in GitHub Desktop.
Save schatteleyn/2003752 to your computer and use it in GitHub Desktop.
Convenient command line methods
/usr/bin/ruby /Users/schatteleyn/manager.rb $1 $2 $3 $4 $5
# SYSTEM ===================================
if ARGV[0] == "flushdns"
puts "Flushing DNS Cache"
@command = "sudo dscacheutil -flushcache"
# REDIS ====================================
elsif ARGV[0] == "redis"
if ARGV[1] == "start"
puts "Starting Redis"
@command = "nohup redis-server > /dev/null &"
elsif ARGV[1] == "stop"
puts "Stopping Redis"
@command = "kill `pidof redis-server`"
end
# ELASTIC SEARCH ===========================
if ARGV[1] == "start"
puts ">> Starting Elastic Search"
@command = "elasticsearch -D es.config=/usr/local/Cellar/elasticsearch/0.19.0/config/elasticsearch.yml -D es.pidfile=/usr/local/var/run/elasticsearch.pid"
elsif ARGV[1] == 'stop'
puts '>> Stopping Elastic Search'
@command = "kill `cat /usr/local/var/run/elasticsearch.pid`"
end
# SIMPLE HTTP ==============================
elsif ARGV[0] == "serve"
puts "Starting Python HTTP Server"
@command = "python -m SimpleHTTPServer"
# MYSQL ====================================
elsif ARGV[0] == "mysql"
if ARGV[1] == "start"
@command = "mysql.server start"
elsif ARGV[1] == "stop"
@command = "mysql.server stop"
end
# APACHE ===================================
elsif ARGV[0] == "ap"
if ARGV[1] == "start"
puts "Starting Apache"
@command = "sudo apachectl start"
elsif ARGV[1] == "stop"
puts "Shutting Down Apache"
@command = "sudo apachectl stop"
elsif ARGV[1] == "restart"
puts "Restarting Apache"
@command = "sudo apachectl restart"
end
end
if @command
if system @command
puts "Done!"
else
puts "Error!"
end
else
puts "Unknown Command!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment