Skip to content

Instantly share code, notes, and snippets.

@davidcornu
Created March 8, 2012 22:00
Show Gist options
  • Save davidcornu/2003728 to your computer and use it in GitHub Desktop.
Save davidcornu/2003728 to your computer and use it in GitHub Desktop.
Convenient command line methods
/usr/bin/ruby /Users/davidcornu/manager.rb $1 $2 $3 $4 $5
# SYSTEM ===================================
if ARGV[0] == "flushdns"
puts "Flushing DNS Cache"
@command = "sudo dscacheutil -flushcache"
# SIMPLE HTTP ==============================
elsif ARGV[0] == "serve"
puts "Starting Python HTTP Server"
@command = "python -m SimpleHTTPServer"
# MEDIA SERVER =============================
elsif ARGV[0] == "ms"
if ARGV[1] == "start"
puts "Starting Media Server"
@command = "cd /Users/davidcornu/Development/artfox/media_server/; ./start.sh"
elsif ARGV[1] == "stop"
puts "Shutting Down Media Server"
@command = "cd /Users/davidcornu/Development/artfox/media_server/; ./stop.sh"
elsif ARGV[1] == "update"
puts "Updating Media Server"
@command = "cd /Users/davidcornu/Development/artfox/media_server/; ./update.sh"
end
# MYSQL ====================================
elsif ARGV[0] == "mysql"
if ARGV[1] == "start"
@command = "mysql.server start"
elsif ARGV[1] == "stop"
@command = "mysql.server stop"
end
# 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 ===========================
elsif ARGV[0] == "elastic"
if ARGV[1] == "run"
puts "Starting Elastic Search"
@command = "elasticsearch -f -D es.config=/usr/local/Cellar/elasticsearch/0.18.7/config/elasticsearch.yml"
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
@davidcornu
Copy link
Author

Second file lives in /usr/local/bin/dav and needs to be chmod +x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment