Tuesday, 31 May 2016

Installing chef client on a Solaris server


To install chef client in a Solaris server we need to install ruby & rubygems packages which in turn have gcc as a dependency.
To install ruby & rubygems from source download the tarball & extract it.

root@solaristest:/tmp# tar xvf ruby-1.8.7-p302.tar
x ruby-1.8.7-p302, 0 bytes, 0 tape blocks
x ruby-1.8.7-p302/lib, 0 bytes, 0 tape blocks
x ruby-1.8.7-p302/lib/drb.rb, 19 bytes, 1 tape blocks
---------------------------------- -------------- -------------------- ----- output truncated

cd ruby-1.8.7-p302

Now run ./configure:

root@solaristest:/tmp/ruby-1.8.7-p302# ./configure
checking build system type... sparc-sun-solaris2.10
checking host system type... sparc-sun-solaris2.10
checking target system type... sparc-sun-solaris2.10
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
---------------------------------- -------------- -------------------- ----- output truncated

Now run make:

root@solaristest:/tmp/ruby-1.8.7-p302# make
make: Warning: Illegal dependency list for target `.DEFAULT'
gcc -g -O2    -DRUBY_EXPORT -I. -I.    -c array.c
gcc -g -O2    -DRUBY_EXPORT -I. -I.    -c bignum.c
gcc -g -O2    -DRUBY_EXPORT -I. -I.    -c class.c
gcc -g -O2    -DRUBY_EXPORT -I. -I.    -c compar.c
gcc -g -O2    -DRUBY_EXPORT -I. -I.    -c dir.c
gcc -g -O2    -DRUBY_EXPORT -I. -I.    -c dln.c
gcc -g -O2    -DRUBY_EXPORT -I. -I.    -c enum.c
gcc -g -O2    -DRUBY_EXPORT -I. -I.    -c enumerator.c
gcc -g -O2    -DRUBY_EXPORT -I. -I.    -c error.c
gcc -g -O2    -DRUBY_EXPORT -I. -I.    -c eval.c
eval.c: In function `rb_eval_string_wrap':
eval.c:1744: warning: assignment discards qualifiers from pointer target type
---------------------------------- -------------- -------------------- ----- output truncated

Now run make install:

root@solaristest:/tmp/ruby-1.8.7-p302# make install
make: Warning: Illegal dependency list for target `.DEFAULT'
./miniruby -I./lib -I.ext/common -I./- -r./ext/purelib.rb  ./instruby.rb --make="make" --dest-dir=""  --extout=".ext"  --mflags=""  --make-flags=""  --data-mode=0644  --prog-mode=0755  --installed-list .installed.list --mantype="man"
installing binary commands
installing command scripts
installing library scripts
installing headers
installing manpages
installing extension objects
installing extension scripts

With this ruby is installed successfully. To check the version type:

root@solaristest:/tmp/ruby-1.8.7-p302# ruby --version
ruby 1.8.7 (2010-08-16 patchlevel 302) [sparc-solaris2.10]


To install rubygems package first extract the tarball as follows:

tar xvf rubygems-1.3.7.tar


Now go to the directory in which the files got extracted & run ruby setup.rb:
cd rubygems-1.3.7
ruby setup.rb

RubyGems 1.3.7 installed
=== 1.3.7 / 2010-05-13
NOTE:
http://rubygems.org is now the default source for downloading gems.
---------------------------------- -------------- -------------------- ----- output truncated

To check the installed version:

root@solaristest:/tmp/rubygems-1.3.7# gem --version
1.3.7

To install chef client download the client package from the chef official website.
Now run the following command to install the package:

root@solaristest:/tmp# pkgadd -d  chef-12.10.24-1.sparc.solaris chef

Processing package instance <chef> from </tmp/chef-12.10.24-1.sparc.solaris>

chef(sparc) 12.10.24-1
Chef Software, Inc. <maintainers@chef.io>
Using </opt> as the package base directory.
## Processing package information.
## Processing system information.
## Verifying disk space requirements.
## Checking for conflicts with packages already installed.
## Checking for setuid/setgid programs.

This package contains scripts which will be executed with super-user
permission during the process of installing this package.

Do you want to continue with the installation of <chef> [y,n,?] y

Installing chef as <chef>
---------------------------------- -------------- -------------------- ----- output truncated

To see the version of chef installed type:

root@solaristest:/tmp# pkginfo -l chef
   PKGINST:  chef
      NAME:  chef
  CATEGORY:  application
      ARCH:  sparc
   VERSION:  12.10.24-1
   BASEDIR:  /opt
    VENDOR:  Chef Software, Inc. <maintainers@chef.io>
      DESC:  The full stack of chef
    PSTAMP:  chef-solaris-10-sun4v-builder-a6fb8f.chef.co2016-04-27T18:37:34Z
  INSTDATE:  May 25 2016 09:41
     EMAIL:  Chef Software, Inc. <maintainers@chef.io>
    STATUS:  completely installed
     FILES:    13848 installed pathnames
                2005 directories
                 417 executables
              249756 blocks used (approx)


While working on this I encountered the following errors:

ERROR 1:

bash-3.2# ./configure
checking build system type... sparc-sun-solaris2.10
checking host system type... sparc-sun-solaris2.10
checking target system type... sparc-sun-solaris2.10
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/tmp/ruby-1.8.7-p302':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.

ERROR 2:

bash-3.2# make
bash: make: command not found

ERROR 3:

bash-3.2# ruby setup.rb
/usr/local/lib/ruby/1.8/sparc-solaris2.10/thread.so: ld.so.1: ruby: fatal: libgcc_s.so.1: open failed: No such file or directory - /usr/local/lib/ruby/1.8/sparc-solaris2.10/thread.so (LoadError)
        from /usr/local/lib/ruby/1.8/thread.rb:5
        from ./lib/rubygems.rb:11:in `require'
        from ./lib/rubygems.rb:11
        from setup.rb:24:in `require'
        from setup.rb:24

The fix for the above errors is rather simple.

Just define the following variables in /etc/profile file:

export PATH=$PATH:/usr/local/bin:/usr/ccs/bin:/usr/sfw/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

These contain paths for required entities like gcc & make which cause the above mentioned errors.


Monday, 25 April 2016

Installing java in Solaris on SPARC 64 bit architecture

This is a short post to describe installation of jdk/jre 1.6 in Solaris 10 on SPARC 64 bit platform.

Please note that java 1.6 is an older version & you'd need a support contract to download it.

Once you have downloaded the iso run the following command to extract it:

bash-3.2# unzip p9553040_160_SOLARIS64.zip
Archive:  p9553040_160_SOLARIS64.zip
  inflating: jdk-6u115-solaris-sparcv9.sh
 extracting: jdk-6u115-solaris-sparcv9.tar.Z
  inflating: jre-6u115-solaris-sparcv9.sh
  inflating: readme.txt

bash-3.2# ls
jdk-6u115-solaris-sparcv9.tar.Z
bash-3.2# zcat jdk-6u115-solaris-sparcv9.tar.Z  | tar -xf -

Once the file has been extracted it'll give us two packages:

One for JRE & other for JDK

bash-3.2# ls
jdk-6u115-solaris-sparcv9.tar.Z  SUNWj6dvx                        SUNWj6rtx

bash-3.2# pkgadd -d . SUNWj6dvx SUNWj6rtx

Processing package instance <SUNWj6dvx> from </java/123>

JDK 6.0 64-bit Dev. Tools (1.6.0_115)(sparc) 1.6.0,REV=2006.11.29.04.58
Copyright (c) 1995, 2016, Oracle and/or its affiliates. All rights reserved.
Using </usr> as the package base directory.
## Processing package information.
## Processing system information.
## Verifying package dependencies.
WARNING:
    The <SUNWj6dev> package "JDK 6.0 Dev. Tools (1.6.0)" is
    a prerequisite package and should be installed.
WARNING:
    The <SUNWj6rtx> package "JDK 6.0 64-bit Runtime Env.
    (1.6.0)" is a prerequisite package and should be
    installed.

Do you want to continue with the installation of <SUNWj6dvx> [y,n,?] y
## Verifying disk space requirements.

Processing package instance <SUNWj6rtx> from </java/123>

JDK 6.0 64-bit Runtime Env. (1.6.0_115)(sparc) 1.6.0,REV=2006.11.29.04.58
Copyright (c) 1995, 2016, Oracle and/or its affiliates. All rights reserved.
Using </usr> as the package base directory.
## Processing package information.
## Processing system information.
   6 package pathnames are already properly installed.
## Verifying package dependencies.
WARNING:
    The <SUNWj6rt> package "JDK 6.0 Runtime Env. (1.6.0)"
    is a prerequisite package and should be installed.

Do you want to continue with the installation of <SUNWj6rtx> [y,n,?] y
## Verifying disk space requirements.
-------------------------------------------------------output truncated

To verify the install you can check the installed version of java with the following command:

bash-3.2# pwd
/usr/jdk/instances/jdk1.6.0/bin/sparcv9
bash-3.2# ./java -fullversion
java full version "1.6.0_115-b12"

Mount a iso without using lofiadm

We usually mount an iso in Solaris using lofiadm.

Apparently we can skip the lofiadm steps & mount the iso directly as an hsfs file system as follows:

bash-3.2# pwd
/iso
bash-3.2# ls
sol-10-u9-ga-sparc-dvd.iso
bash-3.2#

To mount the iso run the following command:

mount -F hsfs /iso/sol-10-u9-ga-sparc-dvd.iso /mnt

The 'df -h' output will look like as follows:

/iso/sol-10-u9-ga-sparc-dvd.iso
                       2.1G   2.1G         0K   100%    /mnt

Fix for NTP error "No association ID's returned"

So today I came across an error wherein I was unable to get NTP running.

I started the service via svcadm like this:

# svcadm restart network/ntp

When I ran 'ntpq -p' to check the status I got the below error:

# ntpq -p
No association ID's returned

The configuration file looked good & had entries for the relevant NTP servers.

# cat /etc/inet/ntp.conf
server ntp1.vodafone.com.au
server ntp2.vodafone.com.au
server ntp3.vodafone.com.au
server ntp4.vodafone.com.au
server ntp5.vodafone.com.au

I then did a manual sync with one of the NTP server listed in the file & that did the trick.

# ntpdate -u ntp1.vodafone.com.au
25 Apr 14:55:05 ntpdate[49624]: adjust time server 10.105.138.4 offset 0.007227 sec

After the manual sync all five NTP servers were detected & were showing up in the output of ntpq -p:

#  ntpq -p
     remote           refid      st t when poll reach   delay   offset    disp
====================================================================
-ntp1.vodafone.c .GPS.            1 u   56   64   77     0.34    2.185  376.19
-ntp2.vodafone.c .GPS.            1 u   56   64   77    13.17    2.123  376.25
*ntp3.vodafone.c .GPS.            1 u   56   64   77    17.26    2.234  376.25
+ntp4.vodafone.c .GPS.            1 u   56   64   77    19.07    2.289  376.19
+ntp5.vodafone.c .GPS.            1 u   56   64   77    46.33    2.268  376.21

Getting started with CFEngine part 5 (Distributed node management & explaining desired state configuration)


In the last tutorial I created the policy my.cf to create a file named hello-world in /tmp folder.
But that was only on my policy server. I briefly illustrated how to distribute that across clients.
Here is a detailed example:

Copy the policy file to the /var/cfengine/masterfiles directory:

cp my.cf /var/cfengine/masterfiles

Edit the /var/cfengine/masterfiles/promises.cf file.
Note: use vim instead of vi as it makes spotting syntactical errors easier.

Modify the /var/cfengine/masterfiles/promises.cf file and insert the bundle name my_test in the bundlesequence in body common control. By doing so it will look something like this:
Don't forget to put a comma after the bundle name.
Include the my.cf in the inputs section of body common control in promises.cf. By doing so it will look something like this:
Remember to put it in double quotes followed by a comma.
With this done every time a cf-agent running on client contacts the policy server the policy will be executed.

In the basics tutorial I mentioned quite a few times about attaining desired state. I'll try to explain this based on our my.cf policy file example.
When the policy was executed on sever & client the hello world file was created on the server & client. Now I removed the file.
[root@dockertest tmp]# rm hello-world
rm: remove regular empty file ‘hello-world’? y
[root@dockertest tmp]# ls
cfengine-nova-3.7.3-1.x86_64.rpm  edit_motd_helloworld.cf  hsperfdata_root  my.cf  promises.cf  redis.sock
[root@dockertest tmp]# date
Sun Apr 24 15:04:21 EDT 2016

After a few minutes when I checked,  wow the file was there again!
[root@dockertest tmp]# ls
cfengine-nova-3.7.3-1.x86_64.rpm  edit_motd_helloworld.cf  hello-world  hsperfdata_root  my.cf  promises.cf  redis.sock
[root@dockertest tmp]# date
Sun Apr 24 15:13:12 EDT 2016
[root@dockertest tmp]# ls -l hello-world
-rw-------. 1 root root 0 Apr 24 15:06 hello-world
[root@dockertest tmp]#

This happened because when the cf-agent synced up after the 5 minute interval it detected a policy deviation from promises.cf & automatically executed the policy again thereby attaining the desired state of configuration again.
This is really useful when we want to monitor & protect files against unauthorized deletion.

Sunday, 24 April 2016

Getting started with CFEngine part 4 (writing the first policy)


Ok, so we've installed the policy server & client & tested out some of the commands.
Now lets write a policy.

The first policy would have to say 'hello world'.

Given below is a small policy file my.cf:

[root@dockertest tmp]# cat my.cf
body common control
{
bundlesequence => { "my_test" };
}
bundle agent my_test{
 files:
  linux::
   "/tmp/hello-world"
     create => "true";
}

The only mandatory element in this section is bundlesequence, which tells CFEngine which bundles  to execute and in which order. For the above example policy, we will have a single bundle my_test executed:

body common control
{
bundlesequence => { "my_test" };
}

The example says to create a file /tmp/hello-world on all Linux hosts.

To run a syntax check run the following command:

[root@dockertest tmp]# cf-promises -f ./my.cf
[root@dockertest tmp]#

To execute the policy type:

[root@dockertest tmp]# cf-agent -KI -f ./my.cf
    info: Created file '/tmp/hello-world', mode 0600
[root@dockertest tmp]#
[root@dockertest tmp]# ls -l /tmp/hello-world
-rw-------. 1 root root 0 Apr 24 13:52 /tmp/hello-world
[root@dockertest tmp]#

To run the policy on a distributed system:
By default cf-serverd will serve policy from the /var/cfengine/masterfiles directory. Upon updates, cf-agent will be notified and start to download these before executing them locally.
This means that by default you should store all your policies in the /var/cfengine/masterfiles directory on your policy server. So, now let’s copy our policy to this location:
cp /tmp/my.cf /var/cfengine/masterfiles/my.cf
1. Modify the /var/cfengine/masterfiles/promises.cf file and insert the bundle name my_test in the bundlesequence in body common control. 
2. Include the my.cf  in the inputs section of body common control in promises.cf. 
Save the file, and you are done!

Getting started with CFEngine part 3 (some useful commands)



This is a brief tutorial about some easy & useful CFEngine commands.

To view the installed version of CFEngine:


[root@dockertest init.d]# /var/cfengine/bin/cf-agent -V
CFEngine Core 3.7.3

CFEngine Enterprise 3.7.3

Keys are necessary when operating in a distributed CFEngine environment. The below command also sets up under /var/cfengine/ the basic directory structure used by CFEngine. To set up the keys type:

[root@dockertest ~]# /var/cfengine/bin/cf-key
A key file already exists at /var/cfengine/ppkeys/localhost.pub

Bootstraping:

Bootstraping the agent means copying the masterfiles to their final working location in /var/cfengine/inputs/ and starting the base cf-execd daemon. This process controls the periodic execution of cf-agent, which is the one that actually executes the promises in the provided policies 

[root@cfeclient tmp]# /var/cfengine/bin/cf-agent --bootstrap --policy-server 192.168.44.179
 warning: Deprecated bootstrap options detected. The --policy-server (-s) option is deprecated from CFEngine community version 3.5.0.Please provide the address argument to --bootstrap (-B) instead. Rewriting your arguments now, but you need to adjust them as this support will be removed soon.
  notice: Bootstrap mode: implicitly trusting server, use --trust-server=no if server trust is already established
R: Bootstrapping from host '192.168.44.179' via built-in policy '/var/cfengine/inputs/failsafe.cf'
R: This autonomous node assumes the role of voluntary client
R: Updated local policy from policy server
R: Did not start the scheduler
  notice: Bootstrap to '192.168.44.179' completed successfully!

To check the status of cfagent run the following command:

[root@dockertest init.d]# ./cfengine3 status
cf-consumer (pid 4875 4874 4873 4872 4871 4870 4869 4868 4867 4866 4865 4864 4863 4862 4861 4860 4859 4858 4857 4856 4855 4854 4853 4852 4851 4848) is running...
cf-hub (pid 4906) is running...
redis-server (pid 4841) is running...
httpd (pid 4986 4985 4984 4983 4982 4833) is running...
postgres is not running
cf-execd (pid 4964) is running...
cf-serverd (pid 4970) is running...
cf-monitord (pid 4976) is running...


To restart the agent type:

[root@dockertest init.d]# ./cfengine3 restart
Shutting down runalerts.sh
Starting CFEngine postgresql-hub:
waiting for server to start.... done
server started

Starting CFEngine httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.44.179 for ServerName

Starting redis-server...
Starting cf-consumer...                                    [  OK  ]
Starting cf-hub...                                         [  OK  ]
Starting cf-execd...                                       [  OK  ]
Starting cf-serverd...                                     [  OK  ]
Starting cf-monitord...                                    [  OK  ]
[root@dockertest init.d]#                                  [  OK  ]


To print verbose information about the behavior of the agent type:

cf-agent -v
------------------ output truncated
 verbose: Diff is empty, nothing to save at '/var/cfengine/state/diff/lastseen.diff'
 verbose: Diff is empty, nothing to save at '/var/cfengine/state/diff/software.diff'
 verbose: Diff is empty, nothing to save at '/var/cfengine/state/diff/patch.diff'
 verbose: No lock purging scheduled
 verbose: Outcome of version CFEngine Promises.cf 3.7.3 (agent-0): Promises observed - Total promise compliance: 100% kept, 0% repaired, 0% not kept (out of 212 events). User promise compliance: 100% kept, 0% repaired, 0% not kept (out of 192 events). CFEngine system compliance: 100% kept, 0% repaired, 0% not kept (out of 20 events).

Using capture groups in grep in Linux

Introduction Let me start by saying that this article isn't about capture groups in grep per se. What we are going to do here with gr...