среда, 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!

четверг, 26 сентября 2013 г.

Git crib

Git

Git is a free & open source, distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Configuration

Set Name and Email Address

$ git config --global user.name "Your Name"
$ git config --global user.email "yourname@yourdomain.com"

Set Colors

$ git config color.ui true

General Commands

Create a Repository

$ mkdir project
$ cd project
$ git init

Ignore Files or Directories

Create .gitignore and add file and directory globs:
dist
tmp
log
.DS_Store

See List of Changed Files

$ git status

See Difference of Files

$ git diff

Stage Files for Committing

$ git add foo.txt
$ git add bar.txt

Unstage a File

$ git reset HEAD bar.txt

See Differences of Staged Files

$ git diff --cached

Commit Staged Files

$ commit -m "Your Message Here"

Revert a Changed File

$ git checkout name/of/file

Branching

Create a Branch

$ git branch <branchName>

Switch to a Branch

$ git checkout <branchName>

Create and Switch to Branch

$ git checkout -b <branchName>

Switch back to master Branch

$ git checkout master

List Local Branches

$ git branch

List Remote Branches

$ git branch -r

List Local and Remote Branches

$ git branch -a

Merge changes from another Branch

$ git merge <branchName>

Rename a Branch

$ git branch -m <currentName> <newName>

Force Rename of Branch

$ git branch -M <currentName> <newName>

Delete a Branch if differences have been merged into current branch

$ git branch -d <branchName>

Force Deletion of Branch

$ git branch -D <branchName>

Delete Remote Branch

$ git branch -d -r <remoteName>/<branchName>
$ git push <remoteName> :<branchName>

Remote Repositories

Show List of Remote Repositories

$ git remote

Add a Remote Repository

$ git remote add <remoteName> <url>

Remove a Remote Repository

$ git remote rm <remoteName>

Rename a Remote Repository

$ git remote rename <oldRemoteName> <newRemoteName>

Push to a Remote Repository

$ git push <remoteName> <branchName>

Pushing to Multiple Remote Repositories at Once

If you want to push to multiple remote repositories using a single name you can first add the two remotes separately and then end .git/config to add a third remote that combines both of them together:
[remote "heroku"]
 url = git@heroku.com:bnd-notes.git
 fetch = +refs/heads/*:refs/remotes/heroku/*
[remote "github"]
 url = git@github.com:buildndeploy/notes.git
 fetch = +refs/heads/*:refs/remotes/github/*
[remote "external"]
    url = git@github.com:buildndeploy/notes.git
 url = git@heroku.com:bnd-notes.git
 fetch = +refs/heads/*:refs/remotes/heroku/*
Then you can update them with a single command:
$ git push external

Stashes

git stash / git stash save
git stash list
git stash apply <stash>
git stash apply stash@{0}
git stash pop

GitHub Fork Merge

$ git remote add upstream git://github.com/qgis/Quantum-GIS.git
$ git fetch upstream
$ git merge upstream/master

четверг, 5 сентября 2013 г.

[CENTOS6] Настраиваем алтернативы для Java

export java_home=/usr/java/default
/usr/sbin/update-alternatives --install /usr/bin/java java ${java_home}/bin/java 20000 \
                                --slave /usr/bin/keytool keytool ${java_home}/bin/keytool \
                                --slave /usr/bin/orbd orbd ${java_home}/bin/orbd \
                                --slave /usr/bin/pack200 pack200 ${java_home}/bin/pack200 \
                                --slave /usr/bin/rmid rmid ${java_home}/bin/rmid \
                                --slave /usr/bin/rmiregistry rmiregistry ${java_home}/bin/rmiregistry \
                                --slave /usr/bin/servertool servertool ${java_home}/bin/servertool \
                                --slave /usr/bin/tnameserv tnameserv ${java_home}/bin/tnameserv \
                                --slave /usr/bin/unpack200 unpack200 ${java_home}/bin/unpack200 \
                                --slave /usr/lib/jvm/jre jre ${java_home} \

четверг, 29 августа 2013 г.

[RPM] Встроенные макросы

Built-in macros

RPM includes a host of built-in macros, including the following useful directories:
%_prefix /usr
%_exec_prefix %{_prefix}
%_bindir %{_exec_prefix}/bin
%_sbindir %{_exec_prefix}/sbin
%_libexecdir %{_exec_prefix}/libexec
%_datadir %{_prefix}/share
%_sysconfdir %{_prefix}/etc
%_sharedstatedir %{_prefix}/com
%_localstatedir %{_prefix}/var
%_libdir %{_exec_prefix}/lib
%_includedir %{_prefix}/include
%_oldincludedir /usr/include
%_infodir %{_prefix}/info
%_mandir %{_prefix}/man
The example directories shown above come from the standard RPM macro file, /usr/lib/rpm/macros, instead of the Red Hat-specific file, /usr/lib/rpm/redhat/macros, which holds:
%_prefix /usr
%_sysconfdir /etc
%_localstatedir /var
%_infodir /usr/share/info
%_mandir /usr/share/man
%_initrddir %{_sysconfdir}/rc.d/init.d
%_defaultdocdir %{_usr}/share/doc

[DEBIAN] Устанавливаем локаль ru_RU.UTF8

apt-get install locales - на все вопросы вносим Y. vi /etc/environment - открываем файл на редактирование и удаляем из него любые записи и вносим одну: LANG="ru_RU.UTF-8"
Помощь по использованию vi находится здесь: Vi или откройте файл через WinSCP
Редактируем файл /etc/locale.gen тем же vi: vi /etc/locale.gen - В списке находим ru_RU.UTF-8 UTF-8 и удаляем значек # перед записью. Сохраняем файл.
locale-gen - запускаем команду для генерации локали. Пример ниже:
root@test:~# locale-gen
Generating locales (this might take a while)...
ru_RU.UTF-8... done
Generation complete.
Перезаходим на сервер. В клиенте, который Вы используете для связи с сервером делаем следующее (большинство людей использует Putty: SSH):
После того как Вы вошли на сервер, кликните на верхнюю часть окна Putty правой кнопкой мыши, выше черного. Выберите Change Settings -> Window - Translation -> из списка выберите UTF-8 и нажмите Apply внизу.
Теперь Вы сможете видеть русский язык в окне связи с сервером при выполнении различных команд.