2014년 11월 26일 수요일

Cookbook application_java and workaround to the error - undefined method 'create' for nil:NilClass

These days, I developed cookbooks to deploy java web applications. To do this efficiently, need to combine some cookbooks: java, tomcat and application_java. As what they intend to do by their names, they certainly install and configure software related to java (JDK, java container server and java application).

Developing java and tomcat cookbook wasn't a big deal, but, I encountered problem with an error in case of application_java. My code was follows:
include_recipe 'java'

application 'shop-admin' do
    path '/var/shop-admin'
    repository 'http://192.168.56.170/zabbix/shop.admin.war'
    revision '1.0'
    scm_provider Chef::Provider::RemoteFile::Deploy

    java_webapp
    tomcat
end
My error message was:
...
================================================================================
Error executing action `deploy` on resource 'deploy_revision[shop-admin]'
================================================================================

NoMethodError
-------------
undefined method `create' for nil:NilClass

Cookbook Trace:
---------------
/var/chef/cache/cookbooks/application_java/libraries/provider_remote_file_deploy.rb:53:in `action_sync'
...
The solution was to change application_java cookbook. By default, Chef Supermarket links to https://github.com/poise/application_java.

Other people who had same issue already posted and someone recommended to clone from https://github.com/jamiely/application_java
I replaced with "jamiely/application_java". After that, my war deployed well.

2014년 11월 22일 토요일

Cost comparision VMware and Redhat Cloud

Comparison between VMware and Redhat - Redhat Cloud Infrastructure (RHCI includes Openstack and redhat currently mainatains RDO). VMware is often and still being compared with others. But cost saving is a silver bullet to attract IT manager. This image came from Redhat's webinar - http://www.redhat.com/en/about/events/building-and-managing-hybrid-cloud-red-hat-cloud-infrastructure.

2014년 5월 10일 토요일

How to change network model for Windows instance in Openstack.

I posted about installing virtio drivers on Windows 2012R2. This was for as Openstack glance.

I chose this image to create a Windows virtual instance using nova command and I found the instance had no network connection at all after boot.


My last post described how to install virtio scsi controller (HDD) and baloon (memory) driver. Network was not included.

In Openstack, the compute node which has KVM hypervisor tries to add virtual network typed "virtio" for instances. My instance had also virtio one. 
$ virsh dumpxml 
...
    <interface type='bridge'>
      <mac address='fa:16:3e:82:9d:c3'/>
      <source bridge='br-int'/>
      <virtualport type='openvswitch'>
        <parameters interfaceid='a3bc1442-e121-4730-9f6f-1abff6466f11'/>
      </virtualport>
      <target dev='tapa3bc1442-e1'/>
      <model type='virtio'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
Because I didn't installed virtio network driver for the glance image.
So, What I did to enable network of the instance was to change network type from "virtio" to "e1000" (default ethernet driver in Linux) of the glance image.

$ glance image-update --property hw_vif_model=e1000 $image_id2
+-------------------------+--------------------------------------+
| Property                | Value                                |
+-------------------------+--------------------------------------+
| Property 'hw_vif_model' | e1000                                |
| checksum                | 572850147e8f2cf1814e4953065a6421     |
| container_format        | bare                                 |
| created_at              | 2014-05-09T04:16:56                  |
| deleted                 | False                                |
| deleted_at              | None                                 |
| disk_format             | qcow2                                |
| id                      | 0ec11912-6634-4e09-bf09-c97373da2a47 |
| is_public               | True                                 |
| min_disk                | 0                                    |
| min_ram                 | 0                                    |
| name                    | windows2012r2                        |
| owner                   | None                                 |
| protected               | False                                |
| size                    | 10739318784                          |
| status                  | active                               |
| updated_at              | 2014-05-09T07:48:21                  |
+-------------------------+--------------------------------------+

After updating, I created the 2nd instance. This time, network in my 2nd instance is working well.


Let's look at how the network type is added for the 2nd instance.
$ virsh dumpxml 
...
    <interface type='bridge'>
      <mac address='fa:16:3e:57:cf:41'/>
      <source bridge='br-int'/>
      <virtualport type='openvswitch'>
        <parameters interfaceid='1a3a7af8-945e-425f-a39f-e6a48b7d87f3'/>
      </virtualport>
      <target dev='tap1a3a7af8-94'/>
      <model type='e1000'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>

As to install virtio network driver, I added it to my evernote. Please refer to this link for further information. Of course, you don't need to change network type in case you've already installed virtio network driver.

2014년 5월 5일 월요일

Installing Windows Server 2012 R2 with VirtIO on KVM/QEMU.


I'd like to share my evenote about installing Windows Server 2012 R2 with virtio on KVM/QEMU.

VirtIO drivers which enable para-virtual in KVM generally provide better performance than emulated devices under full-virtualization.



Tests in this note ran on a Ubuntu 12.04 machine.  
Here's my note : https://www.evernote.com/shard/s63/sh/7ca831a4-b275-4c6f-8886-4ba9103c0af3/5a912740e9ab14f342e3c194974390eb



2013년 8월 13일 화요일

How to solve message "Starting nagios:No directory, logging in with HOME=/" when starting nagios deamon

I wrote a script of installing nagios 3 named "install-nagios3.sh" on my github repository (https://github.com/yeonki-choi/nagios) and tested it. After ran this, everything was fine excepts for message "Starting nagios:No directory, logging in with HOME=/" when starting nagios daemon.
$ sudo service nagios start
Starting nagios:No directory, logging in with HOME=/
done.

I found this message was same-produced when I switched to user "nagios". It was caused there was no home directory for user "nagios". This script created the user "nagios" with no home directory during running to own nagios-core's home directory and start its daemon.

$ sudo su - nagios
No directory, logging in with HOME=/

To do solve this, it just make home directory for that user

# Make a directory and changed the ownership
$ sudo mkdir /home/nagios
$ sudo chown -R nagios:nagios /home/nagios

# Setting the directory as the home of nagios
$ sudo usermod --home /home/nagios nagios
usermod: no changes

# Restarting nagios daemon, this time there is no above message 
$ sudo service nagios restart
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.

2013년 7월 14일 일요일

Warning :Remote branch XXX.. not found in upstream origin, using HEAD instead when cloning xen source

When you clone git repository for xen 4.3, you would get the following message:
"Remote branch RELEASE-4.3.0 not found in upstream origin, using HEAD instead"

This is caused because of git version, prior version to 1.7.10 don't support checking out tag.
# My git version 
$ git --version
git version 1.7.9.5

# Download Xen source
$ git clone -b RELEASE-4.3.0 git://xenbits.xen.org/xen.git
Cloning into 'xen'...
remote: Counting objects: 272877, done.
remote: Compressing objects: 100% (55538/55538), done.
remote: Total 272877 (delta 214914), reused 270399 (delta 212700)
Receiving objects: 100% (272877/272877), 53.61 MiB | 1.75 MiB/s, done.
Resolving deltas: 100% (214914/214914), done.

warning: Remote branch RELEASE-4.3.0 not found in upstream origin, using HEAD instead

Simply, you are able to check out additionally.
$ cd xen
$ git checkout RELEASE-4.3.0
Note: checking out 'RELEASE-4.3.0'.

Or, you can re-install the newer version of git.
# Remove the old git
$ sudo apt-get remove git

# Download git
$ wget https://git-core.googlecode.com/files/git-1.8.1.2.tar.gz
$ tar -xzvf ./git-1.8.1.2.tar.gz
$ cd git-1.8.1.2
$ make prefix=/usr/local all
$ sudo make prefix=/usr/local install
$ git --version
git version 1.8.1.2

# Download Xen source 
$ git clone -b RELEASE-4.3.0 git://xenbits.xen.org/xen.git
Cloning into 'xen'...
remote: Counting objects: 272877, done.
remote: Compressing objects: 100% (55538/55538), done.
remote: Total 272877 (delta 214914), reused 270399 (delta 212700)
Receiving objects: 100% (272877/272877), 53.61 MiB | 4.01 MiB/s, done.
Resolving deltas: 100% (214914/214914), done.
Note: checking out 'f8cc9c2b713b1739b1d3d324716547fa639dce86'.

References:
1. http://stackoverflow.com/questions/17216067/git-clone-b-tag-results-in-warning-remote-branch-not-found-in-upstream-origi/17216068#17216068


2013년 7월 10일 수요일

Note things in dealing with Nagios+Ndo2DB and properties in host configuration

I'd like to point out two things related nagios.
As we know, we are able to save status data of host and service into relational database using ndo2db module and I described how to setup at a post.

When people have nagios + nod2db monitoring system in their environments, they may find that data is duplicated in the table "nagios_hosts" and what makes this happen.

For example, this is result of the query of host definitions

mysql> SELECT host_id, alias, address, config_type FROM `nagios_hosts`;
+----------+-----------+----------------+---------------+
| host_id  | alias     |  address       |  config_type  |
+----------+-----------+----------------+---------------+
|10963     |test03     | 192.168.20.183 |            1  |                                 
|10962     |cent-test  | 192.168.20.175 |            1  |                                 
|10961     |FDCMOCDB01 | 192.168.20.172 |            1  |                                 
|10960     |test03     | 192.168.20.183 |            0  |                                 
|10959     |cent-test  | 192.168.20.175 |            0  |                                 
|10958     |FDCMOCDB01 | 192.168.20.172 |            0  |   
+----------+-----------+----------------+---------------+
Like this, every host is duplicated except for config_type.

Ndo2db can either get host definition from the original config file (It is usually located in /etc/nagios/objects/hosts.cfg) or retained config file(/var/log/nagios/status.dat)

As default, config_output_options is 3 which means get both data from config file and retained config file.

$ cat /etc/nagios/ndomod.cfg | grep config*
...
# CONFIG OUTPUT OPTION
# This option determines what types of configuration data the NDO NEB module will dump from Nagios.
# Values can be OR'ed together.
# Values:
#         0 = Don't dump any configuration information
#         1 = Dump only original config (from config files)
#         2 = Dump config only after retained information has been restored
#         3 = Dump both original and retained configuration
config_output_options=3
I changed this value to 2, I'd like to get data only from the retained file.
$ cat /etc/nagios/ndomod.cfg
...
config_output_options=2
Then, Restarting Services
$ service ndo2db restart
$ service nagios restart

mysql> SELECT host_id, alias, address, config_type FROM `nagios_hosts`;
+----------+-----------+----------------+---------------+
| host_id  | alias     |  address       |  config_type  |
+----------+-----------+----------------+---------------+
|10972     |test03     | 192.168.20.183 |            1  |                                 
|10971     |cent-test  | 192.168.20.175 |            1  |                                 
|10970     |FDCMOCDB01 | 192.168.20.172 |            1  |                                 
+----------+-----------+----------------+---------------+
Next topic, I think it is more important point.
I usually edit config files in the directory "/etc/nagios/objects/" when need to change some properties, active_checks_enabled for instance.
But I managed to know that nagios doesn't pick up some properties from config files. Rather, nagios relies retention files.

It is said that the information from nagios manual

"It is important to point out that several directives in host, service, and contact definitions may not be picked up by Nagios when you change them in your configuration files. Object directives that can exhibit this behavior are marked with an asterisk (*). The reason for this behavior is due to the fact that Nagios chooses to honor values stored in the state retention file over values found in the config files, assuming you have state retention enabled on a program-wide basis and the value of the directive is changed during runtime with an external command."
And these are directives for host definition
...
active_checks_enabled *: ....
passive_checks_enabled *: ....
...

The problem is that I cannot edit the retention status file which is read-only file and only editable by nagios. So, how can I do to change unchangeable properties by ending in config file in programming manner not using nagios web.

Naiogs provides cmd.cgi interface and it can run like the below:

$ curl -d "cmd_mod=2&cmd_typ=48&host=FDCMOCDB01" "http://localhost/nagios/cgi-bin/cmd.cgi" -u "nagiosadmin:*******"
<html>
<head>
<link rel="shortcut icon" href="/nagios/images/favicon.ico" type="image/ico">
<title>
External Command Interface
</title>
<LINK REL='stylesheet' TYPE='text/css' HREF='/nagios/stylesheets/common.css'>
<LINK REL='stylesheet' TYPE='text/css' HREF='/nagios/stylesheets/cmd.css'>
</head>
<body CLASS='cmd'>

<!-- Produced by Nagios (http://www.nagios.org).  Copyright (c) 1999-2007 Ethan Galstad. -->
<table border=0 width=100%>
<tr>
<td align=left valign=top width=33%>
<TABLE CLASS='infoBox' BORDER=1 CELLSPACING=0 CELLPADDING=0>
<TR><TD CLASS='infoBox'>
<DIV CLASS='infoBoxTitle'>External Command Interface</DIV>
Last Updated: Tue Jul 9 16:04:13 KST 2013<BR>
Nagios® Core™ 3.3.1 - <A HREF='http://www.nagios.org' TARGET='_new' CLASS='homepageURL'>www.nagios.org</A><BR>
Logged in as <i>nagiosadmin</i><BR>
</TD></TR>
</TABLE>
</td>
<td align=center valign=top width=33%>
</td>
<td align=right valign=bottom width=33%>
</td>
</tr>
</table>
<P><DIV CLASS='infoMessage'>Your command request was successfully submitted to Nagios for processing.<BR><BR>
Note: It may take a while before the command is actually processed.<BR><BR>
<A HREF='javascript:window.history.go(-2)'>Done</A></DIV></P>
<!-- Produced by Nagios (http://www.nagios.org).  Copyright (c) 1999-2007 Ethan Galstad. -->
</body>
</html>

This is how to run cmd.cgi with curl in the shell environment

$ curl -d cmd_typ=${cmd} \
      -d cmd_mod=2 \
      -d host=${host} \
      -d service=${svc} \
      -d btnSubmit=Commit \
      -s \
      -u 'user:pass \
      "http://nagios.server/nagios/cgi-bin/cmd.cgi"

As parameter "cmd_typ", constant values are defined in the header file "common.h"
...
#define CMD_ENABLE_HOST_CHECK 47
#define CMD_DISABLE_HOST_CHECK 48
...

If you implement this in java, you are able to execute it by using httpclient class (package org.apache.commons.httpclient) like my case.

References:
1. http://eggsonbread.com/2011/03/18/disable-enable-nagios-notifications-via-command-line-curl/
2. https://github.com/ageric/nagios/blob/cc67733e82721546d9d04180c4441cdb41a6f9a2/include/common.h
3. http://forums.cacti.net/post-133568.html