вторник, 22 октября 2013 г.

Virtual Box Console commands

As something of a follow-up post to the previous entry, here’s a quick recipe for creating a Virtual Machine using the VirtualBox command line tools:

We’re using Windows Server 2008 64bit as an example, modify to taste.

$ VM='Windows-2008-64bit'

Create a 32GB “dynamic” disk.

$ VBoxManage createhd --filename $VM.vdi --size 32768

You can get a list of the OS types VirtualBox recognises using:

$ VBoxManage list ostypes

Then copy the most appropriate one into here.

$ VBoxManage createvm --name $VM --ostype "Windows2008_64" --register

Add a SATA controller with the dynamic disk attached.

$ VBoxManage storagectl $VM --name "SATA Controller" --add sata \
> --controller IntelAHCI
$ VBoxManage storageattach $VM --storagectl "SATA Controller" --port 0 \
> --device 0 --type hdd --medium $VM.vdi

Add an IDE controller with a DVD drive attached, and the install ISO inserted into the drive:

$ VBoxManage storagectl $VM --name "IDE Controller" --add ide
$ VBoxManage storageattach $VM --storagectl "IDE Controller" --port 0 \
> --device 0 --type dvddrive --medium /path/to/windows_server_2008.iso

Misc system settings.

$ VBoxManage modifyvm $VM --ioapic on
$ VBoxManage modifyvm $VM --boot1 dvd --boot2 disk --boot3 none --boot4 none
$ VBoxManage modifyvm $VM --memory 1024 --vram 128
$ VBoxManage modifyvm $VM --nic1 bridged --bridgeadapter1 e1000g0

Configuration is all done, boot it up! If you’ve done this one a remote machine, you can RDP to the console via vboxhost:3389.

$ VBoxHeadless -s $VM

Once you have configured the operating system, you can shutdown and eject the DVD.

$ VBoxManage storageattach $VM --storagectl "IDE Controller" --port 0 \
> --device 0 --type dvddrive --medium none

Finally, it’s a good idea to take regular snapshots so that you can always revert back to a known-good state rather than having to completely re-install.

$ VBoxManage snapshot $VM take <name of snapshot>

And, if you need to revert back to a particular snapshot:

$ VBoxManage snapshot $VM restore <name of snapshot>

Enjoy!

Readline shortcuts

Readline shortcuts

GNU Readline is the library used to make advanced command-line wizardry convenient and conistent across a multitude of command-line applications. These programs include bash, bc, ftp, gnuplot, gpg, ksh, mysql, psql, python, smbclient, xmllint and zsh.
The cheatsheet at the right contains a summary of many of the useful line editing command shortcuts which are available in all applications that use libreadline.
See the documentation on the Readline website for even more shortcuts with more elaborate descriptions.

Emacs keys Action Scope Direction/Place
Moving around Ctrl-b Move the cursor one character ⇦ to the left
Ctrl-f Move the cursor one character ⇨ to the right
Alt-b Move the cursor one word ⇦ to the left
Alt-f Move the cursor one word ⇨ to the right
Ctrl-a Move the cursor ⇤ to the start of the line
Ctrl-e Move the cursor ⇥ to the end of the line
Ctrl-x-x[1] Move the cursor ⇤⇥ to the start, and to the end again
Cut, copy
and paste
Backspace Delete the character ⇦ to the left of the cursor
DEL
Ctrl-d
Delete the character underneath the cursor
Ctrl-u Delete everything ⇤ from the cursor back to the line start
Ctrl-k Delete everything ⇥ from the cursor to the end of the line
Alt-d Delete word ⇨ untill before the next word boundary
Ctrl-w Delete word ⇦ untill after the previous word boundary
Ctrl-y Yank/Paste prev. killed text at the cursor position
Alt-y Yank/Paste prev. prev. killed text at the cursor position
History Ctrl-p Move in history one line ⇧ before this line
Ctrl-n Move in history one line ⇩ after this line
Alt-> Move in history all the lines ⇩ to the line currently being entered
Ctrl-r Incrementally search the line history ⇧ backwardly
Ctrl-s[2] Incrementally search the line history ⇩ forwardly
Ctrl-J End an incremental search
Ctrl-G Abort an incremental search and restore the original line
Alt-Ctrl-y Yank/Paste arg. 1 of prev. cmnd at the cursor position
Alt-.
Alt-_
Yank/Paste last arg of prev. cmnd at the cursor position
Undo Ctrl-_
Ctrl-x
Ctrl-u
Undo the last editing command; you can undo all the way back to an empty line
Alt-r Undo all changes made to this line
Ctrl-l Clear the screen, reprinting the current line at the top
Ctrl-l Clear the screen, reprinting the current line at the top
Completion TAB Auto-complete a name
Alt-/[3] Auto-complete a name (without smart completion)
Alt-? List the possible completions of the preceeding text
Alt-* Insert all possible completions of the preceeding text
Transpose Ctrl-t Transpose/drag char. before the cursor ↷ over the character at the cursor
Alt-t Transpose/drag word before the cursor ↷ over the word at/after the cursor

вторник, 8 октября 2013 г.

Installing b43 wireless on ubuntu

Download this:
http://downloads.openwrt.org/sources/wl_apsta-3.130.20.0.o
and
http://mirror2.openwrt.org/sources/broadcom-wl-4.150.10.5.tar.bz2
Copy them into your installation flashdrive
Install b43-fwcutter from /cdrom/pool/main/b/ there will be .deb package
Than:

tar -xjvf broadcom-wl-4.150.10.5.tar.bz2
sudo b43-fwcutter -w /lib/firmware wl_apsta-3.130.20.0.o
sudo b43-fwcutter --unsupported -w /lib/firmware broadcom-wl-4.150.10.5/driver/wl_apsta/wl_prebuilt.o
sudo chmod 775 /lib/firmware/b43
sudo chmod 775 /lib/firmware/b43legacy
sudo modprobe -r b43
sudo modprobe b43

Thats it :) Works on Ubuntu 13.04

пятница, 4 октября 2013 г.

Sphinx on Gentoo

# Обновить portage
emerge --sync
emerge portage

# Установить sphinx
USE="debug id64 mysql -postgres stemmer test" emerge app-misc/sphinx

# Скопировать или переименовать конфигурационный файл
cd /etc/sphinx
cp sphinx.conf.dist sphinx.conf

# Настроить разрешения, чтоб группа web могла редактировать конфигурационный файл
chmod 664 /etc/sphinx/*
chown root:web /etc/sphinx/*

# Добавить пользователя и группу sphinx
groupadd -g 494 sphinx
useradd -g sphinx -u 494 -d /var/lib/sphinx -s /bin/bash -c "Sphinx server" sphinx

# Создать папки, где будут храниться логи, pid-файлы и данные
mkdir -p /var/log/sphinx
mkdir -p /var/run/sphinx
mkdir -p /var/lib/sphinx/data

# Настроить правильные разрешения на эти папки
chown sphinx:sphinx /var/log/sphinx
chown -R sphinx:sphinx /var/lib/sphinx
chown sphinx:sphinx /var/run/sphinx

# Добавить в /etc/sudoers что-то типа
%web ALL=NOPASSWD:/etc/init.d/searchd
%web ALL=(sphinx) NOPASSWD:/usr/bin/indexer

# Проверить от пользователя группы web
sudo -u sphinx /usr/bin/indexer
sudo /etc/init.d/searchd restart|stop|start

# Установить расширения php
PHP_TARGETS="php5-4" emerge pecl-sphinx

Так же  пришлось немного подправить init скрипт, чтобы запускать свинкс от моего пользователя

среда, 2 октября 2013 г.

AntHillPro: Create, manage and delete environments via BeanShell scripts

Creating new entity (project, environment etc)

Lets assume that we need to create new environment within script
First of all, all new stuff will be applied into database only after step ends. When you create new environment you can't manipulate it, you can only add Properties on it, but you can't add agents or you cant add it into Environment Group, you will get an Exception because environment still not exists in scope of anthill. Same exception will happen if you will try to manipulate newly created project or some other instance. So, remember, if you create something you need to do:
  1. <your_new_entity> = new <Something>;
  2. <you_new_entity>.store();
  3. Finish step.
On next step your new entity will be in database and available for manipulation in anthill, you can add it into server groups, projects etc.

Adding into Environment Group

It is quite simple:
  1. Get environment group: EnvironmentGroup envGroup = EnvironmentGroupFactory.getInstance().restore( envGroupID );
  2. envGroup.addServerGroup( env ) , where env should be instance of ServerGroup
I want to point that you do not need to call .store() method, it will store by itself after the end of the step.

Adding into project's workflows.

There is a one limitation: you can add environment only in non originating workflows.
It also simple:
  1. Get project: Project prj = ProjectFactory.getInstance().restore( projectID );
  2. Get non-originating workflow like Workflow wf = prj.getWorkflow( nonOrigWFID ) or get an array of workflows Workflow[] wfArray = prj.getNonOriginatingWorkflowArray() and iterate over it.
  3. Add environment into it: wf.addServerGroup( env ) , where env should be instance of ServerGroup
Also you do not need to call .store() method here.

Deleting environment

In first part we have created environment and added it into environment group and workflows. Now if you want to delete it from anthill you need to delete it from all workflows where this environment is used.
It's not quite obvious, but... :) Here will be 3 steps in total: 

First step:

  • Get environment: ServerGroup env = ServerGroupFactory.getInstance().restoreForName( "my-env-name" );
  • Get environment's group: EnvironmentGroup[] envGroupArray = EnvironmentGroupFactory.getInstance().restoreAllForEnvironment( env );
Get all non-originating workflows that use this environment. In docs I've found method in WorkflowFactory:
  • Workflow[] wfInEnvArray = WorkflowFactory.getInstance().restoreAllNonOriginatingWorkflowsForEnvGroupsInEnvironment( env, envGroupArray, "*", "*", "*" );
we got all required variables earlier. Then you just need to iterate over this list and use <workflow>.removeServerGroup( env ); 
On this point Job step should finish and all removals will be applied into database, without it we can't delete environment, you'll get en exception that this env is in use.

Second step:

Also before delete you need to remove this environment from the environment group.
We have environment group which this environment belongs to, so just remove: envGroup.removeServerGroup( env ); 

Third step:

Just get ServerGroup object for required environment and call .delete() method.

вторник, 1 октября 2013 г.

NGINX + FastCGI Perl on Gentoo

Adding to make.conf modules required for nginx and cgi wrapper

NGINX_MODULES_HTTP="access auth_basic autoindex charset fastcgi gzip gzip_static limit_req map proxy rewrite scgi ssi stub_status"
NGINX_MODULES_MAIL=""

Emerging nginx
emerge -av nginx www-misc/fcgiwrap www-servers/spawn-fcgi

  • www-misc/fcgiwrap, a FastCGI server for wrapping CGI scripts
  • www-servers/spawn-fcgi, a FastCGI manager for spawning fcgiwrap.
Make any adjustments you like to /etc/nginx/mime.types. I added:
types {
    …
    application/x-python                  py;
    application/x-shell                   sh;
    …
}
 
Configure spawn-fcgi to launch fcgiwrap with:
# cp /etc/conf.d/spawn-fcgi /etc/conf.d/spawn-fcgi.fcgiwrap
# emacs /etc/conf.d/spawn-fcgi.fcgiwrap
# cat /etc/conf.d/spawn-fcgi.fcgiwrap
FCGI_SOCKET=/var/run/fcgiwrap.sock
FCGI_ADDRESS=
FCGI_PORT=
FCGI_PROGRAM=/usr/sbin/fcgiwrap
FCGI_USER=nginx
FCGI_GROUP=nginx
FCGI_EXTRA_OPTIONS="-M 0700"
ALLOWED_ENV="PATH HOME"
HOME=/
FCGI_CHILDREN=1
FCGI_CHROOT=
# cd /etc/init.d/
# ln -s spawn-fcgi spawn-fcgi.fcgiwrap
 
Start fcgiwrap with:
# /etc/init.d/spawn-fcgi.fcgiwrap start
 
Add it to the default runlevel with:
# rc-update add spawn-fcgi.fcgiwrap default
 
NGINX configuration:
server {
...
location / {
    include fastcgi_params;
    fastcgi_pass  unix:/var/run/fcgiwrap.sock-1;
  }
...
}
 
Should work now!