Skip to content

Instantly share code, notes, and snippets.

@raygunsix
Last active September 16, 2016 21:17
Show Gist options
  • Save raygunsix/5144690 to your computer and use it in GitHub Desktop.
Save raygunsix/5144690 to your computer and use it in GitHub Desktop.

Useful Commands

Remove all docker containers and images

# Stop all containers
docker stop $(docker ps -a -q)
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)

Run chef-solo in vagrant vm

chef-solo -c /tmp/vagrant-chef-1/solo.rb -j /tmp/vagrant-chef-3/dna.json

Run chef-shell in solo mode

chef-shell -s -c /tmp/vagrant-chef-3/solo.rb -j /tmp/vagrant-chef-3/dna.json

Show encrypted data bag item

knife data bag show --editor=/usr/bin/vim --secret-file=../../.chef/encrypted_data_bag_secret secrets ITEM

Mysql backup / restore

backup: mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql

restore: mysql -u root -p[root_password] [database_name] < dumpfilename.sql

sass generate

RAILS_ENV=qa nohup bundle exec rake sass:generate &

copy s3 bucket

RAILS_ENV=qa nohup bundle exec rake fog_s3_copy[from-bucket,to-bucket,access_key_id,secret_access_key] &

passenger tools

/usr/sbin/passenger-status
/usr/sbin/passenger-memory-stats

scp to vagrant vm

scp -P 2222 -i .vagrant/machines/default/virtualbox/private_key file vagrant@localhost:/tmp

scp to boot2docker

scp -i ~/.ssh/id_boot2docker -P 2022 file-to-upload docker@localhost:~

Switch ruby on EY Managed

sudo eselect ruby set ruby19 && sudo /etc/init.d/nginx restart

Sphinx

Find search errors in rails log:

grep -C 10 "search" production.log | grep -C 50 "Completed 500 Internal Server Error"

Disk space

To find the largest 10 files (linux/bash):

find . -type f -print0 | xargs -0 du -s | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}

To find the largest 10 directories:

find . -type d -print0 | xargs -0 du -s | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}

Show swap usage by process

Run top then press 'O' (capital letter o) followed by 'p' then 'enter'

Install ruby 2.0 using rbenv

CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl`" rbenv install 2.0.0-p353

Clean up pid space while debugging upstart scripts

http://www.markhneedham.com/blog/2012/09/29/upstart-job-getting-stuck-in-the-startkilled-state/

Dump and restore chef node

knife node show NODE_NAME -F json > NODE_NAME.json
knife node from file NODE_NAME.json

Basic ceph operations

#!/usr/bin/env python

import boto
import boto.s3.connection
access_key = ''
secret_key = ''
bucket_name = ''
host = ''

conn = boto.connect_s3( 
    aws_access_key_id = access_key,
    aws_secret_access_key = secret_key,
    host = host,
    #is_secure=False,               # uncommmnt if you are not using ssl
    calling_format = boto.s3.connection.OrdinaryCallingFormat(),
)

#newbucket = conn.create_bucket(bucket_name)

for bucket in conn.get_all_buckets():
    print "{name}\t{created}".format(
        name = bucket.name,
        created = bucket.creation_date,
    )

#bucket = conn.get_bucket(bucket_name)
#key = bucket.new_key('hello.txt')
#key.set_contents_from_string('Hello World!')

for key in bucket.list():
    print "{name}\t{size}\t{modified}".format(
      name = key.name,
      size = key.size,
      modified = key.last_modified,
    )

List available azure Ubuntu VM images

azure vm image list canadacentral canonical ubuntuserver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment