среда, 17 апреля 2013 г.

autoexpect

Expect - tool for automatically run interactive scripts.
Autoexpect - tool for generate expect script.
Generated code is dirty, but working, It will save many hours.
Example:

autoexpect ssh root@192.168.122.240


work with script, after logout you receive script.exp which contain

 set timeout -1
spawn ssh root@192.168.122.240
match_max 100000
expect -exact "Warning: Permanently added '192.168.122.240' (RSA) to the list of known hosts.\r\r
root@192.168.122.240's password: "
send -- "testpass\r"
expect -exact "\r
Permission denied, please try again.\r\r
root@192.168.122.240's password: "
send -- "vagrant\r"
expect -exact "\r
Last login: Mon Mar 25 21:38:15 2013\r\r
^[\]0;root@centos64:~^G^[\[?1034h\[root@centos64 ~\]# "
send -- "uname -a\r"
expect -exact "uname -a\r
Linux centos64.vagrantup.com 2.6.32-358.el6.x86_64 #1 SMP Fri Feb 22 00:31:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux\r
^[\]0;root@centos64:~^G\[root@centos64 ~\]# "
send -- "touch /tmp/123\r"
expect -exact "touch /tmp/123\r
^[\]0;root@centos64:~^G\[root@centos64 ~\]# "
send -- "exit\r"
expect eof

воскресенье, 14 апреля 2013 г.

pre-commit hooks for checking commits

there are examples for ruby code and puppet manifests(chef can validate automatically, but stupid puppet can't):
1. create file ./.git/hooks/pre-commit
2. add code

#!/bin/sh
echo 'working pre commit hook'
git diff --cached --name-only --diff-filter=ACM | while read file; do
  # check only puppet files
  if [ "${file##*.}" == 'pp' ]
  then
    echo "check $file"
    puppet parser validate $file
  fi
done

3. require set exec permissions. DO NOT FORGET !!!! (it is cause for not execution hook)
chmod +x ./.git/hooks/pre-commit
Complete.

Also example for ruby:

#!/bin/sh
echo 'working pre commit hook'
git diff --cached --name-only --diff-filter=ACM | while read file; do
  if [ "${file##*.}" == 'rb' ]
  then
    echo "check rubocop $file"
    rubocop $file
  fi
done

воскресенье, 7 апреля 2013 г.

shmmax error for start postgresql

During start postgresql appear error  
Apr 07 12:38:55 localhost.localdomain pg_ctl[9810]: FATAL: could not create shared memory segment: Invalid argument 
Apr 07 12:38:55 localhost.localdomain pg_ctl[9810]: DETAIL: Failed system call was shmget(key=5432001, size=41279488, 03600). 
Apr 07 12:38:55 localhost.localdomain pg_ctl[9810]: HINT: This error usually means that PostgreSQL's request for a shared memory segment exceeded your ker...nections. 
Apr 07 12:38:55 localhost.localdomain pg_ctl[9810]: If the request size is already small, it's possible that it is less than your kernel's SHMMIN parameter...lled for. 
Apr 07 12:38:55 localhost.localdomain pg_ctl[9810]: The PostgreSQL documentation contains more information about shared memory configuration. 
Apr 07 12:39:00 localhost.localdomain pg_ctl[9810]: pg_ctl: could not start server Apr 07 12:39:00 localhost.localdomain pg_ctl[9810]: Examine the log output.

fix in chef recipes

shmmax='kernel.shmmax=335544320' 
execute "set shmax" do
 command "sysctl -w #{shmmax}" 
end 

file "/etc/sysctl.d/shmmax.conf" do
 content shmmax 
end