Archive for the ‘ Administration ’ Category

Resetting a user’s password in Chef

Resetting a user’s password in Chef

reset-windows-password

This morning in someone had locked themselves out of their WebUI admin account, and wanted to know how to reset the password.

So long you have knife set up with an admin account locally, this should do the trick:

#!/usr/bin/ruby
 
unless ARGV[0] && ARGV[1]
  puts "Usage: set_password.rb username password"
  exit 1
end
 
require 'rubygems'
require 'chef'
require 'chef/config'
require 'chef/webui_user'
 
Chef::Config.from_file(File.expand_path("knife.rb"))
 
user = Chef::WebUIUser.load(ARGV[0])
if user
  user.set_password(ARGV[1])
  user.save
else
  puts "Could not find user #{ARGV[0]}."
  exit 2
end

Put it in a file, and then run ruby set_password.rb admin newpassword. If it doesn’t say anything, it worked.

via Resetting a user’s password in Chef | Blank Pad Development.

Poor Man’s Profiler

will profile for food

#!/bin/bash
nsamples=1
sleeptime=0
pid=$(pidof mysqld)
 
for x in $(seq 1 $nsamples)
  do
    gdb -ex "set pagination 0" -ex "thread apply all bt" -batch -p $pid
    sleep $sleeptime
  done | 
awk '
  BEGIN { s = ""; } 
  /Thread/ { print s; s = ""; } 
  /^#/ { if (s != "" ) { s = s "," $4} else { s = $4 } } 
  END { print s }' | 
sort | uniq -c | sort -r -n -k 1,1

poor man’s profiler.

SVN pre-commit hook

Stop

How to avoid system files in your repository

Today Operating systems are often creating system files to accelerate directory operations:

MacOSX: ‘.DS_Store’
Windows: ‘Thumbs.db’
KDE: ‘.directory’
….

To avoid that these files mess up your repository, create inside the 'hook' directory a file named: 'pre-commit' (beside a the example file ‘pre-commit.tmpl’).
It is very important to make sure that the script has execution rights ( chmod a+x pre-commit )

#!/bin/bash
 
REPOS="$1"
TXN="$2"
 
SVNLOOK=/usr/bin/svnlook
 
# Make sure that the log message contains some text.
$SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" > /dev/null
if [ $? -ne 0 ]; then
        echo "Log message not specified!" 1>&2
        exit 1
fi
 
# Do not commit crap like ...
CRAP_FILES=( '.DS_Store' 'Thumbs.db' '.directory' )
for FILE in $($SVNLOOK changed -t "$TXN" "$REPOS" | cut -b 5- | xargs basename); do
        for CRAP in "${CRAP_FILES[@]}"; do
                if [ "$FILE" = "$CRAP" ]; then
                        echo "Temporary files cannot be commited (ex: '.DS_Store', 'Thumbs.db')!" 1>&2
                        exit 1
                fi
        done
done
 
# All test passed
exit 0

Enjoy!