Thursday, March 28, 2013

What does cfengine Bootstrapping mean?


Cfengine bootstrapping means/servers the purpose of: 

1.  Starting/configuring cf-agent so that it runs automatically in every few minutes
2.  The agent connects to the defined policy server to get the updated policy files. 

Here is how you bootstrap cf-agent. 

cf-agent --bootstrap --policy-server=<ip_of_your_policy_distribution_server>

The above command when executed will start cf-agent to run in every 5 minutes to get the policy files from the policy server that you have given above and implement those policies. 

If you are configuring a machine to be used as a policy distribution server then all you need to do is use its own IP and it will give you proper messaging like "R: This host assumes the role of policy distribution host". 

Once the bootstrapping is over, you will notice that cf-execd and cf-serverd are running. 

See for example output: 


ps axw | grep "cf-"

  951 ?        Ss     0:00 /var/cfengine/bin/cf-execd
  957 ?        Ss     0:00 /var/cfengine/bin/cf-serverd


The agent machines will copy the policy files from your policy distribution servers /var/cfengine/masterfiles/ directory to /var/cfengine/inputs directory. 

sed command to replace first occurrence of a pattern in file

sed command to replace first occurrence of a pattern in file : 


sed '0,/pattern/s/pattern/replacement/' filename

That's simple and sweet!

How to recover deleted files in Linux


A file in linux file system is just a link to an inode. When you delete the file, actually the link is deleted and not the actual inode until all references to that inode are deleted. This gives me an impression that there has to be some way by which we can recover accidentally deleted files and directories in Linux. 

Unfortunately, I could not find any good and straight forward solution for this. There are couple of tools available today like Magic Rescue, photorec. You need to see if they work for you.. I did not find them worth for the files and directories that I deleted.

Monday, March 25, 2013

A look at cfengine binaries and what they do



cf-promises
This compiles and verifies the promises that have been defined. Basically used to pre-check configurations before you can actually deploy those.  

cf-agent
This is the actual binary that maintains the system resources based on policy files.  

cf-serverd
Only the server can share files with other agent hosts and also receive requests to execute policies. It is not possible to send (push) new information to CFEngine from outside.

cf-execd
This is the scheduling daemon (which can either supplement or replace cron). It works as a wrapper, executing and collecting the output of cf-agent and E-mailing it to system account. 

cf-runagent
This is a helper program that can talk to cf-serverd and request that it execute cf-agent with its existing policy. It can thus be used to simulate a push of changes to CFEngine hosts, if their policy includes that they check for updates. 

cf-report
Generates summary and other reports in a variety of formats for export or integration with other systems. 

cf-know
This agent can generate an ISO standard Topic Map from a number of promises about system knowledge. It is used for rendering documentation as a `semantic web'.

Thursday, March 21, 2013

Error code 19 in Windows Device Manager for DVD

Remove/Delete the LowFilter and/or UpperFilter (you might have only one od these) entries from this registry area:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E965-E325-11CE-BFC1-08002BE10318}

Note: You will have several identical keys like this {4D36E965-E325-11CE-BFC1-08002BE10318}. The one you are looking for will have DVD/CD Rom Drives as the top entry. Reboot after deleting the LowFilter and/or UpperFilter entries.

Accessing MS SQL DATABASE FROM COMMAND PROMPT

To access MS SQL database from command prompt follow below steps in line:-

1.) Locate sqlcmd on your machine and trace down to its path from command prompt.

2.) To access named instance, use below command refer help for switches explanation.

SQLCMD -S SERVERNAME\INSTANCENAME –E

3.) Once connection is established it will prompt screen as


4.) Use below command to check out DB instances.

sp_databases
Go




on command prompt to execute any query we need to set go and then press enter.


Wednesday, March 20, 2013

Building and Installing Cfengine from Source

Pre-requisites: 
1. OpenSSL - Encryption System. http://www.openssl.org 
2. Tokyo Cabinet - Flat File Database. http://fallabs.com/tokyocabinet/ 
3. PCRE - Perl Compatible Regular Expression Library. http://www.pcre.org/ 

Sample commands to Install the pre-requisites under ubuntu: 

1. sudo apt-get update
2. sudo apt-get install libtokyocabinet-dev
3.  sudo apt-get install libssl-dev
4. sudo apt-get install libpcre3-dev


Downloading and Installing Cfengine
If you have not purchased ready to use cfengine binaries, you need you build them from source code. This is pretty easy once you have the required development environment setup ie., installed looks like gccflexbison. 

Here are the steps you need to follow for building cfengine from source. 

1.  Download Latest Cfengine source to a directory. http://cfengine.com/source-code
2.  tar zxf cfengine-x.x.x.tar.gz
3.  ./configure
4.  make
5.  make install

The last step actually installs the built binaries onto your system. Be default all gets installed in /var/cfengine/

That's all you need to do for installing cfengine. 

Easy.. Isn't It? 

Tuesday, March 19, 2013

Cfengine Features - A Quick Look.


Cfengine is the only configuration tool that is based on actual Research.


Why Cfengine against other configuration tool?

  • Longest Track Record. 
  • Based on actual research. 
  • Works equally well on 1 as well as 1000's of servers. 
  • A very helpful and large community. 
  • Supports largest number of platforms. 
  • Idempotent ie., Multiple applications of the operation does not change result. 
  • Capable of making each and every host autonomous. 
  • Non-reliant on a working network to function correctly. 
  • Lightweight and generic.
  • Open source software (GPL or COSL)

Latest version of Cfengine as of writing this article is 3.3.5


The primary principle of Cfengine is automatic convergence from Clean or Unknown states back to Configured. It is Resilient meaning, it pulls config from a Policy server. If server is unavailable or there are network issues it reads the cached copy from /var/cfengine/inputs

It does not have to worry about how many hosts... Each host is responsible for updating itself. 


It is hardly 2 MB in size and consumes very little network bandwidth. Have been used on embedded systems too. 








How to download file using cURL?


Simple.. use the -O option which tells that the downloaded file should be named as that of the original file that are we are trying to download. 

For e.g., 

curl -O http://mydomain.com/example.zip

This will download the file example.zip into the same directory from where you are running this command and will name the downloaded file as example.zip. 

There are a lot of options which can be used with curl. For a list of them see curl --help. 

An excellent link which I found that details various curl day to day examples is http://www.thegeekstuff.com/2012/04/curl-examples/. 

How to Unzip/extract an .tar.gz file?

Use command: 

tar -xvzf community_images.tar.gz

x : Extracts the files. 
v : Prints verbose output.
z : Tells tar to decompress using gzip.
f : Tells the name of the file to be Unzip and extracted.


Thursday, March 7, 2013

How to check your CentOS version


Easiest way is to use command line.. 

cat /etc/centos-release
Or
cat /etc/redhat-release

CentOS version history follows that of Red Hat
If you want to know more details on your kernel etc.. use the below command: 
uname -a
Sample Output
Linux sample.com 2.6.18-194.26.1.el5xen #1 SMP Tue Nov 9 13:35:30 EST 2010 x86_64 x86_64 x86_64 GNU/Linux

There you could be newer kernels installed on your CentOS server but not actually running. You can list the installed kernels using yum or rpm. You can then see which kernel is set to start on boot by checking your /etc/grub.conf.

Another great way to get all this information would be to use lsb-release..: 


lsb_release -a
LSB Version: :core-3.1-amd64:core-3.1-noarch:graphics-3.1-amd64:graphics-3.1-noarch
Distributor ID: CentOS
Description: CentOS release 5.5 (Final)
Release: 5.5
Codename: Final


How to view Events of a MySql Schema

To see various events that are there in MySql Schema use the below command:

show events; 

If you want to see events on a particular schema include the From clause..

show events from MySchema;