Saturday, December 16, 2017

Handler 'handler' missing on module 'copy': module 'copy' has no attribute 'handler'

In my AWS Lambda function I am getting the following error in cloudwatch.

 Handler 'handler' missing on module 'copy': module 'copy' has no attribute 'handler' 

I am using a zip upload function, with Python 3.6.

 Solution:
Here the fix is how we call the handler. Its name.

In my case, I have renamed the copy.py to index.py
Inside the index.py, I have a function - def handler(event, context):

So my lambda handler is : index.handler
ie. Module.Function (filename.function_name)

Zip the folder and upload to lambda. See this blog for zip
 

Wednesday, December 13, 2017

errorMessage": "Cannot find module '/var/task/CreateThumbnail'

When I worked with AWS lambda function for creating a thumbnail for images uploaded to a S3 bucket. I am facing the following error while lambda test.

 errorMessage": "Cannot find module '/var/task/CreateThumbnail'

The reason for this issue is because of non proper zip the contents that we uploaded to lambda function.

zip -r ../yourfilename.zip *

Your folder may contain your index.js, node_modules, etc. files. Upload the new yourfilename.zip in your lambda function and try to run the test, the issue got fixed.

Monday, December 11, 2017

TypeError: csv is not a function in Nodejs

I am getting the following error in Nodejs, when I use a csv module.

TypeError: csv is not a function
    at Object.<anonymous> (/root/app.js:4:11)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:383:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:496:3


Here is my npm list:
[root@machine2 ~]# npm list
root@1.0.0 /root
├── csv@2.0.0 extraneous
└─┬ debug@3.1.0
  └── ms@2.0.0

 
Solution for this issue:
You need to remove the curret csv module and need to instll csv@0.3.7 which will solve this issue. Below given steps will surely help you.
 
[root@machine2 ~]# npm remove csv
- lodash.get@4.4.2 node_modules/lodash.get
- csv-generate@2.0.0 node_modules/csv-generate
- csv-parse@2.0.0 node_modules/csv-parse
- csv-stringify@2.0.0 node_modules/csv-stringify
- stream-transform@1.0.0 node_modules/stream-transform
- csv@2.0.0 node_modules/csv
npm WARN root@1.0.0 No description
npm WARN root@1.0.0 No repository field.
 

[root@machine2 ~]# npm list
root@1.0.0 /root
└─┬ debug@3.1.0
  └── ms@2.0.0

[root@machine2 ~]# npm install csv@0.3.7
root@1.0.0 /root
└── csv@0.3.7
npm WARN root@1.0.0 No description
npm WARN root@1.0.0 No repository field.
[root@machine2 ~]#


It works!
 

Thursday, December 7, 2017

Error on starting Consul

My Consul client is not able to start the consul service. Its getting the following error
Consul version is Consul v1.0.0 

WARNING: LAN keyring exists but -encrypt given, using keyring
==> Starting Consul agent...
==> Joining cluster...
==> 5 error(s) occurred:

* Failed to join 192.168.1.10: No installed keys could decrypt the message
* Failed to join
192.168.1.11: No installed keys could decrypt the message
* Failed to join
192.168.1.12: No installed keys could decrypt the message
* Failed to join
192.168.1.13: No installed keys could decrypt the message
* Failed to join
192.168.1.14: No installed keys could decrypt the message

Solution for this issue:

1. cd $consul-data-dir/serf
2.  Added the current encryption key in "local.keyring"
3. Start consul

It works. In my case I have two data center. One data center's encryption key is missing in file  "local.keyring". After updating and restarting it works fine.

Wednesday, December 6, 2017

Installing AWS CLI on Centos

How to install AWS CLI on Centos?

AWS CLI helps you a lot to interact with your AWS resources through CLI. This is good if you are an experienced person. As a pre-request, you need Python 2 version 2.6.5+ or Python 3 version 3.3+ in your machine.

1. Login to the server.
2. curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
3. unzip awscli-bundle.zip
4.
./awscli-bundle/install -b ~/bin/aws
5.  aws --version
 

Monday, December 4, 2017

Nomad Error:FIX

How to solve this Nomad Error.

Error submitting job: Unexpected response code: 500 (rpc error: 11 error(s) occurred:

* Task group <TASK_NAME> validation failed: 1 error(s) occurred:

* 1 error(s) occurred:

* Max parallel can not be less than one: 0 < 1
* Task group <GROUP_NAME> validation failed: 1 error(s) occurred:

* 1 error(s) occurred:


I am using Nomad version 0.7.0

Solution:

In my job stanza, I need to add max_parallel count

update {
   
    stagger = "10s"
   
    max_parallel = 2
 
    }


For more details, read here

Saturday, November 18, 2017

How to add a user in sudoers

How to add a user in sudoers list?

My OS is CentOS release 6.9 (Final). At the moment I have only root user. I need to create a user and add that user in sudoers.

Login to server as root. - ssh {ip}
Create user- useradd {arun}
Password to that user - password {arun}
usermod -aG wheel {arun}
Run - visudo
Scroll down to the bottom where wheel groups are described.

## Allows people in group wheel to run all commands
# %wheel        ALL=(ALL)       ALL
{arun}          ALL=(ALL)       ALL

#
Now login as that user {arun}
sudo ls -la /root

It will ask for password, then list all files in /root directory.

Wednesday, October 11, 2017

Thinking of migration from Ansible to HashiCorp

Convincing clients to move from Ansible to HashiCorp Terraform for provisioning infrastructure on AWS. Hashi is a good team having a lot of efficient products in different cloud technologies. The attached image is one of the most informative slides of the presentation.


Saturday, October 7, 2017

Ansible plugin for Jenkins

I need to utilize my ansible playbook in jenkins. We do have a plugin called Ansible Plugin.
You can install this plugin from jenkins itself. Once you login in jenkins --> Manage Jenkins --> Manage Plugins search for ansible plugin. Select, download and install plugin with restart of jenkins.

What we are doing here in this example:

I had a playbook, which contains two hosts, office.lan and lb.lan, the play book will just print a message "Hello from Ansible!!" when it runs.

Here is my ansible directory structure:

Directory: /home/shivin/Desktop/ansible-workshop
File : main.yml
Other directory: inventories/localdc

Run this play book from shell : 

ansible-playbook main.yml -i inventories/localdc --user root --ask-pass

This will ask for the password and will get a result, if everything is configured correctly.

How we can configure in Jenkins:

First need to give the ansible path in jenkins. Login to Jenkins --> Manage Jenkins --> Global Tool Configuration

Give a name : Ansible<version>
Path to ansible executables directory: /usr/bin/

For job configuration:
In my jenkins job, i am downloading the ansible playbook files from GIT to the workspace.


 Then run the job :)
 

Tuesday, August 22, 2017

Jenkins Pipeline code to run in a particular label


    node('TestLabel') {

        stage('Build') {
           
                echo 'Building..'
           
        }
        stage('Test') {
           
                echo 'Testing..'
           
        }
        stage('Deploy') {
           
                echo 'Deploying....'
           
        }

    }

Tuesday, August 15, 2017

Mongodb integration with PHP

In my CentOs box, i installed php5.5 and mongodb. Now i am getting the error
Mongodb is not enabled with PHP.

Solution to fix the issue.

Install gcc php-pear php-devel
yum install gcc php-pear php-devel php5-dev openssl-devel -y 

pecl install mongo
Cyrus SASL as "no"

vim /etc/php.ini
extension=mongo.so

Restart apache
service httpd restart

Verify
php -m | grep -i mongo

 
 

323 packages excluded due to repository priority protections

When I run "yum update php*" operation, in CentOs i am getting the following error:

"323 packages excluded due to repository priority protections"

Solution to fix the issue:

This is because of the plugin "priorities" helps to solve this issue. Open the file
/etc/yum/pluginconf.d/priorities.conf  and change the value of enabled =1 to 0.

Execute  yum update php*

It works.

Thursday, August 10, 2017

jq - How we can use jq

jq - JSON processor. We can use this to parse a JSON file in bash scripts. Its an opensource and available in github. We can use this like our sed, awk and grep.

How we can install jq on Centos machine?

jq has no runtime dependencies as its written in C. We need to download and extract to use it. You can play around with jq from here.

wget -O jq https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64
chmod +x ./jq
cp jq /usr/bin
 
 
 


Wednesday, July 12, 2017

How can we change from address in mutt

How can I change the from address in mutt?

Mutt is a mail client in Linux. By default the from address of the mail which is sent by muttrc will be the machine hostname. You can change that using the following steps.

1. Login to the server as root.
2. vi /etc/Muttrc
Update the file using the following.
set realname="Dennis Young"
set from="dennis.young@young.com"
set use_from=yes

3.Save the file

This helps to solve the issue.

Tuesday, July 11, 2017

ERROR 1558 (HY000): Column count of mysql.user is wrong. Expected 42, found 39. Created with MySQL 50173, now running 50556. Please use mysql_upgrade to fix this error.

I am getting the following error in mysql operation.

ERROR 1558 (HY000): Column count of mysql.user is wrong. Expected 42, found 39. Created with MySQL 50173, now running 50556. Please use mysql_upgrade to fix this error.

Solution:

Login to the server
[root@blackmagic ~]# mysql_upgrade -u root -p
Enter password:

(Enter your password)

This will fix the issue and its solved.

Thursday, June 15, 2017

monit dead but pid file exists

When I tried to start monit process, I am getting the following error

monit dead but pid file exists

Issue is solved by the following setps:

1. Login to the server.
2. vim /etc/monit.conf
Remove the following line set statefile /var/monit/state
3. Restart monit

Click here to see the steps to solve - monit dead but subsys locked


monit dead but subsys locked

When I tried to check the status of monit process, I am getting the following error

monit dead but subsys locked

Issue is solved by the following setps:

1. Login to the server.
2. vim /etc/monit.conf
Add the following, set daemon 120
3. Restart monit

This will help to solve this error.

Sunday, May 21, 2017

Error while starting jenkins

Today, when I install and setup Jenkins, I am getting the following error while starting the jenkins service.

OS : CentOS release 6.8 (Final)

Following is the error:

Running from: /usr/lib/jenkins/jenkins.war
May 21, 2017 7:38:37 PM Main deleteWinstoneTempContents
WARNING: Failed to delete the temporary Winstone file /tmp/winstone/jenkins.war
Jenkins requires Java7 or later, but you are running 1.7.0_131-mockbuild_2017_02_13_15_19-b00 from /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.131.x86_64/jre
java.lang.UnsupportedClassVersionError: winstone/Launcher : Unsupported major.minor version 52.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:803)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:442)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:64)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:354)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:348)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:347)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
        at Main._main(Main.java:224)
        at Main.main(Main.java:112)


Solution to fix the issue:

1. Take the backup of /etc/init.d/jenkins to a safe location.
2.  update-alternatives --config java (to the latest java) 
3. Update the file /etc/init.d/jenkins after candidates with your result of echo $JAVA_HOME

The  /etc/init.d/jenkins snippet is below
# Search usable Java as /usr/bin/java might not point to minimal version required by Jenkins.
# see http://www.nabble.com/guinea-pigs-wanted-----Hudson-RPM-for-RedHat-Linux-td25673707.html
candidates="
/usr/java/latest/bin/java
/etc/alternatives/java
/usr/lib/jvm/java-1.8.0/bin/java
/usr/lib/jvm/jre-1.8.0/bin/java
/usr/lib/jvm/java-1.7.0/bin/java
/usr/lib/jvm/jre-1.7.0/bin/java
/usr/bin/java



4. Restart jenkins




Tuesday, May 2, 2017

Patching 0 for a variable in python

As part of a program logic, i need to patch 0 for a variable to make sure the total length of the string is 3.

Here the variable name is shivin

shivin = shivin.zfill(3)
return shivin

Wednesday, April 5, 2017

How to sort the contents of a file in linux

How to sort the contents of a file in linux

I have a file in a path /tmp which contains some rpm packages. I need to sort the file.

ll /tmp/pckg.txt
sort /tmp/pckg.txt > /tmp/s_pckg.txt
A new file /tmp/s_pckg.txt will be created and the contents in that file will be in sorted order.

sort -r /tmp/pckg.txt > /tmp/s_pckg.txt
Reverse sorted.

sort -nk2 /tmp/s_pckg.txt
On the basis of second column it will sort.

Useful command combination in System Administration

Useful command combination in System Administration

Once you are in a linux box, these commands will help you to save your time a lot.

[root@linuxblack tmp]# ps aux|grep nagios | awk '{print $2}'|xargs kill -9 to kill the process owned by nagios


[root@linuxblack tmp]# ll | grep 02:1| awk '{print $9}'| xargs gzip list and zip the files in a dir whose time is 02:1


[root@linuxblack tmp]# ll | grep Jul| awk '{print $9}'| xargs du -hs - list and display the disk usage


[root@linuxblack tmp]# lsof -i TCP:443|awk '{print $2}'|xargs kill -9 Kill the process listening on port 443

How to move a linux process to foreground and background

How to move a linux process to foreground and background

I started a java process (not using &), but i need to move that process to background and foreground.

1. First I stopped the process using CTRL+Z ,
2. I do a process grep and i could see its running, (ps aux|grep java)
3. I issues command "jobs", it return me a job ID.


Example : - In this case job id is : 1
-bash-4.1$ jobs
[1]+ Stopped java -jar


4. Command -bash-4.1$ fg 1 (will bring the job id 1 to foreground)
5. Command -bash-4.1$ bg 1 (will move the job id 1 to background)

How to move a website from one cpanel to another cpanel server

How to move a website from one cpanel to another cpanel server

Our requirement is to migrate a full website from old cpanel server to new cpanel server. This has to be done in command prompt.

Follow the steps:

1. Login to the old cpanel server as root.
2. Backup the whole website using the command: /scripts/pkgacct {cpanel_username}
3. It will create the backup in /home folder as /home/cpmove-cpanelusername.tar.gz
4. Copy the backup file to the new server: scp /home/cpmove-cpanelusername.tar.gz root@newserver.com:/home
5. Login the new server as root.
6. Verify the size of the backup files.
7. It's the time to restore the backup in new server: /scripts/restorepkg {cpanel_username}
8. This will help to re-create everything from old server to the new server.
9. Test and verify, then go ahead in changing the DNS.

Mattermost Error: MySQL FULLTEXT indexes issue in logs

Mattermost Error: MySQL FULLTEXT indexes issue in logs

While working on Mattermost in my local machine I got the following error:

MySQL FULLTEXT indexes

Solution for fixing the issue is:

1. Login the server
2. Login to the mysql prompt:
show table status;
3. There you can see all the tables are having Engine as MYISAM.
4. You need to update those tables as INNODB
ALTER TABLE <table name> ENGINE = INNODB;

This helped to solve the issue.

Scenario based VMware questions

Scenario based VMware questions

1. Which method you adopt for taking backup of ESXi configuration ?
2. vMotion failed at 27%. What could be the possible reasons ?
3. What could be the reason for failing a VM to start after moving from another VMware platform ?
4. Can we clone a VM without VCenter ?
5. What are the possible reasons for ESXi host shown as disconnected in vCenter ?
6. After VMware clone Redhat network interface is not detecting, what may be the reasons ?
7. How can we resize an IDE virtual disk in VMware ?
8. What could be the reason for Software iSCSI adapters are not visible ?
9. What could be the reason for "Cannot create VMs with virtual machine version 9 in ESXi" ?
10. How to extend a logical volume in Windows 2003 hosted in VMware ?
11. What are the different ways to shrink the size of a vmdk file ?
12. Application server hosted in VMs are facing performance degradation. How to confirm whether it is an application related issue or VMware related issue ?
13. How to remove iscsi targets from ESXi with 'Dead' or 'Error' status ?
14. Reclaim the size of a thin provisioned vmdk file ?
15. What are the possible reasons for the operation to resize a VM disk failed ?
16. What could be the reason for "VM appears as inaccessible in vCenter" ?

Tuesday, April 4, 2017

Search and Replace in Vi editor

Situation:

I have a file called main.html, I need to search and replace _output with OUTPUT.

Steps:

Open the file in vi editor - vi main.html
:%s/_output/g/OUTPUT
Save file

The :substitute command searches for a text pattern, and replaces it with a text string. There are many options, but these are what you probably want:

:%s/foo/bar/g
    Find each occurrence of 'foo' (in all lines), and replace it with 'bar'.

:s/foo/bar/g
    Find each occurrence of 'foo' (in the current line only), and replace it with 'bar'.

:%s/foo/bar/gc
    Change each 'foo' to 'bar', but ask for confirmation first.

:%s/\<foo\>/bar/gc
    Change only whole words exactly matching 'foo' to 'bar'; ask for confirmation.

:%s/foo/bar/gci
    Change each 'foo' (case insensitive due to the i flag) to 'bar'; ask for confirmation.
    :%s/foo\c/bar/gc is the same because \c makes the search case insensitive.
    This may be wanted after using :set noignorecase to make searches case sensitive (the default).

:%s/foo/bar/gcI
    Change each 'foo' (case sensitive due to the I flag) to 'bar'; ask for confirmation.
    :%s/foo\C/bar/gc is the same because \C makes the search case sensitive.
    This may be wanted after using :set ignorecase to make searches case insensitive. 

Thursday, March 16, 2017

What is DevOps?

What is DevOps?

Devops = Development + Operations

DevOps is a framwork which integrates the Development team, QA and Operations. It's a collaboration effort to make the software delivery smooth.

Values of Devops
Following are the values of DevOps, that make it a success.

- Culture
- Automation
- Measurement
- Shairing

Devops Methodology

First Methodology - People over Process then selecting Tools
Second Methodology - Continues Devlivery
Third Methodology - Lean Management
Fourth Methodology - Change Control
Fifth Methodology - Infrastructure as Code

10 Pratices that drives DevOps to success
Following ten practices helps the DevOps to success in your organization.

1. Chaos Monkey
2. Blue/Green Deployment
3. Dependency Injection
4. Andon Cards
5. The Cloud
6. Embedded teams
7. Blameless postmortems
8.Status pages
9.Developers on call
10.Incidents

Six practices that are important for CI

1.Build should pass the coffee test (<5 min)
2.Commit really small bits
3.Don't leave the build broken
4.Use  a trunk-based development flow
5.Don't allow flaky tests. Fix them!
6.The build should return a status, a log, and an artifact.



Friday, March 10, 2017

/usr/bin/env: ‘node’: No such file or directory

I got this error when I tried to install Hubot

Error:

/usr/bin/env: ‘node’: No such file or directory

Fix:

ln -s /usr/bin/nodejs /usr/bin/node

root@mybot:/opt/hubot# ./bin/hubot
/usr/bin/env: ‘node’: No such file or directory
root@mybot:/opt/hubot# ln -s /usr/bin/nodejs /usr/bin/node
root@mybot:/opt/hubot# ./bin/hubot
Hubot>

Tuesday, February 14, 2017

How to create a Junit test case with failure

Today for testing, I need to create a junit test case xml file. Here is the sample which helps to create this failure xml.


<testsuite tests="3">
    <testcase classname="foo1" name="ASuccessfulTest"/>
    <testcase classname="foo2" name="AnotherSuccessfulTest"/>
    <testcase classname="foo3" name="AFailingTest">
        <failure type="NotEnoughFoo"> details about failure </failure>
    </testcase>
</testsuite>
 
This helps me to create a test.xml file having a failure in test case.