Skip to content

Instantly share code, notes, and snippets.

View blasterpal's full-sized avatar

Hank Beaver blasterpal

View GitHub Profile
@blasterpal
blasterpal / check_process_on_all_ey_serverssh
Created October 17, 2012 15:23
Run something on all EY servers
CMD="ps -ef | grep resque | grep -v grep"
for R_E in production staging demo
do
echo "${R_E}"
ey ssh "${CMD}" -e ${R_E} --utilities=utility
echo "${R_E}"
echo "-------------------------------"
done
@blasterpal
blasterpal / thread_dump_sidekiq.sh
Created October 9, 2012 15:25
Thread dump all Sidekiq processes
ps -ef | grep sidek | grep -v grep | cut -c10-14 | grep -v tail| xargs kill -TTIN
@blasterpal
blasterpal / pull_db_backup_ey2.rb
Created October 4, 2012 14:52
Pull DB Backup from Engine Yard Ver 2
#This version is non-interactive. Just put in your bucket in file in same dir.
bucket = `cat prodbucket.txt`.strip
list = `sudo /usr/local/ey_resin/bin/eybackup -l BAM -e mysql -b #{bucket}`
#puts list.split("\n")
#exit
latest_file = list.split('\n').first.split("\n").select{|ea| ea =~ /^[0-9]*:/}.last
latest_index = latest_file.split(":").first
puts "Downloading #{latest_file}"
`sudo /usr/local/ey_resin/bin/eybackup -e mysql -d #{latest_index}:BAM -b #{bucket}`
@blasterpal
blasterpal / backup_sidekiq_queues.rb
Created October 4, 2012 14:32
Backup Sidekiq queue entries to disk
@conn = Sidekiq.redis {|conn| @conn = conn}
@conn.smembers('queues').each {|q|
File.open("/home/rails/#{q}_sidekiq.dump",'w') {|f|
l = @conn.lrange("queue:#{q}",0,-1)
f << l
}
}
@blasterpal
blasterpal / pull_ey_db_backup.rb
Created September 27, 2012 19:04
Fetch a DB Backup from another server on EY
#!/usr/bin/ruby
if ARGV.size < 1
puts "you need to supply bucket"
exit
end
bucket = ARGV[1]
puts "fetching list of prod backups"
list = `sudo /usr/local/ey_resin/bin/eybackup -l BAM -e mysql -b #{bucket}`
puts list.split("\n")
latest_file = list.split('\n').first.split("\n").select{|ea| ea =~ /^[0-9]*:/}.last
@blasterpal
blasterpal / hash_recursive_count.rb
Created September 25, 2012 23:56
Recursively count all keys or do something with a hash
def self.counth(thehash,count=0)
count += thehash.keys.size if thehash.is_a? Hash
thehash.keys.each do |key|
if thehash[key].is_a? Hash
count = counth(thehash[key],count)
end
end
count
end
@blasterpal
blasterpal / mysql_grant.sql
Created September 5, 2012 17:49
Create mysql user with specific permissions
CREATE USER 'joe'@'%' IDENTIFIED BY 'xxxxxx';
# ALL PRIVILEGES is everything except grant
GRANT ALL PRIVILEGES ON APP_production_temp.* TO 'joe'@'%';
GRANT SELECT ON APP_production.* TO 'joe'@'%';
GRANT SELECT ON stats_production.* TO 'joe'@'%';
@blasterpal
blasterpal / uuid_file_search.sh
Created August 28, 2012 14:42
Search for UUID files or directories
ls | egrep -e '^[a-z0-9]{8}-.*'
@blasterpal
blasterpal / test_for_command_shell.sh
Created August 28, 2012 13:46
Test if command exists and echo status code
type redis-cli > /dev/null 2>&1 ; echo $?
# used in python like so:
# IS_REDIS_SERVER = int(commands.getoutput("type redis-cli > /dev/null 2>&1 ; echo $?")) == 0
@blasterpal
blasterpal / ps.sh
Created July 19, 2012 15:10
PS Commands galore
#Forking view of ps
ps axjf
# inspect a single process
ps -p 20673 -F