$ command line ruby cheat sheets
Cheat Sheet Title: [ no_spaces_alphanumeric_only ]
Cheat Sheet:============================ # the ethnio admin cheat sheet; use it with cheat for optimal happiness: http://errtheblog.com/posts/32-cheat-again # version 3.0 by maintainer chris blow august 11, 2008 # 919 763 5299 is my mothers phone number # tell her if wrote something wrong and you are sore about it. # otherwise please add yer notes and send it back to me! = ============================ # NOTE: if you see a bug please file it here for now # NOTE: if you fix a bug write it down # NOTE: do not put passwords in this file ============================================== = BUGS & todos = ============================================== BUG: filters break the recruits table. (Per-incident patch - login with mysql and ------ update screeners set filters=NULL where remote_key =12345; ) BUG: some js problems with reordering questions. Not reproducible reliably. (Per incident patch: blame it on Mozilla or Microsoft) BUG: mongrel_restart is broken. BUG: BUG: BUG: ... add em please TODO: upgrade rails 1.3 is out and fixes mongrel_restart bug. we should upgrade soon. Also might fix caching extension bug. BUG FIXED 08/11: logrotate bug. Logs were not getting rotated correctly because mongrel was not being restarted. Also an unnecessary rake log:clear needed to be removed. Used copytruncate instead. updated the logrotate section with what we are now using (correct per rimuhost techs). BUG FIXED 08/11: The last page of the screener displays as plaintext js. This was being caused by apache not handling the POST to the remotes/12345 url (which serves js with a GET using rails REST magic). the fix, in the ethnio.conf: RewriteCond %{REQUEST_METHOD} POST RewriteRule ^/(.*)$ balancer://ethnio_production_cluster%{REQUEST_URI} [P,QSA,L] =============================================== = IN CASE OF EMERGENCY = =============================================== ###### worst case scenario # The worst thing that can happen is that ethnio is not down but it is not serving files. # That is, apache is up, but mongrel is down. # You must either stop apache, or (much better) turn off traffic politely with capistrano. #TODO ==================================================== = specs = ==================================================== current specs: apache 2.2 4 instances of mongrel 1.0 ruby 1.8.6 rails 2.02 mysql 5.0.22 apache 2.2. installation configuration: ./configure --prefix=/usr/local/apache2 --enable-mods-shared=all \ --enable-deflate --enable-proxy --enable-proxy-balancer \ --enable-proxy-http --enable-ssl --with-axps2 ================================================= = logrotate = ================================================= #### this is the latest logrotate using copytruncate instead of stupid postrotate stuff /u/apps/ethnio/shared/log/production.log { weekly missingok rotate 8 compress notifempty # postrotate # cd /u/apps/ethnio/current&& rake log:clear # endscript copytruncate } ============================================ = Cruise Control and the CC box = ============================================ #TODO ============================================ = performance = ============================================ ########## all-purpose performance lookup curl -w '\nlookup time:\t%{time_namelookup}\nconnect time:\t%{time_connect}\nprexfer time:\t%{time_pretransfer}\nstartxfer time:\t%{time_starttransfer}\n\ntotal time:\t%{time_total}\n' -o /dev/null http://ethniodev.com/remotes/17436 ########## check the number of apache clients: pgrep -c httpd (should be well less than the max set in the relevant conf) ########## check memory: free -m #(the cached amount should be at least 500, its measured in mb) ########## benchmark (best done from the local machine) ab -n 5000 -c 50 http://ethnio.com/remotes/30090 # (reqs. per second should be like 800 or something big like that) ########## using profiler (easy but often unintelligible imo) script/performance/profiler 'screener.find_by_id(1).filtered_recruits' ########## using benchmarker # make sure you first set the environment var. export rails_perf_data=/path/to/ethnio's/log/directory #run everything railsbench perf_run 10 #also see railsbench perf_run 10 -bm=remotes.edit --log #and edit /config/benchmarks.rb /config/benchmarks.yml =============================================== = subversion = =============================================== ######### checkout svn co http://ethnio.textdriven.com/svn/ethnio/trunk . ######### branching svn copy http://ethnio.textdriven.com/svn/ethnio/branches/filter-stable http://ethnio.textdriven.com/svn/ethnio/tags/filters-stable-latest ########## tagging svn copy http://ethnio.textdriven.com/svn/ethnio/trunk http://ethnio.textdriven.com/svn/ethnio/tags/latest-stable ####### adding a new subversion user (gets fucked up a lot) # 1. cd to the domain’s etc/ directory # 2. with any text editor, edit ‘svn-access.conf’ by adding a ‘permission line’ for ‘newuser’ to an existing repository (repositories are created in webmin # 3. add a password for ‘newuser’ to the svn.basic.passwd file with htpasswd svn.basic.passwd newuser ####### editing an existing user’s password # 1. cd to the domain’s etc/ directory # 2. edit the user’s password with htpasswd svn.basic.passwd existinguser ########## editing an existing user’s permissions 1. cd to the domain’s etc/ directory 2. edit the existing user’s permission line in the correct repository in ‘svn-access.conf’ (with any text editor) ######### removing a user 1. cd to the domain’s etc/ directory 2. remove the user’s permission line from the ‘svn-access.conf’ file (with any text editor) 3. remove the user’s password line from the ‘svn.basic.passwd’ file (with any text editor) ======================================= = trac = ======================================= # TODO: As of August 2008 something is wrong with trac permissions and CGB cant get in. CGB hasn't spent too much time on it and frequently takes the stupidly lazy route of just taking down the .htaccess file when he needs to get in. Emphasis on stupid. ########## totally useless fragmentary notes on this problem #rewriteengine on #rewriterule ethnio(.*) http://ethnio.textdriven.com:9046/ethnio$1 [p] authtype basic authname "ethnio" authuserfile /users/home/ethnio/trac.htpasswd require valid-user [ethnio@alberni ~/etc]$ htdigest trac.digest.passwd ethnio.textdriven.com chris adding user chris in realm ethnio.textdriven.com new password: re-type new password: [ethnio@alberni ~/etc]$ pwd /users/home/ethnio/etc http://manuals.textdrive.com/read/chapter/54 =========================================== = imagemagick = =========================================== # TODO: we no longer use imagemagick for graphs, just for logo resizing, so that should be changed to minimagick or a smaller lib. ###### installing imagemagick (is a bear.) #uninstall and reinstall everything as per #http://www.elctech.com/2007/2/24/installing-rmagick-properly-in-osx #might also need to uninstall and clean libiconv: sudo port -f uninstall libiconv && sudo port clean --all libiconv && sudo port install libiconv ======================================= = svn = ======================================= ##### property seting svn propset svn:ignore "*" public/assets svn propset svn:ignore "assets" public svn ci public #### compare two remote builds: svn diff http://ethnio.textdriven.com/svn/ethnio/tags/filters-stable-caching-fix2 http://ethnio.textdriven.com/svn/ethnio/branches/filters-stable ##### create a tag cd /working/dir svn copy . http://ethnio.textdriven.com/svn/ethnio/tags/tagname ###### create a branch cd /working/dir svn copy . http://ethnio.textdriven.com/svn/ethnio/branches/branchname # you can add -r right after copy to specify a revision. ================================================== = selenium = ================================================== # to run selenium tests locally ruby test/selenium/selenium_suite.rb # if your server is not started rake selenium:start_servant # when you are getting 500 errors you just need to start the selenium server rake selenium:server #look at /log/test.log and log/selenum.log and you very well might need to rake db:setup #to apply migrations to the test db. ========================================================== = piston = ========================================================== ###### create a local modifiable/updateable copy of a plugin. # you want to do this instead of just using svn externals # everything in ethnio should be pistonized # http://piston.rubyforge.org/ piston import svn:#address /vendor/plugins/pluginname ========================================================== = textdrive = ========================================================== https:#webmin.alberni.textdrive.com/ ethnio eT..... ==================================================== = -------------------- rails -------------------- = ==================================================== ####### rails debugging # using the logger in a controller logger.debug(" ------------ #{params[:screener]}") if params[:screener] logger.debug(" ------------ #{params[:screener][:active]}") end logger.debug(" ------------ #{@screener.active}") ####### rails logs # the important ones are in # # /usr/local/apache2/logs (apache) # and in # /u/apps/ethnio/shared/log (the rest of the rails stack) # # also, some shortcuts: watchethnio # gives you tail -f on the production log watchapache # gives you the apache production log watcherrors # gives you the apache errors log. ==================================================== = -------------------- mysql -------------------- = ==================================================== # starting mysql on osx sudo /usr/local/mysql/bin/mysqld_safe #starting on ethnio.com /etc/init.d/mysql start #stopping /etc/init.d/mysql stop #loggin in mysql -uroot -p 1978.......w! ==================================================== = -------------------- mongrel -------------------- = ==================================================== # start mongrel_rails cluster::start -C /u/apps/ethnio/current/config/mongrel/production/mongrel_cluster.yml #no sudo? CGB 08/08 # stop mongrel_rails cluster::stop -C /u/apps/ethnio/current/config/mongrel/production/mongrel_cluster.yml #the old way (above seems to work better, but it's mongrel so im keeping these handy) sudo /etc/init.d/mongrel_cluster stop sudo /etc/init.d/mongrel_cluster start ==================================================== = -------------------- apache -------------------- = ==================================================== ###### tailing the production log sudo tail -f /usr/local/apache2/logs/ethnio_production.log # always use the sudo /etc/init.d/apache2 stop && sudo /etc/init.d/apache2 start # for apache2.2, which is what were running. #do not use apache2ctl reload (thats the wrong version) # editing the apache cong sudo vi /usr/local/apache2/conf/httpd.conf ==================================================== = -------------------- misc CLI -------------------- = ==================================================== ######## making up some self-signed certs openssl genrsa -out www.mycompany.com.key 2048 openssl req -new -x509 -key ethnio.textdriven.com.key -out ethnio.textdriven.com.cr ######### corey port forwarding insanity # just deduce it: ssh -l 9999:127.0.0.1:5900 -l 9998:127.0.0.1:548 -p123 ethnio@pedro.redirectme.net ####### copy robots.txt into every subdir # (be careful with find it will fuck your box up fast!) find -type d -exec cp /robots.txt {} \; ####### do remove a file everywhere. find -name "robots.txt" -exec rm {} \; ####### kill all procs containing 'selenium' (excepting grep): ps aux | grep selenium | sed /grep/d | awk {'print $2'} | xargs kill ######### public private keypairs # read the entire recipe before you start cookin, son #create a key and dont use a password ssh-keygen -t rsa #now scp that mother to the machine scp .ssh/id_rsa.pub ethnio@ethniodev.com:.ssh/authorized_keys2 #but in this case actually that last line will overwrite an existing key, instead just cat ssh/id_rsa.pub and paste the output into .ssh/authorized_keys2 on ethniodev.com thanks. #now good gracious me add this to bash profile for the joy alias ethnio='ssh ethnio@ethniodev.com' ======================================= = monitors = ======================================= CGB has written a few monitor and maint scripts that live in ~/monitors. Now you know. ========================================= = cron = ========================================= #the root crontab sudo crontab -e #system daily/weekly/monthly crons ls /etc/cron/* ======================================= = cap = ======================================= ###### deploy head to demo cap demo deploy -s head=true ###### handy-ass trick to run a command on the machine cap demo invoke command="ls" -s tag=whatever ######### deploying cap production deploy -S head=true #always deploy from a tag, look up the last (automatically created) tag in Cruise Control, like so: cap production deploy -S tag='ethnio-********-ci' #tags look like this: ethnio-20080105023744-ci and you can find them by clicking on browse source in trac ######### turning off traffic politely # => puts the maintenance page in place, apache sends it all traffic # note that head=true isnt used in this case, just needs to be there. cap production deploy:web:disable -s head=true cap production deploy:web:enable -s head=true ####### restarting the application. # from your development machine cap production deploy:restart -s tag=*******
Your cheat sheet will be editable (fixable) by anyone. Each cheat sheet is essentially a wiki page. It may also be used by millions of people for reference purposes from the comfort of their command line. If this is okay with you, please save.
Advertisement